How to connect to AKS cluster nodes

One method to connect to the AKS cluster nodes is to create an interactive shell, aka debug pod.

To list your nodes, use the kubectl get nodes command:

1
2
3
4
5
6
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
aks-nodepool1-36793237-vmss000000 Ready agent 171m v1.27.7
aks-nodepool1-36793237-vmss000001 Ready agent 170m v1.27.7
aks-nodepool1-36793237-vmss000002 Ready agent 156m v1.27.7
aks-torpedo-83020050-vmss000000 Ready agent 151m v1.27.7

Use the kubectl debug command to run a container image on the node to connect to it. The following command starts a privileged container on your node and connects to it.

1
2
3
4
5
6
7
$ kubectl debug node/aks-nodepool1-36793237-vmss000000 -it --image=mcr.microsoft.com/dotnet/runtime-deps:6.0
Creating debugging pod node-debugger-aks-nodepool1-36793237-vmss000000-nj9kd with container debugger on node aks-nodepool1-36793237-vmss000000.
If you don't see a command prompt, try pressing enter.

root@aks-nodepool1-36793237-vmss000000:/# chroot /host
# hostname
aks-nodepool1-36793237-vmss000000

When you are done with a debugging pod, enter the exit command to end the interactive shell session. After the interactive container session closes, delete the pod used for access with kubectl delete pod.

1
2
3
4
5
6
7
8
9
# exit
root@aks-nodepool1-36793237-vmss000000:/# exit
exit
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
node-debugger-aks-nodepool1-36793237-vmss000000-nj9kd 0/1 Completed 0 62s

$ kubectl delete pod node-debugger-aks-nodepool1-36793237-vmss000000-nj9kd
pod "node-debugger-aks-nodepool1-36793237-vmss000000-nj9kd" deleted

Reference