This guide explains how to apply custom node labels to worker nodes so that the labels are automatically retained when nodes are recreated or added during scaling.
Tanzu Kubernetes Grid Management
To apply node labels to new or recreated nodes in a workload cluster, follow these steps:
Step 1: List the current KubeadmConfigTemplate objects:
kubectl get KubeadmConfigTemplate -A
Step 2: Take a copy of the template associated with the workload cluster you wish to update:
kubectl get KubeadmConfigTemplate workler-cluster-test -oyaml > KubeadmConfigTemplate-workler-cluster-test.yaml
Step 3: Edit the file and update "metadata.name" to a new name (for example, append -v1)
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
metadata:
.....
name: workload-slot1rp11-legacy-md-0-v1
.....
Step 4: Add the required node labels to "spec.template.spec.joinConfiguration.nodeRegistration.kubeletExtraArgs". In my case, I the following change:
spec:
template:
.....
spec:
.....
joinConfiguration:
.....
nodeRegistration:
.....
kubeletExtraArgs:
.....
node-labels: node-test=test-label
Step 5: Save the file and apply it:
kubectl apply -f KubeadmConfigTemplate-workler-cluster-test.yaml
Step 6: Identify the current MachineDeployment for the cluster and edit it:
kubectl get MachineDeployment
kubectl edit MachineDeployment workler-cluster-test
Step 6: Update the following section to point to the new KubeadmConfigTemplate "spec.template.spec.bootstrap.configRef.name":
spec:
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
name: workload-slot1rp11-legacy-md-0-v1
After the above change is made, a rollout will occur and all worker nodes will have the new label applied.