Connect with RDP to Azure Kubernetes Service (AKS) cluster Windows Server nodes for maintenance or troubleshooting
Throughout the lifecycle of your Azure Kubernetes Service (AKS) cluster, you may need to access an AKS Windows Server node. This access could be for maintenance, log collection, or other troubleshooting operations. You can access the AKS Windows Server nodes using RDP. For security purposes, the AKS nodes aren't exposed to the internet.
Alternatively, if you want to SSH to your AKS Windows Server nodes, you need access to the same key-pair that was used during cluster creation. Follow the steps in SSH into Azure Kubernetes Service (AKS) cluster nodes.
This article shows you how to create an RDP connection with an AKS node using their private IP addresses.
Before you begin
This article assumes that you have an existing AKS cluster with a Windows Server node. If you need an AKS cluster, see the article on creating an AKS cluster with a Windows container using the Azure CLI. You need the Windows administrator username and password for the Windows Server node you want to troubleshoot. You also need an RDP client such as Microsoft Remote Desktop.
If you need to reset the password, use az aks update
to change the password.
az aks update --resource-group myResourceGroup --name myAKSCluster --windows-admin-password $WINDOWS_ADMIN_PASSWORD
If you need to reset the username and password, see Reset Remote Desktop Services or its administrator password in a Windows VM.
You also need the Azure CLI version 2.0.61 or later installed and configured. Run az --version
to find the version. If you need to install or upgrade, see Install Azure CLI.
Deploy a virtual machine to the same subnet as your cluster
The Windows Server nodes of your AKS cluster don't have externally accessible IP addresses. To make an RDP connection, you can deploy a virtual machine with a publicly accessible IP address to the same subnet as your Windows Server nodes.
The following example creates a virtual machine named myVM in the myResourceGroup resource group.
You need to get the subnet ID used by your Windows Server node pool and query for:
- The cluster's node resource group
- The virtual network
- The subnet's name
- The subnet ID
CLUSTER_RG=$(az aks show --resource-group myResourceGroup --name myAKSCluster --query nodeResourceGroup -o tsv)
VNET_NAME=$(az network vnet list --resource-group $CLUSTER_RG --query [0].name -o tsv)
SUBNET_NAME=$(az network vnet subnet list --resource-group $CLUSTER_RG --vnet-name $VNET_NAME --query [0].name -o tsv)
SUBNET_ID=$(az network vnet subnet show --resource-group $CLUSTER_RG --vnet-name $VNET_NAME --name $SUBNET_NAME --query id -o tsv)
Now that you've the SUBNET_ID, run the following command in the same Azure CLI console to create the VM:
PUBLIC_IP_ADDRESS="myVMPublicIP"
az vm create \
--resource-group myResourceGroup \
--name myVM \
--image win2019datacenter \
--admin-username azureuser \
--admin-password {admin-password} \
--subnet $SUBNET_ID \
--nic-delete-option delete \
--os-disk-delete-option delete \
--nsg "" \
--public-ip-address $PUBLIC_IP_ADDRESS \
--query publicIpAddress -o tsv
The following example output shows the VM has been successfully created and displays the public IP address of the virtual machine.
13.62.204.18
Record the public IP address of the virtual machine. You'll use this address in a later step.
Allow access to the virtual machine
AKS node pool subnets are protected with NSGs (Network Security Groups) by default. To get access to the virtual machine, you'll have to enabled access in the NSG.
Note
The NSGs are controlled by the AKS service. Any change you make to the NSG will be overwritten at any time by the control plane.
First, get the resource group and name of the NSG to add the rule to:
CLUSTER_RG=$(az aks show --resource-group myResourceGroup --name myAKSCluster --query nodeResourceGroup -o tsv)
NSG_NAME=$(az network nsg list --resource-group $CLUSTER_RG --query [].name -o tsv)
Then, create the NSG rule:
az network nsg rule create \
--name tempRDPAccess \
--resource-group $CLUSTER_RG \
--nsg-name $NSG_NAME \
--priority 100 \
--destination-port-range 3389 \
--protocol Tcp \
--description "Temporary RDP access to Windows nodes"
Get the node address
To manage a Kubernetes cluster, you use kubectl, the Kubernetes command-line client. To install kubectl
locally, use the az aks install-cli command:
az aks install-cli
To configure kubectl
to connect to your Kubernetes cluster, use the az aks get-credentials command. This command downloads credentials and configures the Kubernetes CLI to use them.
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
List the internal IP address of the Windows Server nodes using the kubectl get command:
kubectl get nodes -o wide
The following example output shows the internal IP addresses of all the nodes in the cluster, including the Windows Server nodes.
$ kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
aks-nodepool1-42485177-vmss000000 Ready agent 18h v1.12.7 10.240.0.4 <none> Ubuntu 16.04.6 LTS 4.15.0-1040-azure docker://3.0.4
aksnpwin000000 Ready agent 13h v1.12.7 10.240.0.67 <none> Windows Server Datacenter 10.0.17763.437
Record the internal IP address of the Windows Server node you wish to troubleshoot. You'll use this address in a later step.
Connect to the virtual machine and node
Connect to the public IP address of the virtual machine you created earlier using an RDP client such as Microsoft Remote Desktop.
After you have connected to your virtual machine, connect to the internal IP address of the Windows Server node you want to troubleshoot using an RDP client from within your virtual machine.
You're now connected to your Windows Server node.
You can now run any troubleshooting commands in the cmd window. Since Windows Server nodes use Windows Server Core, there's not a full GUI or other GUI tools when you connect to a Windows Server node over RDP.
Remove RDP access
When done, exit the RDP connection to the Windows Server node then exit the RDP session to the virtual machine. After you exit both RDP sessions, delete the virtual machine with the az vm delete command:
# Delete the virtual machine
az vm delete \
--resource-group myResourceGroup \
--name myVM
Delete the public IP associated with the virtual machine:
az network public-ip delete \
--resource-group myResourceGroup \
--name $PUBLIC_IP_ADDRESS
Delete the NSG rule:
CLUSTER_RG=$(az aks show --resource-group myResourceGroup --name myAKSCluster --query nodeResourceGroup -o tsv)
NSG_NAME=$(az network nsg list --resource-group $CLUSTER_RG --query [].name -o tsv)
az network nsg rule delete \
--resource-group $CLUSTER_RG \
--nsg-name $NSG_NAME \
--name tempRDPAccess
Connect with Azure Bastion
Alternatively, you can use Azure Bastion to connect to your Windows Server node.
Deploy Azure Bastion
To deploy Azure Bastion, you'll need to find the virtual network your AKS cluster is connected to.
- In the Azure portal, go to Virtual networks. Select the virtual network your AKS cluster is connected to.
- Under Settings, select Bastion, then select Deploy Bastion. Wait until the process is finished before going to the next step.
Connect to your Windows Server nodes using Azure Bastion
Go to the node resource group of the AKS cluster. Run the command below in the Azure local Shell to get the name of your node resource group:
az aks show --name myAKSCluster --resource-group myResourceGroup --query 'nodeResourceGroup' -o tsv
Select the
CLUSTER_RG
resource group we got in prevous step, the format is similar toMC_<AKS_RESOURCE_GROUP>_<ASK_CLUSTER_NAME>_<ASK_DEPLOY_REGION>
, then select Overview, next select your Windows node pool virtual machine scale set in Resources tab.Under Settings, select Instances. Select a Windows server node that you'd like to connect to.
Under Support + troubleshooting, select Bastion.
Enter the credentials you set up when the AKS cluster was created. Select Connect.
You can now run any troubleshooting commands in the cmd window. Since Windows Server nodes use Windows Server Core, there's not a full GUI or other GUI tools when you connect to a Windows Server node over RDP.
Note
If you close out of the terminal window, press CTRL + ALT + End, select Task Manager, select More details, select File, select Run new task, and enter cmd.exe to open another terminal. You can also logout and re-connect with Bastion.
Remove Bastion access
When you're finished, exit the Bastion session and remove the Bastion resource.
- In the Azure portal, go to Bastion and select the Bastion resource you created.
- At the top of the page, select Delete. Wait until the process is complete before proceeding to the next step.
- In the Azure portal, go to Virtual networks. Select the virtual network that your AKS cluster is connected to.
- Under Settings, select Subnet, and delete the AzureBastionSubnet subnet that was created for the Bastion resource.
Next steps
If you need more troubleshooting data, you can view the Kubernetes primary node logs or Azure Monitor.