How can I get the node where the pod is located using kubernetes python client?

How can I get the node where the pod is located using kubernetes python client?

Problem Description:

I have a Pod name and I want to know where the Pod is located using kubernetes python client.
Is it possible to use kubernetes python client in order to get the node name by Pod? (Just like the NODE column in kubectl get pod -o wide)

I’ve referred to the document https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md. But I didn’t find a solution.

Solution – 1

I think read_namespaced_pod has the information (spec.nodeName).

https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#read_namespaced_pod

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject