Kubectl: Add Label to Kubernetes Node

Labels in Kubernetes are used for attaching meta tags to different resources, including nodes.

This helps to organize the nodes and allows to select specific subsets of nodes.

By adding labels to Kubernetes nodes, we can have more control over the resources that we create.

For example, we can make Kubernetes to schedule specific deployments onto nodes with the specific labels only.

In this post I will show how to get, add, overwrite and delete labels from Kubernetes nodes using the kubectl command.

Add Label to Kubernetes Node

To get all kubernetes nodes and show their labels, execute:

$ kubectl get nodes --show-labels

A label can be assigned to a node, as follows:

$ kubectl label node nodeName label=value
- example -
$ kubectl label node node1 region=amer

You can also assign multiple labels to multiple nodes in one command:

$ kubectl label node node1 node2 node3 region=amer env=prod

To overwrite a label – add the --overwrite flag, for example:

$ kubectl label node node1 region=emea --overwrite

To delete a label from a Kubernetes node, execute:

$ kubectl label node nodeName label-
- example -
$ kubectl label node node1 region-
$ kubectl label node node1 env-
Was it useful? Share this post with the world!

Leave a Reply