Labelling and assign roles on nodes

If you want to add labels and assign roles to your nodes, you must edit the Cluster object, and add the labels under spec.topology.workers.metadata :

yaml
workers: machineDeployments: - class: workeramd64hcloud name: md-0 replicas: 5 failureDomain: nbg1 metadata: // [!code ++] labels: // [!code ++] node-role.kubernetes.io/backend: 'true' // [!code ++] node.cluster.x-k8s.io/environment: 'production' // [!code ++] variables: overrides: - name: workerMachineTypeHcloud value: cpx31 - name: workerMachinePlacementGroupNameHcloud value: md-0

For the label to propagate to the node in the workload cluster, it should meet one of the following criteria:

  • Has node-role.kubernetes.io as prefix, e.g. node-role.kubernetes.io/worker: ''
  • Belongs to node-restriction.kubernetes.io domain, e.g. node-restriction.kubernetes.io/location: 'fsn1'
  • Belongs to node.cluster.x-k8s.io domain, e.g. node.cluster.x-k8s.io/environment: 'production'

You can create new machine deployments and separate your node labels however you like. For example, you might have the same five machines, but three with label node.cluster.x-k8s.io/environment: production and two with node.cluster.x-k8s.io/environment: staging :

yaml
workers: machineDeployments: - class: workeramd64hcloud name: md-0 replicas: 5 // [!code --] replicas: 3 // [!code ++] failureDomain: nbg1 metadata: labels: node-role.kubernetes.io/backend: 'true' node.cluster.x-k8s.io/environment: 'production' variables: overrides: - name: workerMachineTypeHcloud value: cpx31 - name: workerMachinePlacementGroupNameHcloud value: md-0 - class: workeramd64hcloud // [!code ++] name: md-1 // [!code ++] replicas: 2 // [!code ++] failureDomain: nbg1 // [!code ++] metadata: // [!code ++] labels: // [!code ++] node-role.kubernetes.io/backend: 'true' // [!code ++] environment: 'staging' // [!code ++] variables: // [!code ++] overrides: // [!code ++] - name: workerMachineTypeHcloud // [!code ++] value: cpx31 // [!code ++] - name: workerMachinePlacementGroupNameHcloud // [!code ++] value: md-0 // [!code ++]
Previous
How to add baremetal servers to your cluster
Next
Remove specific nodes