Skip to content

Commit debc8b6

Browse files
committed
Updated SSH key doc
1 parent 8a387e2 commit debc8b6

File tree

2 files changed

+205
-26
lines changed

2 files changed

+205
-26
lines changed

articles/operator-nexus/howto-kubernetes-cluster-manage-ssh-key.md

Lines changed: 193 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ There are a few different ways that you can provide SSH keys for your cluster no
3030
* If you want to use different SSH keys for different agent pools or control plane nodes, you can provide a unique public key for each pool, allows you to manage SSH access more granularly, this overrides the cluster wide keys. Any new agent pool gets added to the cluster later without keys use the cluster wide keys, if it has key then it uses the provided key.
3131
* If you don't provide any SSH keys when creating your cluster, no SSH keys are inserted into the nodes. This means that users can't SSH into the nodes. You can add SSH keys later by updating the cluster configuration, but can't remove those keys once added.
3232

33-
Refer the [Disconnected mode access](./howto-kubernetes-cluster-connect.md#disconnected-mode-access) guide for steps to find the cluster node IP address.
33+
<!-- Refer the [Disconnected mode access](./howto-kubernetes-cluster-connect.md#disconnected-mode-access) guide for steps to find the cluster node IP address. -->
3434

3535
### [Azure CLI](#tab/azure-cli)
3636

37-
Following are the variables you need to set, along with the [quickstart guide](./quickstarts-kubernetes-cluster-deployment-cli.md#create-an-azure-nexus-kubernetes-cluster) default values you can use for certain variables.
37+
Following are the variables you need to set, along with the [QuickStart guide](./quickstarts-kubernetes-cluster-deployment-cli.md#create-an-azure-nexus-kubernetes-cluster) default values you can use for certain variables.
3838

3939
* `SSH_PUBLIC_KEY` - For the cluster wide keys. Note that using cluster wide key with agent pool and control plane keys doesn't have any effect as the control plane and agent pool keys are used instead of the cluster wide keys.
4040
* `CONTROL_PLANE_SSH_PUBLIC_KEY` - For the control plane, you can provide public keys that are inserted into the control plane nodes.
@@ -64,30 +64,55 @@ Following are the variables you need to set, along with the [quickstart guide](.
6464
dns-service-ip="${DNS_SERVICE_IP}"
6565
```
6666

67-
### [Azure ARM/Bicep](#tab/other)
67+
### [Azure ARM](#tab/other)
6868

69-
The `administratorConfiguration` can be inserted into the `properties` object for the cluster wide keys, and into the `initialAgentPoolConfigurations[].administratorConfiguration` object for each agent pool. The `controlPlaneNodeConfiguration.administratorConfiguration` object is used for the control plane. Update the quickstart ARM template and Bicep templates with the required keys, and in required object.
69+
The `administratorConfiguration` can be inserted into the `properties` object for the cluster wide keys, and into the `initialAgentPoolConfigurations[].administratorConfiguration` object for each agent pool. The `controlPlaneNodeConfiguration.administratorConfiguration` object is used for the control plane.
7070

71-
```arm
72-
"administratorConfiguration": {
73-
"adminUsername": "[parameters('adminUsername')]",
74-
"sshPublicKeys": [
71+
Update the quickstart ARM template or Bicep template parameters with the required keys so that the keys are inserted into the nodes when the cluster is created.
72+
73+
#### To provide cluster wide keys
74+
75+
```json
76+
"sshPublicKeys": {
77+
"value": [
78+
{
79+
"keyData": "ssh-rsa AAAAA...."
80+
},
7581
{
76-
"keyData": "[parameters('sshPublicKey')]"
82+
"keyData": "ssh-rsa BBBBB...."
7783
}
7884
]
7985
}
8086
```
8187

82-
```bicep
83-
administratorConfiguration: {
84-
adminUsername: adminUsername
85-
sshPublicKeys: [
86-
{
87-
keyData: sshPublicKey
88-
}
89-
]
90-
}
88+
#### To provide keys for the control plane
89+
90+
```json
91+
"controlPlaneSshKeys": {
92+
"value": [
93+
{
94+
"keyData": "ssh-rsa AAAAA...."
95+
},
96+
{
97+
"keyData": "ssh-rsa BBBBB...."
98+
}
99+
]
100+
}
101+
```
102+
103+
#### To provide keys for the agent pool
104+
105+
```json
106+
"agentPoolSshKeys": {
107+
"value": [
108+
{
109+
"keyData": "ssh-rsa AAAAA...."
110+
},
111+
{
112+
"keyData": "ssh-rsa BBBBB...."
113+
}
114+
]
115+
}
91116
```
92117

93118
---
@@ -105,32 +130,174 @@ To update the SSH keys, you can apply the same Bicep/ARM configuration used duri
105130
3. If you try to update the agent pool keys or control plane with an empty array, the operation succeeds, and the cluster wide keys are used instead.
106131
4. If you try to update the keys for a cluster that was created without any keys, the new key is added, but you can't remove it.
107132

108-
### Update SSH keys using Azure CLI
133+
### Before you begin
134+
135+
1. Ensure that you have the required permissions to update the cluster configuration.
136+
2. You have the new SSH keys that you want to use for the cluster nodes.
137+
3. You have the parameters file used during the initial deployment or the variables used in the CLI command.
138+
4. To use this guide, you must have an existing Operator Nexus Kubernetes cluster that was created using the quickstart guide.
109139

110-
#### Update cluster wide SSH keys
140+
### Update cluster wide SSH keys
111141

112-
Use the following command to update the cluster wide SSH keys, which are used for all nodes in the cluster. All the nodes in the cluster will be updated with the new keys if the clster was created with only cluster wide keys.
142+
Use the following command to update the cluster wide SSH keys, which are used for all nodes in the cluster. The existing keys are replaced with the new keys.
143+
144+
> [!NOTE]
145+
> This works only if the cluster was created with cluster wide keys. If the cluster was created with agent pool or control plane keys, this operation has no effect. Refer the next sections to update agent pool or control plane keys.
146+
147+
#### Azure CLI to update cluster wide SSH keys
148+
149+
1. Set the `NEW_CLUSTER_WIDE_KEY` variable with the new SSH key.
150+
151+
```bash
152+
NEW_CLUSTER_WIDE_KEY="ssh-rsa CCCCC...."
153+
```
154+
155+
2. Use the following command to update the cluster wide SSH keys.
113156

114157
```azurecli
115158
az networkcloud kubernetescluster update --name "$CLUSTER_NAME" --resource-group "$RESOURCE_GROUP" --subscription "$SUBSCRIPTION_ID" --ssh-key-values "$CLUSER_WIDE_KEY"
116159
```
117160

118-
#### Update agent pool SSH keys
161+
#### Azure ARM and Bicep to update cluster wide SSH keys
162+
163+
1. Update the `sshPublicKeys` parameter in `kubernetes-deploy-parameters.json` with the new SSH key.
164+
165+
```json
166+
"sshPublicKeys": {
167+
"value": [
168+
{
169+
"keyData": "ssh-rsa CCCCC...."
170+
}
171+
]
172+
}
173+
```
174+
175+
2. Redeploy the template.
176+
177+
for ARM:
178+
179+
```azurecli
180+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-deploy.json --parameters @kubernetes-deploy-parameters.json
181+
```
119182

120-
Use the following command to update the SSH keys for a specific agent pool. All the nodes in the agent pool will be updated with the new keys.
183+
for Bicep:
121184

122185
```azurecli
123-
az networkcloud kubernetescluster agentpool update --agent-pool-name "agentpool1" --kubernetes-cluster-name "$CLUSTER_NAME" --resource-group "$RESOURCE_GROUP" --subscription "$SUBSCRIPTION_ID" --ssh-key-values "$AGENT_POOL_KEY"
186+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-deploy.bicep --parameters @kubernetes-deploy-parameters.json
124187
```
125188

126-
#### Update control plane SSH keys
189+
### Update agent pool SSH keys
190+
191+
Use the following command to update the SSH keys for a specific agent pool.
127192

128-
Use the following command to update the SSH keys for the control plane. All the nodes in the control plane will be updated with the new keys.
193+
* All the nodes in the agent pool will be updated with the new keys.
194+
* If the agent pool was created with keys, the new keys will replace the existing keys.
195+
* If the agent pool was created without keys, the new keys will be added.
196+
* If the agent pool was created with cluster wide keys, the new keys will replace the existing keys.
197+
* If you try to update the keys for a cluster that was created without any keys, the new key is added, but you can't remove it.
198+
* If you try to update the agent pool keys with an empty array, the operation succeeds, and the cluster wide keys are used instead.
199+
200+
#### Azure CLI to update agent pool SSH keys
201+
202+
1. Set the `AGENT_POOL_KEY` variable with the new SSH key.
203+
204+
```bash
205+
AGENT_POOL_KEY="ssh-rsa DDDDD...."
206+
```
207+
208+
2. Use the following command to update the agent pool SSH keys.
209+
210+
```azurecli
211+
az networkcloud kubernetescluster agentpool update --agent-pool-name "${CLUSTER_NAME}-nodepool-2" --kubernetes-cluster-name "$CLUSTER_NAME" --resource-group "$RESOURCE_GROUP" --subscription "$SUBSCRIPTION_ID" --ssh-key-values "$AGENT_POOL_KEY"
212+
```
213+
214+
#### Azure ARM and Bicep to update agent pool SSH keys
215+
216+
> [!NOTE]
217+
> Updating node pools created through initial agent pool configuration is not possible with this method, as there is no separate agent pool template and parameter file. Only the agent pool keys for pools created after cluster creation can be updated using this method. To update the keys for the initial agent pool, refer to the CLI command provided in the previous section. If the initial agent pool was created with cluster wide keys, and if you want to update the keys for the initial agent pool, you can update the cluster wide keys.
218+
219+
1. Update the `agentPoolSshKeys` parameter in `kubernetes-nodepool-parameters.json` with the new SSH key.
220+
221+
```json
222+
"agentPoolSshKeys": {
223+
"value": [
224+
{
225+
"keyData": "ssh-rsa DDDDD...."
226+
}
227+
]
228+
}
229+
```
230+
231+
2. Redeploy the template.
232+
233+
for ARM:
234+
235+
```azurecli
236+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-add-agentpool.json --parameters @kubernetes-nodepool-parameters.json
237+
```
238+
239+
for Bicep:
240+
241+
```azurecli
242+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-add-agentpool.bicep --parameters @kubernetes-nodepool-parameters.json
243+
```
244+
245+
### Update control plane SSH keys
246+
247+
Use the following command to update the SSH keys for the control plane.
248+
249+
* All the nodes in the control plane will be updated with the new keys.
250+
* If the control plane was created with keys, the new keys will replace the existing keys.
251+
* If the control plane was created without keys, the new keys will be added.
252+
* If the control plane was created with cluster wide keys, the new keys will replace the existing keys.
253+
* If you try to update the keys for a cluster that was created without any keys, the new key is added, but you can't remove it.
254+
* If you try to update the control plane keys with an empty array, the operation succeeds, and the cluster wide keys are used instead.
255+
256+
> [!NOTE]
257+
> The control plane keys can be updated using the initial deployment template and parameter file, as the control plane is a part of the cluster. However, agent pool keys cannot be updated in the same way, as the agent pool is a sub-resource, unless the agent pool uses cluster wide keys.
258+
259+
#### Azure CLI to update control plane SSH keys
260+
261+
1. Set the `CONTROL_PLANE_KEY` variable with the new SSH key.
262+
263+
```bash
264+
CONTROL_PLANE_KEY="ssh-rsa EEEEE...."
265+
```
266+
267+
2. Use the following command to update the control plane SSH keys.
129268

130269
```azurecli
131270
az networkcloud kubernetescluster update --name "$CLUSTER_NAME" --resource-group "$RESOURCE_GROUP" --subscription "$SUBSCRIPTION_ID" --control-plane-node-configuration ssh-key-values="['$CONTROL_PLANE_KEY']"
132271
```
133272

273+
#### Azure ARM and Bicep to update control plane SSH keys
274+
275+
1. Update the `controlPlaneSshKeys` parameter in `kubernetes-deploy-parameters.json` with the new SSH key.
276+
277+
```json
278+
"controlPlaneSshKeys": {
279+
"value": [
280+
{
281+
"keyData": "ssh-rsa EEEEE...."
282+
}
283+
]
284+
}
285+
```
286+
287+
2. Redeploy the template.
288+
289+
for ARM:
290+
291+
```azurecli
292+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-deploy.json --parameters @kubernetes-deploy-parameters.json
293+
```
294+
295+
for Bicep:
296+
297+
```azurecli
298+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-deploy.bicep --parameters @kubernetes-deploy-parameters.json
299+
```
300+
134301
## Next steps
135302

136303
By understanding how to configure and manage SSH keys on your Operator Nexus Kubernetes cluster nodes, you can ensure that your cluster is secure and that you can access the nodes when you need to troubleshoot issues.

articles/operator-nexus/includes/kubernetes-cluster/quickstart-bicep-deploy.bicep

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,21 @@ param initialPoolAgentOptions object = {}
124124

125125
@description('The cluster wide SSH public key that will be associated with the given user for secure remote login')
126126
param sshPublicKeys array = []
127+
// {
128+
// keyData: "ssh-rsa AAAAA...."
129+
// },
130+
// {
131+
// keyData: "ssh-rsa AAAAA...."
132+
// }
127133

128134
@description('The control plane SSH public key that will be associated with the given user for secure remote login')
129135
param controlPlaneSshKeys array = []
136+
// {
137+
// keyData: "ssh-rsa AAAAA...."
138+
// },
139+
// {
140+
// keyData: "ssh-rsa AAAAA...."
141+
// }
130142

131143
@description('The agent pool SSH public key that will be associated with the given user for secure remote login')
132144
param agentPoolSshKeys array = []

0 commit comments

Comments
 (0)