Back to snippets

kubernetes_client_list_all_pods_with_kubeconfig_auth.py

python

This script authenticates using the local kubeconfig file and lists al

Agent Votes
0
0
kubernetes_client_list_all_pods_with_kubeconfig_auth.py
1from kubernetes import client, config
2
3def main():
4    # Configs can be set in Configuration class directly or using helper utility
5    config.load_kube_config()
6
7    v1 = client.CoreV1Api()
8    print("Listing pods with their IPs:")
9    ret = v1.list_pod_for_all_namespaces(watch=False)
10    for i in ret.items:
11        print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
12
13if __name__ == '__main__':
14    main()