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 label dept=HR:

    az aksarc 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"
    

Update labels on existing node pools

  1. Update a label on an existing node pool using the az aksarc nodepool update command. Updating labels on existing node pools overwrites the old labels with the new labels. Labels must be key/value pairs and have a valid syntax.

    az aksarc nodepool update --resource-group myResourceGroup --cluster-name myAKSCluster --name labelnp --labels dept=ACCT costcenter=6000 --no-wait
    
  2. Verify the labels were set using the kubectl get nodes --show-labels command.

    kubectl get nodes --show-labels | grep -e "costcenter=6000" -e "dept=ACCT"
    

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.