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
Copy file name to clipboardExpand all lines: articles/aks/use-labels.md
+46-19Lines changed: 46 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,33 +12,46 @@ ms.custom: template-how-to
12
12
13
13
# Use labels in an Azure Kubernetes Service (AKS) cluster
14
14
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.
16
16
17
17
In this how-to guide, you'll learn how to use labels in an AKS cluster.
18
18
19
19
## Prerequisites
20
20
21
21
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].
22
22
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
+
```
24
40
25
41
## Create a node pool with a label
26
42
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]
28
44
29
45
```azurecli-interactive
30
46
az aks nodepool add \
31
47
--resource-group myResourceGroup \
32
48
--cluster-name myAKSCluster \
33
49
--name labelnp \
34
50
--node-count 1 \
35
-
--labels dept=IT costcenter=9999 \
51
+
--labels dept=HR costcenter=5000 \
36
52
--no-wait
37
53
```
38
54
39
-
> [!NOTE]
40
-
> Labels must be a key/value pair and have a [valid syntax][kubernetes-label-syntax].
41
-
42
55
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*:
43
56
44
57
```azurecli
@@ -56,34 +69,45 @@ az aks nodepool list -g myResourceGroup --cluster-name myAKSCluster
56
69
"provisioningState": "Creating",
57
70
...
58
71
"nodeLabels": {
59
-
"dept": "IT",
60
-
"costcenter": "9999"
72
+
"costcenter": "5000",
73
+
"dept": "HR"
61
74
},
62
75
...
63
76
},
64
77
...
65
78
]
66
79
```
67
80
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
+
68
87
## Updating labels on existing node pools
69
88
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].
71
90
72
91
```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"
80
104
```
81
105
82
106
## Unavailable labels
83
107
84
108
### Reserved system labels
85
109
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.
87
111
88
112
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.
89
113
@@ -126,10 +150,11 @@ The following list of prefixes are reserved for usage by AKS and can't be used f
126
150
| Prefix |
127
151
| --- |
128
152
| kubernetes.azure.com/ |
153
+
| kubernetes.io/ |
129
154
130
155
### Deprecated labels
131
156
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.
133
158
134
159
| Label | Recommended substitute | Maintainer |
135
160
| --- | --- | --- |
@@ -160,6 +185,8 @@ Learn more about Kubernetes labels at the [Kubernetes labels documentation][kube
0 commit comments