Get node that a specific pod is running on

Viewed 52

I have 2 nodes that I'm running development pods on. I'd like to be able to echo only the node that a pod is running on based on the name.

I can use kubectl get pod -o=custom-columns=NAME:.metadata.name,NODE:spec.nodeName -n my-namespace to pull back all the names and nodes for all pods in that namespace, but I'd like to filter just the nodename for specific pods. Using grep on the pod name works, but I'm not sure if its possible to only show the node when filtering based off a single pod name.

1 Answers

Option-1: Using custom-columns

kubectl get pod mypod -o custom-columns=":.spec.nodeName" --no-headers 

Option-2: Using jsonpath

kubectl get pod mypod -o jsonpath='{.spec.nodeName}'
Related