Skip to content

Commit d520648

Browse files
committed
update use-labels.md
1 parent 329d89f commit d520648

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

articles/aks/use-labels.md

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,46 @@ ms.custom: template-how-to
1212

1313
# Use labels in an Azure Kubernetes Service (AKS) cluster
1414

15-
If you have multiple node pools, you may want to add a label during node pool creation. Labels set at the node pool are added to each node in the node pool. These [labels are visible in Kubernetes][kubernetes-labels] for handling scheduling rules for nodes.
15+
If you have multiple node pools, you may want to add a label during node pool creation. These [labels are visible in Kubernetes][kubernetes-labels] for handling scheduling rules for nodes. You can add labels to a node pool anytime, and they will be set on all nodes in the node pool.
1616

1717
In this how-to guide, you'll learn how to use labels in an AKS cluster.
1818

1919
## Prerequisites
2020

2121
You need the Azure CLI version 2.2.0 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-
In addition, this article assumes you have an existing AKS cluster.
23+
## Create an AKS cluster with a label
24+
25+
To create an AKS cluster with a label, use [az aks create][az-aks-create]. Specify the `--node-labels` parameter to set your labels. Labels must be a key/value pair and have a [valid syntax][kubernetes-label-syntax].
26+
27+
```azurecli-interactive
28+
az aks create \
29+
--resource-group myResourceGroup \
30+
--name myAKSCluster \
31+
--node-count 2 \
32+
--nodepool-labels dept=IT costcenter=9000
33+
```
34+
35+
Verify the labels were set by running `kubectl get nodes --show-labels`.
36+
37+
```bash
38+
kubectl get nodes --show-labels | grep -e "costcenter=9000" -e "dept=IT"
39+
```
2440

2541
## Create a node pool with a label
2642

27-
To create a node pool with a label, use [az aks nodepool add][az-aks-nodepool-add]. Specify the name *labelnp* and use the `--labels` parameter to specify *dept=IT* and *costcenter=9999* for labels.
43+
To create a node pool with a label, use [az aks nodepool add][az-aks-nodepool-add]. Specify the name *labelnp* and use the `--labels` parameter to specify *dept=HR* and *costcenter=5000* for labels. Labels must be a key/value pair and have a [valid syntax][kubernetes-label-syntax]
2844

2945
```azurecli-interactive
3046
az aks nodepool add \
3147
--resource-group myResourceGroup \
3248
--cluster-name myAKSCluster \
3349
--name labelnp \
3450
--node-count 1 \
35-
--labels dept=IT costcenter=9999 \
51+
--labels dept=HR costcenter=5000 \
3652
--no-wait
3753
```
3854

39-
> [!NOTE]
40-
> Labels must be a key/value pair and have a [valid syntax][kubernetes-label-syntax].
41-
4255
The following example output from the [az aks nodepool list][az-aks-nodepool-list] command shows that *labelnp* is *Creating* nodes with the specified *nodeLabels*:
4356

4457
```azurecli
@@ -56,34 +69,45 @@ az aks nodepool list -g myResourceGroup --cluster-name myAKSCluster
5669
"provisioningState": "Creating",
5770
...
5871
"nodeLabels": {
59-
"dept": "IT",
60-
"costcenter": "9999"
72+
"costcenter": "5000",
73+
"dept": "HR"
6174
},
6275
...
6376
},
6477
...
6578
]
6679
```
6780

81+
Verify the labels were set by running `kubectl get nodes --show-labels`.
82+
83+
```bash
84+
kubectl get nodes --show-labels | grep -e "costcenter=5000" -e "dept=HR"
85+
```
86+
6887
## Updating labels on existing node pools
6988

70-
To update a label on existing node pools, use [az aks nodepool update][az-aks-nodepool-update]
89+
To update a label on existing node pools, use [az aks nodepool update][az-aks-nodepool-update]. Updating labels on existing node pools will overwrite the old labels with the new labels. Labels must be a key/value pair and have a [valid syntax][kubernetes-label-syntax].
7190

7291
```azurecli-interactive
73-
az aks nodepool update \
74-
--resource-group myResourceGroup \
75-
--cluster-name myAKSCluster \
76-
--name labelnp \
77-
--node-count 1 \
78-
--labels dept=IT costcenter=9999 \
79-
--no-wait
92+
az aks nodepool update \
93+
--resource-group myResourceGroup \
94+
--cluster-name myAKSCluster \
95+
--name labelnp \
96+
--labels dept=ACCT costcenter=6000 \
97+
--no-wait
98+
```
99+
100+
Verify the labels were set by running `kubectl get nodes --show-labels`.
101+
102+
```bash
103+
kubectl get nodes --show-labels | grep -e "costcenter=6000" -e "dept=ACCT"
80104
```
81105

82106
## Unavailable labels
83107

84108
### Reserved system labels
85109

86-
Since the [2021-08-19 API release][aks-release-2021-gh], Azure Kubernetes Service (AKS) has stopped the ability to make changes to AKS reserved labels. Attempting to change these labels will result in an error message.
110+
Since the [2021-08-19 AKS release][aks-release-2021-gh], Azure Kubernetes Service (AKS) has stopped the ability to make changes to AKS reserved labels. Attempting to change these labels will result in an error message.
87111

88112
The following lists of labels are reserved for use by AKS. *Virtual node usage* specifies if these labels could be a supported system feature on virtual nodes.
89113

@@ -126,10 +150,11 @@ The following list of prefixes are reserved for usage by AKS and can't be used f
126150
| Prefix |
127151
| --- |
128152
| kubernetes.azure.com/ |
153+
| kubernetes.io/ |
129154

130155
### Deprecated labels
131156

132-
The following lists of labels are planned for deprecated with the release of Kubernetes v1.24 in July 2022. Customers should change any label references to the recommended substitute.
157+
The following lists of labels are planned for deprecated with the release of [Kubernetes v1.24][aks-release-calendar]. Customers should change any label references to the recommended substitute.
133158

134159
| Label | Recommended substitute | Maintainer |
135160
| --- | --- | --- |
@@ -160,6 +185,8 @@ Learn more about Kubernetes labels at the [Kubernetes labels documentation][kube
160185

161186

162187
<!-- LINKS - internal -->
188+
[aks-release-calendar]: ./supported-kubernetes-versions.md#aks-kubernetes-release-calendar
189+
[az-aks-create]: /cli/azure/aks#az-aks-create
163190
[az-aks-nodepool-add]: /cli/azure/aks#az-aks-nodepool-add
164191
[az-aks-nodepool-list]: /cli/azure/aks/nodepool#az-aks-nodepool-list
165192
[az-aks-nodepool-update]: /cli/azure/aks/nodepool#az-aks-nodepool-update

0 commit comments

Comments
 (0)