K8s by Example: Node Affinity
| Node affinity constrains Pods to run on nodes with specific labels. Unlike nodeSelector (simple key-value matching), node affinity supports complex expressions with operators like In, NotIn, Exists, and Gt. Use for: GPU workloads, zone placement, hardware requirements, licensing constraints. |
| node-affinity-required.yaml | |
|
| |
| node-affinity-preferred.yaml | |
|
| |
| node-affinity-operators.yaml | |
| Match expressions support operators: | |
| node-affinity-zone.yaml | |
| Zone-based scheduling using standard Kubernetes topology labels. Combine with | |
| node-affinity-combined.yaml | |
| Combine required and preferred affinities. Required rules must match; preferred rules influence scheduling among matching nodes. Multiple terms in | |
| terminal | |
| Label nodes to enable affinity rules. View existing labels to understand available scheduling options. Common labels include architecture, zone, instance type, and custom labels for your workloads. | |