Skip to content

Commit b590ed8

Browse files
Merge pull request #261729 from kaarthis/node-access
node access 1
2 parents b90f328 + 0eb5a92 commit b590ed8

File tree

1 file changed

+65
-82
lines changed

1 file changed

+65
-82
lines changed

articles/aks/node-access.md

Lines changed: 65 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Connect to Azure Kubernetes Service (AKS) cluster nodes
33
description: Learn how to connect to Azure Kubernetes Service (AKS) cluster nodes for troubleshooting and maintenance tasks.
44
ms.topic: article
5-
ms.date: 10/04/2023
5+
ms.date: 12/20/2023
66
ms.reviewer: mattmcinnes
77
ms.custom: contperf-fy21q4, devx-track-linux
88
#Customer intent: As a cluster operator, I want to learn how to connect to virtual machines in an AKS cluster to perform maintenance or troubleshoot a problem.
@@ -16,11 +16,11 @@ This article shows you how to create a connection to an AKS node and update the
1616

1717
## Before you begin
1818

19-
* You have an SSH key. If you don't, you can create an SSH key using [macOS or Linux][ssh-nix] or [Windows][ssh-windows]. Save the key pair in an OpenSSH format, other formats like `.ppk` aren't supported.
19+
This article assumes you have an SSH key. If not, you can create an SSH key using [macOS or Linux][ssh-nix] or [Windows][ssh-windows], to know more refer [Manage SSH configuration][manage-ssh-node-access]. Make sure you save the key pair in an OpenSSH format, other formats like .ppk aren't supported.
2020

21-
* The Azure CLI version 2.0.64 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].
21+
You also need the Azure CLI version 2.0.64 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].
2222

23-
## Create an interactive shell connection to a Linux node
23+
## Create an interactive shell connection to a Linux node using kubectl
2424

2525
To create an interactive shell connection to a Linux node, use the `kubectl debug` command to run a privileged container on your node.
2626

@@ -29,20 +29,20 @@ To create an interactive shell connection to a Linux node, use the `kubectl debu
2929
```bash
3030
kubectl get nodes -o wide
3131
```
32-
32+
3333
The following example resembles output from the command:
34-
34+
3535
```output
36-
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
37-
aks-nodepool1-37663765-vmss000000 Ready agent 166m v1.25.6 10.224.0.33 <none> Ubuntu 22.04.2 LTS 5.15.0-1039-azure containerd://1.7.1+azure-1
38-
aks-nodepool1-37663765-vmss000001 Ready agent 166m v1.25.6 10.224.0.4 <none> Ubuntu 22.04.2 LTS 5.15.0-1039-azure containerd://1.7.1+azure-1
39-
aksnpwin000000 Ready agent 160m v1.25.6 10.224.0.62 <none> Windows Server 2022 Datacenter 10.0.20348.1787 containerd://1.6.21+azure
36+
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE
37+
aks-nodepool1-37663765-vmss000000 Ready agent 166m v1.25.6 10.224.0.33 <none> Ubuntu 22.04.2 LTS
38+
aks-nodepool1-37663765-vmss000001 Ready agent 166m v1.25.6 10.224.0.4 <none> Ubuntu 22.04.2 LTS
39+
aksnpwin000000 Ready agent 160m v1.25.6 10.224.0.62 <none> Windows Server 2022 Datacenter
4040
```
4141

4242
2. 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.
4343

4444
```bash
45-
kubectl debug node/aks-nodepool1-37663765-vmss000000 -it --image=mcr.microsoft.com/dotnet/runtime-deps:6.0
45+
kubectl debug node/aks-nodepool1-37663765-vmss000000 -it --image=mcr.microsoft.com/cbl-mariner/busybox:2.0
4646
```
4747

4848
The following example resembles output from the command:
@@ -52,31 +52,70 @@ To create an interactive shell connection to a Linux node, use the `kubectl debu
5252
If you don't see a command prompt, try pressing enter.
5353
root@aks-nodepool1-37663765-vmss000000:/#
5454
```
55-
55+
5656
This privileged container gives access to the node.
57-
57+
5858
> [!NOTE]
5959
> You can interact with the node session by running `chroot /host` from the privileged container.
6060
6161
### Remove Linux node access
6262
63-
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`.
63+
When you're 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`.
6464
6565
```bash
6666
kubectl delete pod node-debugger-aks-nodepool1-37663765-vmss000000-bkmmx
6767
```
68+
## Create an interactive shell connection to a node using private IP
69+
70+
If you don't have access to the Kubernetes API, you can get access to properties such as ```Node IP``` and ```Node Name``` through the AKS Agentpool Preview API(preview version 07-02-2023 or above) to troubleshoot node-specific issues in your AKS node pools. For convenience, we also expose the public IP if the node has a public IP assigned. However in order to SSH into the node, you need to be in the cluster's virtual network.
71+
72+
1. To get the private IP via CLI, use az cli version 2.53 or above with aks-preview extension installed.
73+
74+
```bash
75+
az aks machine list --resource-group myResourceGroup --cluster-name myAKSCluster --nodepool-name nodepool1 -o table
76+
77+
```
78+
79+
The following example resembles output from the command:
80+
81+
```output
82+
Name Ip
83+
--------------------------------- --------------------------
84+
aks-nodepool1-33555069-vmss000000 10.224.0.5,family:IPv4;
85+
aks-nodepool1-33555069-vmss000001 10.224.0.6,family:IPv4;
86+
aks-nodepool1-33555069-vmss000002 10.224.0.4,family:IPv4;
87+
```
88+
To target a specific node inside the nodepool, use this command:
89+
90+
```bash
91+
az aks machine show --cluster-name myAKScluster --nodepool-name nodepool1 -g myResourceGroup --machine-name aks-nodepool1-33555069-vmss000000 -o table
92+
93+
```
94+
The following example resembles output from the command:
95+
96+
```output
97+
Name Ip
98+
--------------------------------- --------------------------
99+
aks-nodepool1-33555069-vmss000000 10.224.0.5,family:IPv4;
100+
```
101+
102+
2. Use the private IP to SSH into the node. [Azure Bastion][azure-bastion] also provides you with information for securely connecting to virtual machines via private IP address. Make sure that you configure an Azure Bastion host for the virtual network in which the VM resides.
103+
104+
```bash
105+
106+
```
68107

69108
## Create the SSH connection to a Windows node
70109

71-
Currently, you can't connect to a Windows Server node directly by using `kubectl debug`. Instead, you need to first connect to another node in the cluster, and then connect to the Windows Server node from that node using SSH. Alternatively, you can [connect to Windows Server nodes using remote desktop protocol (RDP) connections][aks-windows-rdp] instead of using SSH.
110+
At this time, you can't connect to a Windows Server node directly by using `kubectl debug`. Instead, you need to first connect to another node in the cluster, then connect to the Windows Server node from that node using SSH. Alternatively, you can [connect to Windows Server nodes using remote desktop protocol (RDP) connections][aks-windows-rdp] instead of using SSH or use SSH with 'machines API' presented at the start of this document.
72111

73-
To connect to another node in the cluster, use the `kubectl debug` command. For more information, see [Create an interactive shell connection to a Linux node][ssh-linux-kubectl-debug].
112+
To connect to another node in the cluster, use the `kubectl debug` command. For more information, see the Linux section.
74113

75114
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.
76115

77116
> [!IMPORTANT]
78117
>
79-
> The following steps for creating the SSH connection to the Windows Server node from another node can only be used if you created your AKS cluster using the Azure CLI and the `--generate-ssh-keys` parameter. If you didn't use this method to create your cluster, use a password instead of an SSH key. To do this, see [Create the SSH connection to a Windows node using a password](#create-the-ssh-connection-to-a-windows-node-using-a-password)
118+
> The following steps for creating the SSH connection to the Windows Server node from another node can only be used if you created your AKS cluster using the Azure CLI and the `--generate-ssh-keys` parameter. AKS Update command can also be used to manage, create SSH keys on an existing AKS cluster. For more information refer [Manage SSH configuration][manage-ssh-node-access].
80119
81120
1. Open a new terminal window and use the `kubectl get pods` command to get the name of the pod started by `kubectl debug`.
82121

@@ -111,17 +150,14 @@ To create the SSH connection to the Windows Server node from another node, use t
111150
3. Open a new terminal and run the command `kubectl get nodes` to show the internal IP address of the Windows Server node:
112151

113152
```bash
114-
kubectl get nodes -o wide
153+
kubectl get no -o custom-columns=NAME:metadata.name,'INTERNAL_IP:status.addresses[?(@.type == \"InternalIP\")].address'
115154
```
116155

117156
The following example resembles output from the command:
118157

119158
```output
120-
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE
121-
KERNEL-VERSION CONTAINER-RUNTIME
122-
aks-nodepool1-37663765-vmss000000 Ready agent 166m v1.25.6 10.224.0.33 <none> Ubuntu 22.04.2 LTS 5.15.0-1039-azure containerd://1.7.1+azure-1
123-
aks-nodepool1-37663765-vmss000001 Ready agent 166m v1.25.6 10.224.0.4 <none> Ubuntu 22.04.2 LTS 5.15.0-1039-azure containerd://1.7.1+azure-1
124-
aksnpwin000000 Ready agent 160m v1.25.6 10.224.0.62 <none> Windows Server 2022 Datacenter 10.0.20348.1787 containerd://1.6.21+azure
159+
NAME INTERNAL_IP
160+
aks-nodepool1-19409214-vmss000003 10.224.0.8
125161
```
126162

127163
In the previous example, *10.224.0.62* is the internal IP address of the Windows Server node.
@@ -154,73 +190,20 @@ To create the SSH connection to the Windows Server node from another node, use t
154190
> ssh -o 'ProxyCommand ssh -p 2022 -W %h:%p [email protected]' -o PreferredAuthentications=password [email protected]
155191
> ```
156192
157-
### Create the SSH connection to a Windows node using a password
158-
159-
If you didn't create your AKS cluster using the Azure CLI and the `--generate-ssh-keys` parameter, you'll use a password instead of an SSH key to create the SSH connection. To do this with Azure CLI, perform the following steps. Replace `<nodeRG>` with a resource group name and `<vmssName>` with the scale set name in that resource group.
160-
161-
1. Create a root user called `azureuser`.
162-
163-
```azurecli
164-
az vmss update -g <nodeRG> -n <vmssName> --set virtualMachineProfile.osProfile.adminUsername=azureuser
165-
```
166-
167-
2. Create a password for the new root user.
168-
169-
```azurecli
170-
az vmss update -g <nodeRG> -n <vmssName> --set virtualMachineProfile.osProfile.adminPassword=<new password>
171-
```
172-
173-
3. Update the instances to use the above changes.
174-
175-
```azurecli
176-
az vmss update-instances -g <nodeRG> -n <vmssName> --instance-ids '*'
177-
```
178-
179-
4. Reimage the affected nodes so you can connect using your new credentials.
180-
181-
```azurecli
182-
az vmss reimage -g <nodeRG> -n <vmssName> --instance-id <affectedNodeInstanceId>
183-
```
184-
185-
5. Use `kubectl debug` to connect to another node.
186-
187-
```azurecli
188-
kubectl debug node/<nodeName> -it --image=mcr.microsoft.com/dotnet/runtime-deps:6.0
189-
```
190-
191-
6. Open a second terminal to use port forwarding to connect the debug pod to your local computer.
192-
193-
```azurecli
194-
kubectl port-forward <debugPodName> 2022:22
195-
```
196-
197-
7. Open a third terminal to get the IP address of the affected node to initiate the SSH connection. You can get this IP address with `kubectl get nodes -o wide`. The IP address is listed in the **INTERNAL-IP** column. After you have it, use the following command to connect:
198-
199-
```azurecli
200-
ssh -o 'ProxyCommand ssh -p 2022 -W %h:%p [email protected]' azureuser@<affectedNodeIp>
201-
```
202-
203-
8. Enter your password.
204-
205-
### Remove SSH access
206-
207-
When done, `exit` the SSH session, stop any port forwarding, and then `exit` the interactive container session. After the interactive container session closes, delete the pod used for SSH access using the `kubectl delete pod` command.
208-
209-
```bash
210-
kubectl delete pod node-debugger-aks-nodepool1-37663765-vmss000000-bkmmx
211-
```
212-
213193
## Next steps
214194
215-
* To help troubleshoot any issues with SSH connectivity to your clusters nodes, you can [view the kubelet logs][view-kubelet-logs] or [view the Kubernetes master node logs][view-master-logs].
216-
* See [Manage SSH configuration][manage-ssh-node-access] to learn about managing the SSH key on an AKS cluster or node pools.
195+
If you need more troubleshooting data, you can [view the kubelet logs][view-kubelet-logs] or [view the Kubernetes master node logs][view-master-logs].
196+
197+
See [Manage SSH configuration][manage-ssh-node-access] to learn about managing the SSH key on an AKS cluster or node pools.
217198
218199
<!-- INTERNAL LINKS -->
219200
[view-kubelet-logs]: kubelet-logs.md
220201
[view-master-logs]: monitor-aks-reference.md#resource-logs
221202
[install-azure-cli]: /cli/azure/install-azure-cli
222203
[aks-windows-rdp]: rdp.md
204+
[azure-bastion]: ../bastion/bastion-overview.md
223205
[ssh-nix]: ../virtual-machines/linux/mac-create-ssh-keys.md
224206
[ssh-windows]: ../virtual-machines/linux/ssh-from-windows.md
225-
[ssh-linux-kubectl-debug]: #create-an-interactive-shell-connection-to-a-linux-node
207+
[agentpool-rest-api]: /rest/api/aks/agent-pools/get#agentpool
226208
[manage-ssh-node-access]: manage-ssh-node-access.md
209+

0 commit comments

Comments
 (0)