Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell (ssh) into Azure AKS (Kubernetes) cluster worker node

I have a Kubernetes cluster in Azure using AKS and I'd like to 'login' to one of the nodes. The nodes do not have a public IP.

Is there a way to accomplish this?

like image 906
Greg Bala Avatar asked Nov 21 '18 21:11

Greg Bala


People also ask

How do I SSH into Kubernetes node aks?

To create the SSH connection to the Windows Server node from another node, use the SSH keys provided when you created the AKS cluster and the internal IP address of the Windows Server node. Open a new terminal window and use the kubectl get pods command to get the name of the pod started by kubectl debug .

How do I login to worker node in Kubernetes?

See Setting Up Cluster Access. Then in a terminal window, enter kubectl get nodes to see the public IP addresses of worker nodes in node pools in the cluster. Using the Console. In the Console, display the Cluster List page and then select the cluster to which the worker node belongs.

How do I SSH into Kubernetes master node?

You can use the IP address to log on to the master nodes of the dedicated Kubernetes cluster. If you do not enable SSH logon over the Internet when you create the cluster, you must add a listener that listens on SSH port 22 to the Server Load Balancer (SLB) instance of the API server.


1 Answers

The procedure is longly decribed in an article of the Azure documentation: https://docs.microsoft.com/en-us/azure/aks/ssh. It consists of running a pod that you use as a relay to ssh into the nodes, and it works perfectly fine:

You probably have specified the ssh username and public key during the cluster creation. If not, you have to configure your node to accept them as the ssh credentials:

$ az vm user update \
  --resource-group MC_myResourceGroup_myAKSCluster_region \
  --name node-name \
  --username theusername \
  --ssh-key-value ~/.ssh/id_rsa.pub

To find your nodes names:

az vm list --resource-group MC_myResourceGroup_myAKSCluster_region -o table

When done, run a pod on your cluster with an ssh client inside, this is the pod you will use to ssh to your nodes:

kubectl run -it --rm my-ssh-pod --image=debian
# install ssh components, as their is none in the Debian image
apt-get update && apt-get install openssh-client -y

On your workstation, get the name of the pod you just created:

$ kubectl get pods

Add your private key into the pod:

$ kubectl cp ~/.ssh/id_rsa pod-name:/id_rsa

Then, in the pod, connect via ssh to one of your node:

ssh -i /id_rsa [email protected]

(to find the nodes IPs, on your workstation):

az vm list-ip-addresses --resource-group MC_myAKSCluster_myAKSCluster_region -o table
like image 65
dbourcet Avatar answered Sep 21 '22 22:09

dbourcet