Skip to main content

How to SSH into nodes

Option 1: Using ssh#

If you want to access the server directly via ssh, the first step is to find out the IP address of the nodes:

		$ kubectl get nodes -o wide
NAME                               STATUS   ROLES           AGE    VERSION   INTERNAL-IP   EXTERNAL-IP      OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
mycluster-md-0-bkbqh-7sjwd-8qlpk   Ready    control-plane   2d3h   v1.29.5   <none>        41.181.105.184   Ubuntu 22.04.4 LTS   6.5.0-26-generic   containerd://1.7.16
mycluster-rqh9d-ckm5p              Ready    <none>          2d3h   v1.29.5   <none>        37.252.95.135    Ubuntu 22.04.4 LTS   6.5.0-26-generic   containerd://1.7.16
mycluster-rqh9d-lfxck              Ready    <none>          2d3h   v1.29.5   <none>        234.118.5.204    Ubuntu 22.04.4 LTS   6.5.0-26-generic   containerd://1.7.16
mycluster-rqh9d-n7b8p              Ready    <none>          2d3h   v1.29.5   <none>        186.72.52.235    Ubuntu 22.04.4 LTS   6.5.0-26-generic   containerd://1.7.16
	

Copy the IP address of the node, shown in the EXTERNAL-IP column and ssh into it using your ssh key:

		$ ssh -p 100 -o IdentitiesOnly=true -i <path-to/ssh-key> root@<node-ip-address>
	

Option 2: Using kubectl#

The command-line utility kubectl offers practical ways to access your node's shell.

List your nodes:

		$ kubectl get nodes
NAME                               STATUS   ROLES           AGE    VERSION
mycluster-md-0-bkbqh-7sjwd-8qlpk   Ready    <none>          2d3h   v1.29.5
mycluster-rqh9d-ckm5p              Ready    control-plane   2d3h   v1.29.5
mycluster-rqh9d-lfxck              Ready    control-plane   2d3h   v1.29.5
mycluster-rqh9d-n7b8p              Ready    control-plane   2d3h   v1.29.5
	

Now, copy the name of the node you want to connect to and run:

		$ kubectl debug node/<node-name> -it --image=busybox
	

In the command above, busybox is used since it's a lightweight container image loaded with basic utilities you expect to find in a Linux environment, but you can use any container image you want, like ubuntu for a more complete environment or nicolaka/netshoot for specialized networking debug tools.

For more information, you can refer to the official Kubernetes documentation.