Kubernetes Scheduling: Taints, Tolerations, Node Affinity and Topology Spread
Control where pods run: nodeSelector, node affinity, pod affinity and anti-affinity, taints and tolerations.
Published December 2, 2026
By default the scheduler places pods wherever resources allow. Real clusters need more control: GPU workloads on GPU nodes, system components on dedicated nodes, replicas spread across zones so one zone failure does not take down a service. Kubernetes offers a set of complementary scheduling controls for exactly these needs.
The concept
Attraction and requirements are expressed on pods. nodeSelector is the simplest: run only on nodes with these labels. Node affinity adds richer rules, required or preferred. Pod affinity and anti-affinity place pods relative to other pods, for example keeping replicas apart or co-locating a cache with its app. Topology spread constraints distribute pods evenly across zones or nodes with a configurable maximum skew.
Repulsion is expressed on nodes with taints. A tainted node rejects pods unless they declare a matching toleration. Taints reserve nodes (GPU, high-memory, spot instances) for workloads that explicitly opt in. Tolerations alone do not attract pods to tainted nodes; combine them with node affinity when pods must run only there.
The scheduling toolbox
| Mechanism | Set on | Effect | Example |
|---|---|---|---|
| nodeSelector | Pod | Must run on labelled nodes | disktype: ssd |
| Node affinity | Pod | Required/preferred node rules | zone in [ap-south-1a, 1b] |
| Pod anti-affinity | Pod | Keep away from matching pods | One replica per node |
| Topology spread | Pod | Even spread across domains | maxSkew 1 across zones |
| Taint | Node | Repels pods without toleration | gpu=true:NoSchedule |
| Toleration | Pod | Allows scheduling on tainted node | tolerate gpu=true |
Spreading for availability
Dedicated nodes
Practical examples
Spread replicas across zones and nodes
Topology spread constraints for HA.
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector: { matchLabels: { app: api } }
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector: { matchLabels: { app: api } }Reserve GPU nodes
Taint the nodes, then tolerate and target them.
kubectl taint nodes gpu-node-1 gpu=true:NoSchedule
---
spec:
tolerations: [{ key: gpu, operator: Equal, value: "true", effect: NoSchedule }]
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions: [{ key: node-type, operator: In, values: [gpu] }]Check node labels and taints
Know what you are matching against.
kubectl get nodes -L topology.kubernetes.io/zone,node-type
kubectl describe node gpu-node-1 | grep -A2 TaintsCommon mistakes
- Required anti-affinity with more replicas than nodes, leaving pods Pending.
- Tolerations without affinity, so pods may still land on general nodes.
- All replicas in one zone because no spread constraints were set.
- Overly strict rules that make rescheduling impossible during node failures.
Key takeaways
- Affinity and spread constraints attract or distribute pods.
- Taints repel; tolerations permit.
- Spread replicas across zones for availability.
- Prefer "preferred" rules unless a requirement is truly mandatory.
FAQ
What is the difference between NoSchedule and NoExecute?
NoSchedule blocks new pods; NoExecute also evicts existing pods that do not tolerate the taint.
Does the scheduler rebalance pods later?
No. Rules apply at scheduling time; the descheduler project can evict pods to rebalance.
Are topology spread constraints better than anti-affinity?
For even distribution, usually yes; they are more flexible and scale better than pairwise anti-affinity.