CertGrid CertGrid
Hands-on Lab·Certified Kubernetes Administrator

Node Affinity: Required and Preferred

nodeSelector is all or nothing. Node affinity adds expressions and, more importantly, a soft form. Run a required rule that pins every replica to one node, then a preferred rule whose condition matches nothing at all and watch all four replicas schedule anyway.

Scheduling and Placement Guide 40 of 103 Intermediate

Written against the versions above. Node names are this lab's. The placement outcomes are the real scheduler results from this run.

Two workers labelled with zones and one left unlabelled, which is what makes the soft rule observable.
Server NameIP AddressOSRolesCPURAMHDD
CKA1001192.168.0.175Ubuntu 26.04 LTSControl Plane Node2 Core4 GB50 GB
CKA1001-NODE01192.168.0.176Ubuntu 26.04 LTSWorker Node (zone=a)2 Core4 GB50 GB
CKA1001-NODE02192.168.0.177Ubuntu 26.04 LTSWorker Node (zone=b)2 Core4 GB50 GB
CKA1001-NODE03192.168.0.178Ubuntu 26.04 LTSWorker Node (unlabelled)2 Core4 GB50 GB

Before you start

  1. Label two nodes, leave one bare

  2. Required affinity behaves like a nodeSelector with better grammar

  3. Preferred affinity that matches nothing, and schedules anyway

  4. Clean up

Official sources