Connect via ssh to a minikube node

minikube ssh connect node

3 min read | by Jordi Prats

minikube is a great tool for testing: For some activities we might need to access via ssh to the kubernetes nodes, minikube even provides a command to do it so we don't even have to break a sweat

Using the minikube ssh we can connect to the node of an existing minikube cluster:

$ minikube ssh
docker@minikube:~$ ps auxf
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.4  0.0  21860 11244 ?        Ss   15:52   0:00 /sbin/init
root         179  0.1  0.0  28948 12048 ?        S<s  15:53   0:00 /lib/systemd/systemd-journald
message+     191  0.0  0.0   7008  3628 ?        Ss   15:53   0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
root         203  0.4  0.1 2084564 48652 ?       Ssl  15:53   0:00 /usr/bin/containerd
root         204  0.0  0.0  12184  7252 ?        Ss   15:53   0:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
root        3726  0.0  0.0  12296  7400 ?        Ss   15:56   0:00  \_ sshd: docker [priv]
docker      3728  0.0  0.0  12296  4712 ?        S    15:56   0:00      \_ sshd: docker@pts/1
docker      3729  0.1  0.0   4248  3532 pts/1    Ss   15:56   0:00          \_ -bash
docker      3739  0.0  0.0   6052  2920 pts/1    R+   15:56   0:00              \_ ps auxf
root         464  2.2  0.2 2123020 91892 ?       Ssl  15:54   0:02 /usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --default-ulimit=nofile=1048576:1048576 --tlsverify --tlscacert /etc/docke
(...)

In cas we have multiple minikube nodes we just need to specify the node using the -n option, otherwise we are going to get connected to the first one:

$ kubectl get nodes
NAME           STATUS   ROLES                  AGE     VERSION
minikube       Ready    control-plane,master   6m34s   v1.22.3
minikube-m02   Ready    <none>                 4m41s   v1.22.3
$ minikube ssh
docker@minikube:~$ logout
$ minikube ssh -n minikube-m02
docker@minikube-m02:~$ logout

We can disable the native Golang SSH client to actually see the exact ssh command it uses to connect to the node:

$ minikube ssh -n minikube-m02 --native-ssh=false

On a minikube cluster created using docker container we would see something similar to:

(...)
   8009 ?        Ssl    0:07  \_ /usr/libexec/gnome-terminal-server
   8017 pts/0    Ss     0:00  |   \_ bash
  40990 pts/0    Sl+    0:00  |   |   \_ minikube ssh -n minikube-m02 --native-ssh=false
  41118 pts/0    S+     0:00  |   |       \_ /usr/bin/ssh -F /dev/null -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none -o LogLevel=quiet -o PasswordAuthentication=no -o ServerAliveInterval=60 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null docker@127.0.0.1 -o IdentitiesOnly=yes -i /home/jprats/.minikube/machines/minikube-m02/id_rsa -p 32782
(...)

Posted on 09/05/2022

Categories