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

MechanismSet onEffectExample
nodeSelectorPodMust run on labelled nodesdisktype: ssd
Node affinityPodRequired/preferred node ruleszone in [ap-south-1a, 1b]
Pod anti-affinityPodKeep away from matching podsOne replica per node
Topology spreadPodEven spread across domainsmaxSkew 1 across zones
TaintNodeRepels pods without tolerationgpu=true:NoSchedule
TolerationPodAllows scheduling on tainted nodetolerate gpu=true

Spreading for availability

Deployment api (6 replicas)Topology spreadmaxSkew 1 by zonezone a2 podszone b2 podszone c2 pods
Spreading replicas across zones survives a zone outage.

Dedicated nodes

GPU nodetaint gpu=true:NoScheduleRegular podno toleration → rejectedML podtoleration + node affinity → scheduled
Taints reserve nodes; tolerations plus affinity target them.

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 Taints

Common 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.

More DevOps articles