Home > front end >  How to get the node name for a pod?
How to get the node name for a pod?

Time:12-22

What is the kubectl command that retrieves only the node name for a given pod? I'm aware that kubectl get pods <my-pod> -o wide would display this information, but what I want is the kubectl command that only displays the node name, so I can use it as a shell script variable.

CodePudding user response:

This works:

NODE=$(kubectl get pod -n <my-namespace> <my-pod> -o "jsonpath={.spec.nodeName}")

CodePudding user response:

Refer below commands

kubectl run busybox --image=busybox:1.28 --command -- sleep 3600

POD_NAME=$(kubectl get pods -l run=busybox -o jsonpath="{.items[0].metadata.name}")
NODE_NAME=$(kubectl get pod $POD_NAME -o "jsonpath={.spec.nodeName}")
echo $NODE_NAME

  • Related