Course contentsShow
← Cloud and Infrastructure
Lesson 1345 of 2,98927. Kubernetes Scheduling and ResourcesFree lesson

Labeling Nodes for Selection

Understand how to add labels to nodes and use them in pod specifications for scheduling.

Labeling Nodes for Selection

What you'll learn: How to add custom labels to your Kubernetes nodes and reference them in pod specifications to control where pods run.

The Core Idea

Now that you understand node selectors, you need to know how to prepare your nodes by giving them meaningful labels. Think of labels as tags you attach to nodes to describe their characteristics—like "has-gpu=true" or "environment=production"—so you can later use those tags to guide pod placement.

Adding Labels to Nodes

You use kubectl label to tag nodes with key-value pairs:

kubectl label nodes worker-node-1 disktype=ssd
kubectl label nodes worker-node-2 gpu=nvidia-t4
kubectl label nodes worker-node-3 environment=production

To verify your labels:

kubectl get nodes --show-labels

Or filter nodes by a specific label:

kubectl get nodes -l disktype=ssd

Using Node Labels in Pod Specs

Once your nodes are labeled, reference those labels in your pod's nodeSelector:

apiVersion: v1
kind: Pod
metadata:
  name: gpu-workload
spec:
  nodeSelector:
    gpu: nvidia-t4
  containers:
  - name: training-container
    image: ml-training:latest

This pod will only schedule on nodes with the label gpu=nvidia-t4.

Practical Analogy

Labeling nodes is like putting colored stickers on boxes in a warehouse. Later, when you need to store something temperature-sensitive, you can say "only use boxes with the blue 'refrigerated' sticker"—you don't need to know specific box IDs, just the characteristic you need.

Key Takeaway: Label your nodes with meaningful key-value pairs using kubectl label, then use those labels in nodeSelector to control pod placement based on node characteristics.