D.Joe
D.Joe

Reputation: 53

Execute a command on Kubernetes node from the master

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

Upvotes: 2

Views: 10461

Answers (1)

Rico
Rico

Reputation: 61669

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 your 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.

Update:

There are two other alternatives here:

  1. You can create a pod (or debug pod) with a nodeSelector that specifically makes that pod run on the specific node.

  2. If you are trying to debug something on a pod already running on a specific node, you can also try creating a debug ephemeral container.

On newer versions of Kubernetes you can use a debug pod to run something on a specific node

✌️

Upvotes: 6

Related Questions