<p>I would like to execute a command on a node from the master. For e.g let's say I have worker node: kubenode01</p>
<p>Now a pod (pod-test) is running on this node. Using &quot;kubectl get pods --output=wide&quot; on the master shows that the pod is running on this node.
Trying to execute a command on that pod from the master results into an error e.g:</p>
<p><em><code>kubectl exec -ti pod-test -- cat /etc/resolv.conf</code></em></p>
<p>The result is:</p>
<p><em><code>Error from server: error dialing backend: dial tcp 10.0.22.131:10250: i/o timeout</code></em></p>
<p>Any idea?
Thanks in advance</p>

D.Joe
<p>You can execute <code>kubectl</code> commands from anywhere as long as your <a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/" rel="nofollow noreferrer"><code>kubeconfig</code></a> is configured to point to the right cluster URL (<a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kube-apiserver/" rel="nofollow noreferrer">kube-apiserver</a>), with the right credentials and the firewall allows connecting to the kube-apiserver port.</p>
<p>In your case, I'd check if your <em><code>10.0.22.131:10250</code></em> is the real <em><code>IP:PORT</code></em> for your kube-apiserver and that you can access it.</p>
<p>Note that <em><code>kubectl exec -ti pod-test -- cat /etc/resolv.conf</code></em> runs on the <em>Pod</em> and not on the Node. If you'd like to run on the Node just simply use <a href="https://en.wikipedia.org/wiki/Secure_Shell" rel="nofollow noreferrer">SSH</a>.</p>
<p>Update:</p>
<p>There are two other alternatives here:</p>
<ol>
<li><p>You can create a pod (or debug pod) with a <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector" rel="nofollow noreferrer">nodeSelector</a> that specifically makes that pod run on the specific node.</p>
</li>
<li><p>If you are trying to debug something on a pod already running on a specific node, you can also try creating a <a href="https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/#ephemeral-container" rel="nofollow noreferrer">debug ephemeral container</a>.</p>
</li>
</ol>
<p>On newer versions of Kubernetes you can use a debug pod to run something on a specific node</p>
<p>✌️</p>
