Execute a command on Kubernetes node from the master

8/17/2020

I would like to execute a command on a node from the master. For e.g let's say I have worker node: kubenode01

Now a pod (pod-test) is running on this node. Using "kubectl get pods --output=wide" 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:

kubectl exec -ti pod-test -- cat /etc/resolv.conf

The result is:

Error from server: error dialing backend: dial tcp 10.0.22.131:10250: i/o timeout

Any idea? Thanks in advance

-- D.Joe
kubernetes

1 Answer

8/17/2020

You can execute kubectl commands from anywhere as long as your kubeconfig is configured to point to the right cluster URL (kube-apiserver), with the right credentials and the firewall allows connecting to the kube-apiserver port.

In your case, I'd check if you 10.0.22.131:10250 is the real IP:PORT for your kube-apiserver and that you can access it.

Note that kubectl exec -ti pod-test -- cat /etc/resolv.conf runs on the Pod and not on the Node. If you'd like to run on the Node just simply use SSH.

✌️

-- Rico
Source: StackOverflow