You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Connect to Azure Kubernetes Service (AKS) cluster nodes
3
3
description: Learn how to connect to Azure Kubernetes Service (AKS) cluster nodes for troubleshooting and maintenance tasks.
4
-
ms.topic: article
5
-
ms.date: 12/20/2023
4
+
ms.topic: troubleshooting
5
+
ms.date: 01/08/2024
6
6
ms.reviewer: mattmcinnes
7
7
ms.custom: contperf-fy21q4, devx-track-linux
8
8
#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.
9
9
---
10
10
11
11
# Connect to Azure Kubernetes Service (AKS) cluster nodes for maintenance or troubleshooting
12
12
13
-
Throughout the lifecycle of your Azure Kubernetes Service (AKS) cluster, you might need to access an AKS node. This access could be for maintenance, log collection, or troubleshooting operations. You can securely authenticate against AKS Linux and Windows nodes using SSH, and you can also [connect to Windows Server nodes using remote desktop protocol (RDP)][aks-windows-rdp]. For security reasons, the AKS nodes aren't exposed to the internet. To connect to the AKS nodes, you use `kubectl debug` or the private IP address.
13
+
Throughout the lifecycle of your Azure Kubernetes Service (AKS) cluster, you eventually need to directly access an AKS node. This access could be for maintenance, log collection, or troubleshooting operations.
14
14
15
-
This article shows you how to create a connection to an AKS node and update the SSH key on an existing AKS cluster.
15
+
You access a node through authentication, which methods vary depending on your Node OS and method of connection. You securely authenticate against AKS Linux and Windows nodes using SSH. Alternatively, for Windows Servers you can also connect to Windows Server nodes using the [remote desktop protocol (RDP)][aks-windows-rdp].
16
+
17
+
For security reasons, AKS nodes aren't exposed to the internet. Instead, to connect directly to any AKS nodes, you need to use either `kubectl debug` or the host's private IP address.
18
+
19
+
This guide shows you how to create a connection to an AKS node and update the SSH key of your AKS cluster.
16
20
17
21
## Before you begin
18
22
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.
23
+
To follow along the steps, you need to use Azure CLI that supports version 2.0.64 or later. Run `az --version` to check the version. If you need to install or upgrade, see [Install Azure CLI][install-azure-cli].
24
+
25
+
Complete these steps if you don't have an SSH key. Create an SSH key depending on your Node OS Image, for [macOS and Linux][ssh-nix], or [Windows][ssh-windows]. Make sure you save the key pair in the OpenSSH format, avoid unsupported formats such as `.ppk`. Next, refer to [Manage SSH configuration][manage-ssh-node-access] to add the key to your cluster.
26
+
27
+
## Linux and macOS
20
28
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].
29
+
Linux and macOS users can SSH to access their node using `kubectl debug`or their private IP Address. Windows users should skip to the Windows Server Proxy section for a workaround to SSH via proxy.
22
30
23
-
##Create an interactive shell connection to a Linux node using kubectl
31
+
### SSH using kubectl debug
24
32
25
-
To create an interactive shell connection to a Linux node, use the `kubectl debug` command to run a privileged container on your node.
33
+
To create an interactive shell connection, use the `kubectl debug` command to run a privileged container on your node.
26
34
27
35
1. To list your nodes, use the `kubectl get nodes` command:
28
36
29
37
```bash
30
38
kubectl get nodes -o wide
31
39
```
32
40
33
-
The following example resembles output from the command:
41
+
Sample output:
34
42
35
43
```output
36
44
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE
@@ -39,44 +47,49 @@ To create an interactive shell connection to a Linux node, use the `kubectl debu
39
47
aksnpwin000000 Ready agent 160m v1.25.6 10.224.0.62 <none> Windows Server 2022 Datacenter
40
48
```
41
49
42
-
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.
50
+
2. Use the `kubectl debug`command to start a privileged container on your node and connect to it.
The following example resembles output from the command:
56
+
Sample output:
49
57
50
58
```output
51
59
Creating debugging pod node-debugger-aks-nodepool1-37663765-vmss000000-bkmmx with container debugger on node aks-nodepool1-37663765-vmss000000.
52
60
If you don't see a command prompt, try pressing enter.
53
61
root@aks-nodepool1-37663765-vmss000000:/#
54
62
```
55
63
56
-
This privileged container gives access to the node.
64
+
You now have access to the node through a privileged container as a debugging pod.
57
65
58
66
> [!NOTE]
59
67
> You can interact with the node session by running `chroot /host` from the privileged container.
60
68
61
-
### Remove Linux node access
69
+
### Exit kubectl debug mode
62
70
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 usedfor access with `kubectl delete pod`.
71
+
When you're done with your node, enter the `exit`command to end the interactive shell session. After the interactive container session closes, delete the debugging pod used with `kubectl delete pod`.
64
72
65
73
```bash
66
74
kubectl delete pod node-debugger-aks-nodepool1-37663765-vmss000000-bkmmx
67
75
```
68
-
## Create an interactive shell connection to a node using private IP
69
76
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.
77
+
## Private IP Method
78
+
79
+
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 Agent Pool Preview API][agent-pool-rest-api] (preview version 07-02-2023 or above) to troubleshoot node-specific issues in your AKS node pools.
80
+
81
+
### Create an interactive shell connection to a node using the IP address
82
+
83
+
For convenience, the nodepools are exposed when the node has a public IP assigned. However, you need to be in the cluster's virtual network to SSH into the node.
71
84
72
-
1. To get the private IP via CLI, use az cli version 2.53 or above with aks-preview extension installed.
85
+
1. To get the private IP, use the `machine list` to show all your VMs.
73
86
74
87
```bash
75
88
az aks machine list --resource-group myResourceGroup --cluster-name myAKSCluster --nodepool-name nodepool1 -o table
76
89
77
90
```
78
91
79
-
The following example resembles output from the command:
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.
115
+
2. SSH using your private IP address to access your node.
3. Optionally, you can test with Azure Bastion. Follow these steps to set up [Azure Bastion][azure-bastion] to test your connection to your virtual machines using a private IP address. Make sure that the Azure Bastion is hosted in the same virtual network as your VM.
109
122
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.
123
+
## Windows Server proxy connection
111
124
112
-
To connect to another node in the cluster, use the `kubectl debug` command. For more information, see the Linux section.
125
+
Follow these steps as a workaround to connect with SSH on a Windows Server node.
113
126
114
-
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.
127
+
### Create a proxy server
128
+
129
+
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 with `kubectl`, 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].
130
+
131
+
To connect to another node in the cluster, use the `kubectl debug` command. For more information, follow the above steps in the kubectl section. Create an SSH connection to the Windows Server node from another node, and use the SSH keys provided when you created the AKS cluster and the internal IP address of the Windows Server node.
115
132
116
133
> [!IMPORTANT]
117
134
>
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].
135
+
> 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. The AKS Update command can also be used to manage, create SSH keys on an existing AKS cluster. For more information, see [manage SSH node access][manage-ssh-node-access].
136
+
137
+
Finish the prior steps to use kubectl debug, then return to this section, as you need to run the `kubectl debug` in your proxy.
119
138
120
139
1. Open a new terminal window and use the `kubectl get pods` command to get the name of the pod started by `kubectl debug`.
121
140
122
141
```bash
123
142
kubectl get pods
124
143
```
125
144
126
-
The following example resembles output from the command:
The following example resembles output from the command:
190
+
Sample output:
172
191
173
192
```output
174
193
The authenticity of host '10.224.0.62 (10.224.0.62)' can't be established.
175
194
ECDSA key fingerprint is SHA256:1234567890abcdefghijklmnopqrstuvwxyzABCDEFG.
176
195
Are you sure you want to continue connecting (yes/no)? yes
177
-
178
-
[...]
179
-
180
-
Microsoft Windows [Version 10.0.17763.1935]
181
-
(c) 2018 Microsoft Corporation. All rights reserved.
182
-
183
-
azureuser@aksnpwin000000 C:\Users\azureuser>
184
196
```
185
197
186
198
> [!NOTE]
@@ -192,18 +204,18 @@ To create the SSH connection to the Windows Server node from another node, use t
192
204
193
205
## Next steps
194
206
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].
207
+
If you need more troubleshooting data, you can [view the kubelet logs][view-kubelet-logs] or [view the Kubernetes control plane logs][view-control-plane-logs].
196
208
197
-
See [Manage SSH configuration][manage-ssh-node-access] to learn about managing the SSH key on an AKS cluster or node pools.
209
+
To learn about managing your SSH keys, see [Manage SSH configuration][manage-ssh-node-access].
0 commit comments