Skip to content

Commit a6ef3b2

Browse files
authored
Merge pull request #203884 from erik-ha-msft/erikha-aks-rdp
[AKS - Update RDP and add Azure Bastion steps
2 parents 285f43f + a2a0ed6 commit a6ef3b2

File tree

1 file changed

+130
-35
lines changed

1 file changed

+130
-35
lines changed

articles/aks/rdp.md

Lines changed: 130 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ titleSuffix: Azure Kubernetes Service
44
description: Learn how to create an RDP connection with Azure Kubernetes Service (AKS) cluster Windows Server nodes for troubleshooting and maintenance tasks.
55
services: container-service
66
ms.topic: article
7-
ms.date: 06/04/2019
7+
ms.date: 07/06/2022
88

99

1010
#Customer intent: As a cluster operator, I want to learn how to use RDP to connect to nodes in an AKS cluster to perform maintenance or troubleshoot a problem.
1111
---
1212

1313
# Connect with RDP to Azure Kubernetes Service (AKS) cluster Windows Server nodes for maintenance or troubleshooting
1414

15-
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. Alternatively, if you want to use SSH to access the AKS Windows Server nodes and you have access to the same keypair that was used during cluster creation, you can follow the steps in [SSH into Azure Kubernetes Service (AKS) cluster nodes][ssh-steps]. For security purposes, the AKS nodes are not exposed to the internet.
15+
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.
16+
17+
Alternatively, if you want to SSH to your AKS Windows Server nodes, you'll 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][ssh-steps].
1618

1719
This article shows you how to create an RDP connection with an AKS node using their private IP addresses.
1820

@@ -22,13 +24,13 @@ This article shows you how to create an RDP connection with an AKS node using th
2224

2325
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][aks-quickstart-windows-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][rdp-mac].
2426

25-
If you need to reset the password you can use `az aks update` to change the password.
27+
If you need to reset the password, use `az aks update` to change the password.
2628

2729
```azurecli-interactive
2830
az aks update -g myResourceGroup -n myAKSCluster --windows-admin-password $WINDOWS_ADMIN_PASSWORD
2931
```
3032

31-
If you need to reset both the username and password, see [Reset Remote Desktop Services or its administrator password in a Windows VM
33+
If you need to reset the username and password, see [Reset Remote Desktop Services or its administrator password in a Windows VM
3234
](/troubleshoot/azure/virtual-machines/reset-rdp).
3335

3436
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][install-azure-cli].
@@ -37,15 +39,15 @@ You also need the Azure CLI version 2.0.61 or later installed and configured. Ru
3739

3840
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 PowerShell][aks-quickstart-windows-powershell]. 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][rdp-mac].
3941

40-
If you need to reset the password you can use `Set-AzAksCluster` to change the password.
42+
If you need to reset the password, use `Set-AzAksCluster` to change the password.
4143

4244
```azurepowershell-interactive
4345
$cluster = Get-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster
4446
$cluster.WindowsProfile.AdminPassword = $WINDOWS_ADMIN_PASSWORD
4547
$cluster | Set-AzAksCluster
4648
```
4749

48-
If you need to reset both the username and password, see [Reset Remote Desktop Services or its administrator password in a Windows VM
50+
If you need to reset the username and password, see [Reset Remote Desktop Services or its administrator password in a Windows VM
4951
](/troubleshoot/azure/virtual-machines/reset-rdp).
5052

5153
You also need the Azure PowerShell version 7.5.0 or later installed and configured. Run `Get-InstalledModule -Name Az` to find the version. If you need to install or upgrade, see [Install Azure PowerShell][install-azure-powershell].
@@ -60,7 +62,11 @@ The following example creates a virtual machine named *myVM* in the *myResourceG
6062

6163
### [Azure CLI](#tab/azure-cli)
6264

63-
First, get the subnet used by your Windows Server node pool. To get the subnet ID, you need the name of the subnet. To get the name of the subnet, you need the name of the VNet. Get the VNet name by querying your cluster for its list of networks. To query the cluster, you need its name. You can get all of these by running the following in the Azure Cloud Shell:
65+
You'll need to get the subnet ID used by your Windows Server node pool. The commands below will query for the following information:
66+
* The cluster's node resource group
67+
* The virtual network
68+
* The subnet's name
69+
* The subnet ID
6470

6571
```azurecli-interactive
6672
CLUSTER_RG=$(az aks show -g myResourceGroup -n myAKSCluster --query nodeResourceGroup -o tsv)
@@ -69,16 +75,22 @@ SUBNET_NAME=$(az network vnet subnet list -g $CLUSTER_RG --vnet-name $VNET_NAME
6975
SUBNET_ID=$(az network vnet subnet show -g $CLUSTER_RG --vnet-name $VNET_NAME --name $SUBNET_NAME --query id -o tsv)
7076
```
7177

72-
Now that you have the SUBNET_ID, run the following command in the same Azure Cloud Shell window to create the VM:
78+
Now that you've the SUBNET_ID, run the following command in the same Azure Cloud Shell window to create the VM:
7379

7480
```azurecli-interactive
81+
PUBLIC_IP_ADDRESS="myVMPublicIP"
82+
7583
az vm create \
7684
--resource-group myResourceGroup \
7785
--name myVM \
7886
--image win2019datacenter \
7987
--admin-username azureuser \
80-
--admin-password myP@ssw0rd12 \
88+
--admin-password {admin-password} \
8189
--subnet $SUBNET_ID \
90+
--nic-delete-option delete \
91+
--os-disk-delete-option delete \
92+
--nsg "" \
93+
--public-ip-address $PUBLIC_IP_ADDRESS \
8294
--query publicIpAddress -o tsv
8395
```
8496

@@ -88,11 +100,15 @@ The following example output shows the VM has been successfully created and disp
88100
13.62.204.18
89101
```
90102

91-
Record the public IP address of the virtual machine. You will use this address in a later step.
103+
Record the public IP address of the virtual machine. You'll use this address in a later step.
92104

93105
### [Azure PowerShell](#tab/azure-powershell)
94106

95-
First, get the subnet used by your Windows Server node pool. You need the name of the subnet and its address prefix. To get the name of the subnet, you need the name of the VNet. Get the VNet name by querying your cluster for its list of networks. To query the cluster, you need its name. You can get all of these by running the following in the Azure Cloud Shell:
107+
You'll need to get the subnet ID used by your Windows Server node pool. The commands below will query for the following information:
108+
* The cluster's node resource group
109+
* The virtual network
110+
* The subnet's name and address prefix
111+
* The subnet ID
96112

97113
```azurepowershell-interactive
98114
$CLUSTER_RG = (Get-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster).nodeResourceGroup
@@ -115,15 +131,18 @@ $ipParams = @{
115131
New-AzPublicIpAddress @ipParams
116132
117133
$vmParams = @{
118-
ResourceGroupName = 'myResourceGroup'
119-
Name = 'myVM'
120-
Image = 'win2019datacenter'
121-
Credential = Get-Credential azureuser
122-
VirtualNetworkName = $VNET_NAME
123-
AddressPrefix = $ADDRESS_PREFIX
124-
SubnetName = $SUBNET_NAME
125-
SubnetAddressPrefix = $SUBNET_ADDRESS_PREFIX
126-
PublicIpAddressName = 'myPublicIP'
134+
ResourceGroupName = 'myResourceGroup'
135+
Name = 'myVM'
136+
Image = 'win2019datacenter'
137+
Credential = Get-Credential azureuser
138+
VirtualNetworkName = $VNET_NAME
139+
AddressPrefix = $ADDRESS_PREFIX
140+
SubnetName = $SUBNET_NAME
141+
SubnetAddressPrefix = $SUBNET_ADDRESS_PREFIX
142+
PublicIpAddressName = 'myPublicIP'
143+
OSDiskDeleteOption = 'Delete'
144+
NetworkInterfaceDeleteOption = 'Delete'
145+
DataDiskDeleteOption = 'Delete'
127146
}
128147
New-AzVM @vmParams
129148
@@ -136,7 +155,7 @@ The following example output shows the VM has been successfully created and disp
136155
13.62.204.18
137156
```
138157

139-
Record the public IP address of the virtual machine. You will use this address in a later step.
158+
Record the public IP address of the virtual machine. You'll use this address in a later step.
140159

141160
---
142161

@@ -146,7 +165,6 @@ AKS node pool subnets are protected with NSGs (Network Security Groups) by defau
146165

147166
> [!NOTE]
148167
> 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.
149-
>
150168
151169
### [Azure CLI](#tab/azure-cli)
152170

@@ -160,7 +178,14 @@ NSG_NAME=$(az network nsg list -g $CLUSTER_RG --query [].name -o tsv)
160178
Then, create the NSG rule:
161179

162180
```azurecli-interactive
163-
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"
181+
az network nsg rule create \
182+
--name tempRDPAccess \
183+
--resource-group $CLUSTER_RG \
184+
--nsg-name $NSG_NAME \
185+
--priority 100 \
186+
--destination-port-range 3389 \
187+
--protocol Tcp \
188+
--description "Temporary RDP access to Windows nodes"
164189
```
165190

166191
### [Azure PowerShell](#tab/azure-powershell)
@@ -239,7 +264,7 @@ aks-nodepool1-42485177-vmss000000 Ready agent 18h v1.12.7 10.240.0.4
239264
aksnpwin000000 Ready agent 13h v1.12.7 10.240.0.67 <none> Windows Server Datacenter 10.0.17763.437
240265
```
241266

242-
Record the internal IP address of the Windows Server node you wish to troubleshoot. You will use this address in a later step.
267+
Record the internal IP address of the Windows Server node you wish to troubleshoot. You'll use this address in a later step.
243268

244269
## Connect to the virtual machine and node
245270

@@ -251,7 +276,7 @@ After you've connected to your virtual machine, connect to the *internal IP addr
251276

252277
![Image of connecting to the Windows Server node using an RDP client](media/rdp/node-rdp.png)
253278

254-
You are now connected to your Windows Server node.
279+
You're now connected to your Windows Server node.
255280

256281
![Image of cmd window in the Windows Server node](media/rdp/node-session.png)
257282

@@ -264,18 +289,29 @@ You can now run any troubleshooting commands in the *cmd* window. Since Windows
264289
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][az-vm-delete] command:
265290

266291
```azurecli-interactive
267-
az vm delete --resource-group myResourceGroup --name myVM
292+
# Delete the virtual machine
293+
az vm delete \
294+
--resource-group myResourceGroup \
295+
--name myVM
268296
```
269297

270-
And the NSG rule:
298+
Delete the public IP associated with the virtual machine:
271299

272300
```azurecli-interactive
273-
CLUSTER_RG=$(az aks show -g myResourceGroup -n myAKSCluster --query nodeResourceGroup -o tsv)
274-
NSG_NAME=$(az network nsg list -g $CLUSTER_RG --query [].name -o tsv)
275-
```
301+
az network public-ip delete \
302+
--resource-group myResourceGroup \
303+
--name $PUBLIC_IP_ADDRESS
304+
```
305+
306+
Delete the NSG rule:
276307

277308
```azurecli-interactive
278-
az network nsg rule delete --resource-group $CLUSTER_RG --nsg-name $NSG_NAME --name tempRDPAccess
309+
CLUSTER_RG=$(az aks show -g myResourceGroup -n myAKSCluster --query nodeResourceGroup -o tsv)
310+
NSG_NAME=$(az network nsg list -g $CLUSTER_RG --query [].name -o tsv)
311+
az network nsg rule delete \
312+
--resource-group $CLUSTER_RG \
313+
--nsg-name $NSG_NAME \
314+
--name tempRDPAccess
279315
```
280316

281317
### [Azure PowerShell](#tab/azure-powershell)
@@ -286,22 +322,80 @@ When done, exit the RDP connection to the Windows Server node then exit the RDP
286322
Remove-AzVM -ResourceGroupName myResourceGroup -Name myVM
287323
```
288324

289-
And the NSG rule:
325+
Delete the public IP associated with the virtual machine:
326+
327+
```azurepowershell-interactive
328+
Remove-AzPublicIpAddress -ResourceGroupName myResourceGroup -Name myPublicIP
329+
```
330+
331+
Delete the NSG rule:
290332

291333
```azurepowershell-interactive
292334
$CLUSTER_RG = (Get-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster).nodeResourceGroup
293335
$NSG_NAME = (Get-AzNetworkSecurityGroup -ResourceGroupName $CLUSTER_RG).Name
336+
337+
Get-AzNetworkSecurityGroup -Name $NSG_NAME -ResourceGroupName $CLUSTER_RG | Remove-AzNetworkSecurityRuleConfig -Name tempRDPAccess | Set-AzNetworkSecurityGroup
294338
```
295339

340+
Delete the NSG created by default from New-AzVM:
341+
296342
```azurepowershell-interactive
297-
Get-AzNetworkSecurityGroup -Name $NSG_NAME -ResourceGroupName $CLUSTER_RG | Remove-AzNetworkSecurityRuleConfig -Name tempRDPAccess | Set-AzNetworkSecurityGroup
343+
Remove-AzNetworkSecurityGroup -ResourceGroupName myResourceGroup -Name myVM
298344
```
299345

300346
---
301347

348+
## Connect with Azure Bastion
349+
350+
Alternatively, you can use [Azure Bastion][azure-bastion] to connect to your Windows Server node.
351+
352+
### Deploy Azure Bastion
353+
354+
To deploy Azure Bastion, you'll need to find the virtual network your AKS cluster is connected to.
355+
356+
1. In the Azure portal, go to **Virtual networks**. Select the virtual network your AKS cluster is connected to.
357+
1. Under **Settings**, select **Bastion**, then select **Deploy Bastion**. Wait until the process is finished before going to the next step.
358+
359+
### Connect to your Windows Server nodes using Azure Bastion
360+
361+
Go to the node resource group of the AKS cluster. Run the command below in the Azure Cloud Shell to get the name of your node resource group:
362+
363+
#### [Azure CLI](#tab/azure-cli)
364+
365+
```azurecli-interactive
366+
az aks show -n myAKSCluster -g myResourceGroup --query 'nodeResourceGroup' -o tsv
367+
```
368+
369+
#### [Azure PowerShell](#tab/azure-powershell)
370+
371+
```azurepowershell-interactive
372+
(Get-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster).nodeResourceGroup
373+
```
374+
375+
---
376+
377+
1. Select **Overview**, and select your Windows node pool virtual machine scale set.
378+
1. Under **Settings**, select **Instances**. Select a Windows server node that you'd like to connect to.
379+
1. Under **Support + troubleshooting**, select **Bastion**.
380+
1. Enter the credentials you set up when the AKS cluster was created. Select **Connect**.
381+
382+
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.
383+
384+
> [!NOTE]
385+
> 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.
386+
387+
### Remove Bastion access
388+
389+
When you're finished, exit the Bastion session and remove the Bastion resource.
390+
391+
1. In the Azure portal, go to **Bastion** and select the Bastion resource you created.
392+
1. At the top of the page, select **Delete**. Wait until the process is complete before proceeding to the next step.
393+
1. In the Azure portal, go to **Virtual networks**. Select the virtual network that your AKS cluster is connected to.
394+
1. Under **Settings**, select **Subnet**, and delete the **AzureBastionSubnet** subnet that was created for the Bastion resource.
395+
302396
## Next steps
303397

304-
If you need additional troubleshooting data, you can [view the Kubernetes master node logs][view-master-logs] or [Azure Monitor][azure-monitor-containers].
398+
If you need more troubleshooting data, you can [view the Kubernetes primary node logs][view-primary-logs] or [Azure Monitor][azure-monitor-containers].
305399

306400
<!-- EXTERNAL LINKS -->
307401
[kubectl]: https://kubernetes.io/docs/user-guide/kubectl/
@@ -321,4 +415,5 @@ If you need additional troubleshooting data, you can [view the Kubernetes master
321415
[install-azure-cli]: /cli/azure/install-azure-cli
322416
[install-azure-powershell]: /powershell/azure/install-az-ps
323417
[ssh-steps]: ssh.md
324-
[view-master-logs]: view-master-logs.md
418+
[view-primary-logs]: ../azure-monitor/containers/container-insights-log-query.md#resource-logs
419+
[azure-bastion]: ../bastion/bastion-overview.md

0 commit comments

Comments
 (0)