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

Fabrice Jammes
<p>Refer below commands</p>
<pre><code>kubectl run busybox --image=busybox:1.28 --command -- sleep 3600

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

</code></pre>
