Use cluster labels in AKS enabled by Azure Arc

Applies to: Azure Stack HCI, version 23H2

If you have multiple node pools, you might want to add a label during node pool creation. Kubernetes labels handle the scheduling rules for nodes.

This article describes how to use labels in a Kubernetes cluster on AKS enabled by Arc.

Create a Kubernetes cluster with a label

  1. Create a Kubernetes cluster with a label using the az aksarc create command and specify the --node-labels parameter to set your labels. Labels must be a key/value pair and have valid syntax.

    az aksarc create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --nodepool-labels dept=IT
    
  2. Verify that the labels were set using the kubectl get nodes --show-labels command:

    kubectl get nodes --show-labels | grep -e "dept=IT"
    

Create a node pool with a label

  1. Create a node pool with a label using the az aksarc nodepool add command and specify a name for the --name parameters and labels for the --labels parameter. Labels must be a key/value pair and have valid syntax.

    The following example creates a node pool named labelnp with the labels dept=HR:

    az aks nodepool add –resource-group myResourceGroup –cluster-name myAKSCluster –name labelnp –node-count 1 –labels dept=HR –no-wait
    

    The following example output from the az aksarc nodepool list command shows the labelnp node pool creates nodes with the specified nodeLabels:

    [
      {
        ...
        "count": 1,
        ...
        "name": "labelnp",
        "orchestratorVersion": "1.15.7",
        ...
        "provisioningState": "Creating",
        ...
        "nodeLabels":  {
          "costcenter": "5000",
          "dept": "HR"
        },
        ...
      },
     ...
    ]
    
  2. Verify the labels were set using the kubectl get nodes --show-labels command:

    kubectl get nodes --show-labels | grep -e "dept=HR"
    

Unavailable labels

AKS enabled by Azure Arc follows the same rules as AKS:

  • You can't change the reserved system label. If you attempt to do so, an error is returned.
  • The Kubernetes and AKS reserved prefixes can't be used for any node.

For more information, see Unavailable labels in the AKS documentation.

Next steps

For more information about Kubernetes labels, see the Kubernetes documentation.