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

Node Selectors Basics

Learn how nodeSelector provides simple key-value matching to schedule pods on specific nodes.

Node Selectors Basics

You'll learn how to use nodeSelector to schedule pods onto specific nodes based on simple key-value labels.

The Scheduling Problem

By default, Kubernetes schedules your pods onto any available node that has sufficient resources. But sometimes you need more control—perhaps you want database pods on nodes with SSDs, or GPU workloads on nodes with specialized hardware.

What is nodeSelector?

nodeSelector is the simplest way to constrain which nodes your pod can run on. It works like a filter using key-value pairs (labels). You add labels to your nodes, then specify matching labels in your pod spec. Kubernetes will only schedule that pod on nodes that have all the requested labels.

Think of it like a bouncer at a club: The pod says "I only go where there's label disktype=ssd", and Kubernetes checks each node's labels, only allowing the pod onto matching nodes.

How It Works

First, label your node:

kubectl label nodes node-1 disktype=ssd

Then, in your pod specification, add a nodeSelector:

apiVersion: v1
kind: Pod
metadata:
  name: database-pod
spec:
  containers:
  - name: db
    image: postgres:14
  nodeSelector:
    disktype: ssd

Now this pod will only run on nodes labeled disktype=ssd. If no matching nodes exist, the pod stays Pending.

When to Use It

Use nodeSelector for straightforward requirements: hardware types (SSD vs HDD), environment tiers (prod vs dev nodes), or specialized capabilities (GPU presence). It's perfect when you have clear, simple matching criteria.

Key Takeaway: nodeSelector provides basic label-based scheduling constraints using simple key-value matching, ensuring pods land only on appropriately labeled nodes.