> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Add or Remove Labels to Nodes in Kubernetes
- URL: https://linuxhandbook.com/kubectl-label-node/
- Published: 2020-10-07T06:17:18.000Z
- Updated: 2022-10-13T15:43:46.000Z
- Description: Learn to add labels to nodes in Kubernetes, change the labels and remove those labels later.
- Author: Rakesh Jain
- Tags: Using Kubernetes

When you work on a real-time environment there will be times when you want to run a specific type of workloads (or application) a designated worker node.

For example, production workloads should be running on specific worker nodes and shouldn't get mixed with staging or development workloads.

This is where adding labels to the node will be helpful.

Let me show you how to add labels to nodes in [Kubernetes](https://kubernetes.io/?ref=linuxhandbook.com), change the labels and remove those labels later.

## How to read node labels in Kubernetes

You can [list Kubernetes node details](https://linuxhandbook.com/read-nodes-kubernetes/) along with their labels in this fashion:

```shell
kubectl get nodes --show-labels

```

If you want to know the details for a specific node, use this:

```
kubectl label --list nodes node_name
```

> The labels are in form of key-value pair. They must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to 63 characters each.

## How to assign label to a node

Now suppose you want `kworker-rj1` node to host all the production related workloads.

Let's label that node with an appropriate name (like production):

```bash
root@kmaster-rj:~# kubectl label nodes kworker-rj1 workload=production
node/kworker-rj1 labeled

```

Confirm the pod labelling:

```bash
root@kmaster-rj:~# kubectl label --list nodes kworker-rj1 | grep -i workload
workload=production

```

I used the [grep command](https://linuxhandbook.com/grep-command-examples/) to weed out unnecessary details and focus on the label.

## How to overwrite the node label 

If you later decide to overwrite some labels based on the requirements see how you can achieve that.

```bash
root@kmaster-rj:~# kubectl label --overwrite nodes kworker-rj1 workload=staging
node/kworker-rj1 labeled

```

You may confirm the pod re-labelling:

```bash
root@kmaster-rj:~# kubectl label --list nodes kworker-rj1 | grep -i workload
workload=staging

```

[ ![Linux Foundation Kubernetes Certification Discount](https://linuxhandbook.com/content/images/2022/10/lf-foundation-kubernetes.webp) ](https://linuxhandbook.com/training/kubernetes-fundamentals)

## How to remove the node labels

To remove the label from a node, provide the key without any value.

```bash
root@kmaster-rj:~# kubectl label --overwrite nodes kworker-rj1 workload-
node/kworker-rj1 labeled

```

You can confirm the node label removal:

```bash
root@kmaster-rj:~# kubectl label --list nodes kworker-rj1 | grep -i workload
root@kmaster-rj:~#

```

That's all! I hope you got familiar with the kubectl label command with this tutorial.