Skip to main content

Labelling and assign roles on nodes

Editing the Cluster Object#

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:
        labels:
          node-role.kubernetes.io/backend: "true"
          node.cluster.x-k8s.io/environment: "production"
      variables:
        overrides:
          - name: workerMachineTypeHcloud
            value: cpx42
          - name: workerMachinePlacementGroupNameHcloud
            value: md-0
	

Label Propagation Criteria#

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'

Machine Deployments Example#

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
      replicas: 3
      failureDomain: nbg1
      metadata:
        labels:
          node-role.kubernetes.io/backend: "true"
          node.cluster.x-k8s.io/environment: "production"
      variables:
        overrides:
          - name: workerMachineTypeHcloud
            value: cpx42
          - name: workerMachinePlacementGroupNameHcloud
            value: md-0
    - class: workeramd64hcloud
      name: md-1
      replicas: 2
      failureDomain: nbg1
      metadata:
        labels:
          node-role.kubernetes.io/backend: "true"
          node.cluster.x-k8s.io/environment: "staging"
      variables:
        overrides:
          - name: workerMachineTypeHcloud
            value: cpx42
          - name: workerMachinePlacementGroupNameHcloud
            value: md-0