Kubernetes Labels: Node, Namespace, Pod Labelling with Examples

In Kubernetes, labels are foundational to how DevOps teams organize, automate, and scale infrastructure. They act as metadata tags—simple key-value pairs that define what a resource is, what it does, and how it should behave within the cluster.

Node, Pod and Namespace labels, in particular, play a key role in workload placement, environment segregation, and traffic management, forming the backbone of affinity rules, selectors, and deployment automation.

What are Labels in Kubernetes?

Have you ever wondered what a label actually is in Kubernetes and why it matters so much?

A label in Kubernetes is simply a key–value pair attached to objects like Pods, Nodes, and Deployments — but it’s far more powerful than it looks. Labels are used to categorize and identify resources, helping you group workloads by app, environment, or version.

Types of Labels?

While there aren’t formal “types” of labels, Devops commonly uses organizational labels like app, component, or tier, and environment-based ones like env=dev or env=prod.

Thinking about label restrictions?

Both label keys and values have strict syntax and length limits — each key must be unique per object, the value can’t exceed 63 characters, and keys can include an optional DNS-style prefix up to 253 characters. These label rules apply to both Pods and Nodes, ensuring consistent structure across the cluster.

For example:

labels:
  environment: production
  app: frontend

To stay compliant with best practices, Kubernetes also defines recommended standard labels such as app.kubernetes.io/name and app.kubernetes.io/component, which make automation, selectors, and CI/CD integrations more reliable.

In short, labels in Kubernetes aren’t just metadata — they’re the foundation of how you organize, query, and scale workloads efficiently.


What is a Node Label in Kubernetes

A Node label identifies a Node’s characteristics or intended workload type.
It helps control Pod placement and optimize infrastructure utilization.

labels:
  node-role.kubernetes.io/worker: ""
  instance-type: high-memory
  region: us-east

You might have:

  • Backend services needing high CPU → scheduled on node-type=backend
  • ML jobs needing GPU nodes → scheduled on node-type=gpu
  • Logging or monitoring agents → scheduled on specific infra=true nodes

This makes infrastructure management predictable and scalable.

How to Add a Label to a Node

This command adds a new label to a specific node.

kubectl label node <node-name> <key>=<value>

Example:
kubectl label node worker-node-1 env=production

In real-world DevOps environments, labeling nodes is a best practice for workload placement and environment segregation.

For example, adding labels like env=production or tier=backend helps control where specific workloads should run through node affinity rules, ensuring performance and compliance needs are consistently met.

How to Get Node Labels

This command lists all nodes along with their attached labels.

kubectl get nodes --show-labels

It’s commonly used to audit and verify node configurations before applying scheduling constraints. DevOps engineers often run this command to confirm that node labels are consistent — especially in clusters with dedicated hardware for databases, caching, or frontend workloads.

How to Change Node Label

This command updates or replaces an existing node label.

kubectl label node <node-name> <key>=<new-value> --overwrite

Example:
kubectl label node worker-node-1 env=staging --overwrite

In production pipelines, this is frequently done when reclassifying nodes — such as converting a staging node into production or reallocating compute resources for testing. It ensures that the node’s label-based rules (like affinities or taints) align with its current operational purpose.

How to Remove a Label from Node

This command removes an existing label from a node.

kubectl label node <node-name> <key>-

Example:
kubectl label node worker-node-1 env-

Removing node labels is useful during infrastructure cleanup or reconfiguration, especially when decommissioning certain roles or resetting nodes for fresh workloads. It prevents unintended scheduling behaviors that could occur if outdated labels remain on reused nodes.


What is Pod Label in Kubernetes

A Pod label classifies Pods into logical groups — e.g., by application, version, or environment.

Example:

labels:
  app: payment-service
  env: production

These labels are used by:

  • Services → to route traffic to correct Pods
  • Deployments → to identify and manage ReplicaSets
  • Monitoring tools → to filter metrics per environment or app

How to Add Label to Pod

kubectl label pod web-app app=frontend

This command adds a new label app=frontend to the pod named web-app. Labels like this are crucial in Kubernetes for organizing, selecting, and managing workloads.

In real-world DevOps workflows, engineers often label pods to associate them with specific applications, environments, or deployment stages.

How to Get Pod Labels

Want to see all labels assigned to your Pods?

Just run “kubectl get pods --show-labels” or filter them using “kubectl get pods -l env=prod“.

kubectl get pods --show-labels

This command lists all pods along with their attached labels in a given namespace. It’s especially useful for verifying label-based configurations like node affinity, pod affinity, or service selectors.

How to Change Pod Label

kubectl label pod <pod-name> <key>=<new-value> --overwrite

Example:
kubectl label pod web-app app=backend --overwrite

This code updates or replaces the existing env label on the web-app pod. In DevOps workflows, this is particularly useful during canary or progressive deployments, where traffic is gradually shifted between different versions of an application.

For example, you might have pods labeled version=v1 and version=v2, and the Service selector decides which version receives requests. Updating labels dynamically allows teams to control traffic flow, promote a canary version to production, or roll back instantly if issues arise.

It’s also used in automated pipelines to reassign environments (like env=stagingenv=prod) without redeploying the entire pod, ensuring faster, safer rollout adjustments.

How to Remove Label from Pod

kubectl label pod <pod-name> <key>-

Example:
kubectl label pod web-app env-

This command is often used in real-world DevOps workflows to clean up or reset pod metadata after a rollout, canary deployment, or automated test cycle.

For example, during a blue-green or staging deployment, engineers may temporarily label pods to group them by environment (env=staging, env=prod) for monitoring or routing traffic.

Once validation is complete, removing those labels prevents confusion and ensures production metrics or policies aren’t affected by leftover test labels. It’s also helpful in CI/CD pipelines where automation scripts dynamically add and remove labels for tracking, scheduling, or cleanup after a job completes.


What is Namespace Label in Kubernetes

In K8s, a namespace label is simply a key–value pair attached to a namespace.

How to Add Label to Namespace

You can add a label to a namespace when creating it in YAML under the metadata.labels field, or later using:

kubectl label namespace dev env=prod

How to Get Namespace Labels

To get namespace labels, use kubectl get namespace --show-labels or kubectl get ns dev --show-labels for a specific one.

kubectl get namespace --show-labels

How to Change Namespace Labels

If you need to change a namespace label, simply reapply it with a new value using the same command — Kubernetes will overwrite the old one.

How to Remove Namespace Labels

And to remove a namespace label, use the - suffix, like:

kubectl label namespace dev env-

Summary

Labels in Kubernetes are more than identifiers — they’re control mechanisms that make large-scale automation possible. By labeling Nodes, Pods and Namespace effectively, DevOps teams can dictate where workloads run, streamline blue-green or canary releases, and ensure consistent environment management.

Mastering label operations — adding, changing, viewing, and removing — gives engineers full command over cluster organization and workload behavior. In real-world DevOps pipelines, these small key-value pairs often decide the success of scaling strategies, cost optimization, and zero-downtime deployments.

Author

Sharukhan is the founder of Tecktol. He has worked as a software engineer specializing in full-stack web development.