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
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 30 min
- Reviewed21 August 2026
Written against the versions above. Node names are this lab's. The placement outcomes are the real scheduler results from this run.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node (zone=a) | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node (zone=b) | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node (unlabelled) | 2 Core | 4 GB | 50 GB |
Before you start
- At least three workers, so a spread is visible.
- The Labels and Selectors guide. Affinity is built on the same expressions.
- Permission to label nodes.
-
Label two nodes, leave one bare
-
Required affinity behaves like a nodeSelector with better grammar
-
Preferred affinity that matches nothing, and schedules anyway
-
Clean up