Search code examples
pythonapikubernetesclient

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


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

  • 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