Python Kubernetes Client equivalent of kubectl get pods

1/16/2020

I'm trying to use the Python Kubernetes Client to get the run-time of each container for all my pods. Using the K8s CLI this information is available by using kubectl describe pods.

I can get the output for a single pod by using

api_response = api_instance.read_namespaced_pod(name='pod-name',namespace='namespace-name')

However, I need this information for all the pods.

What is the equivalent of kubectl get podsfor Python K8s library? I'm thinking I can use this to create a list of pods and use the mentioned command above to loop through them by their pod-name and get the required information.

-- aideen
devops
docker
kubernetes
kubernetes-pod
python

1 Answer

1/16/2020

From the docs you can try this api_response = api_instance.list_namespaced_pod(namespace='namespace-name')

-- Arghya Sadhu
Source: StackOverflow