Labeling Nodes and MachineSets

Labeling Nodes

As an OKD cluster administrator, you can add additional labels to your nodes. For example, you might label nodes with the env label using the values of dev, qa, or prod with the intent that development, quality assurance, and production workloads will be deployed to a specific subset of nodes.

The labels you choose are arbitrary, but you must publish the labels and their associated values to your developers so that they can configure their applications appropriately.

Use the oc label command as a cluster administrator to immediately add, update, or remove a node label. For example, use the following command to label a node with env=dev:

oc label node node1.compute.internal env=dev

Use the --overwrite option to change an existing label.

oc label node node1.compute.internal env=prod --overwrite

Remove a label by specifying the label name followed by a hyphen, such as env-.

oc label node node1.compute.internal env

Use the --show-labels option with the oc get nodes command to see the case-sensitive labels assigned to a node.

oc get node node2.compute.internal --show-labels

Notice that a node might have several default labels assigned by OKD. Labels whose keys include the suffix should not be changed by a cluster administrator because they are used internally by the scheduler.

Cluster administrators can also use the -L option to determine the value of a single label. For example:

oc get node -L

Multiple -L options in the same oc get command are supported. For example:

oc get node -L \
> -L -L env

Labeling Machine Sets

Although node labels are persistent, if your OKD cluster contains machine sets (created if your cluster was installed using the full stack automation method), then you should also add labels to the machine set configuration. This ensures that new machines (and the nodes generated from them) will also contain the desired labels.

You can identify the relationship between machines and nodes by listing machines in the openshift-machine-api namespace and including the -o wide option.

oc get machines -n openshift-machine-api -o wide

Machines used for worker nodes should come from a machine set. The name of a machine contains the name of the machine set from which it was generated.

oc get machineset -n openshift-machine-api

Edit a machine set so that new machines generated from it will have the desired label or labels. Modifying a machine set will not apply changes to existing machines or nodes. For example:

oc edit machineset ocp-qz7hf-worker-us-west-1b \
> -n openshift-machine-api