Listing Kubernetes namespaces with Ansible

A Kubernetes cluster has multiple namespaces internally, and you can usually find the ones a cluster has with kubectl get namespaces. You can do the same with Ansible by creating a file called k8s-ns-show.yaml with the following content:

---
- hosts: localhost
tasks:
- name: Get information from K8s
k8s_info:
api_version: v1
kind: Namespace
register: ns
- name: Print info
debug:
var: ns

We can now execute this, as follows:

$ ansible-playbook k8s-ns-show.yaml

You will now see information regarding the namespaces in the output. 

Notice that in the seventh line of the code (kind: Namespace), we are specifying the type of resources we are interested in. You can specify other Kubernetes object types to see them (for example, you can try this with Deployments, Services, and Pods).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset