Skip to main content
In this lesson we cover Kubernetes node selectors — the simplest way to constrain where Pods are scheduled. Scenario: you operate a 3-node cluster with two smaller nodes and one larger node (more CPU, memory, or I/O). For resource-heavy workloads (for example, batch data processing), you likely want those Pods to run only on the larger node so they do not contend with lighter workloads on smaller nodes. By default, the Kubernetes scheduler may place any Pod on any node that meets resource requests and other constraints. Without placement rules, a heavy Pod might land on a small node — which can cause performance problems. Node selectors provide a declarative mechanism to require that a Pod be scheduled only onto nodes that have specific labels. How it works (conceptually)
  • Label nodes with key/value pairs that describe their attributes (for example, size=large).
  • Add a nodeSelector to the Pod spec referencing those keys and values.
  • The scheduler matches the Pod’s nodeSelector against node labels and schedules the Pod only onto nodes that satisfy all the required labels.
Example Pod manifest using nodeSelector:
Label the node before creating the Pod. Use kubectl label nodes with the node name and key=value format. For example, to label node node01 as large:
Verify node labels:
Create the Pod from your manifest:
The scheduler will place the Pod on node01 (or any node that has the label size=large).
nodeSelector performs exact key/value matching. Keys and values are case-sensitive, and all key/value pairs specified under nodeSelector must match a node for scheduling to occur.
Limitations and when to use richer scheduling rules
  • nodeSelector supports only equality matches (exact match of key=value).
  • It cannot express logical OR or negation (for example, “large OR medium” or “not small”).
  • It has no notion of preferred vs required — everything listed under nodeSelector is required.
For more complex rules use:
  • Node affinity (supports operators, required vs preferred).
  • Pod affinity / pod anti-affinity (scheduling based on the presence or location of other Pods).
Comparison: nodeSelector vs node affinity References
A presentation slide titled "Node Selectors – Limitations" showing four server nodes (Node 1 labeled Large, Node 4 labeled Medium) with container icons above them. A bullet note reads "Large OR Medium? NOT Small."

Watch Video