Use it to control placement, or when pods are Pending because no node matches.
Taints, Tolerations and Affinity
Taints repel pods from nodes unless pods tolerate them; node affinity and nodeSelector attract pods to nodes; pod (anti-)affinity places pods relative to other pods.
1. kubectl describe pod — scheduling message.
2. Node taints: kubectl describe node | grep Taints.
3. Pod tolerations/affinity.
4. Labels on nodes: kubectl get nodes --show-labels.
5. Adjust rules.
pod rules + node taints/labels → scheduler filters → placement
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Read the FailedScheduling message: it lists how many nodes failed each check. Confirm node labels match the affinity rules. Check that spread constraints can be met with the current number of zones.
Step 2 Common failures Narrow the fault
Required anti-affinity with more replicas than nodes leaves Pods Pending. Tolerating a taint without node affinity lets Pods run anywhere. Node labels removed during upgrades break required affinity.
Pending with "node(s) had untolerated taint" or "didn't match node affinity" in events. Prefer soft (preferred) rules unless placement is mandatory.
kubectl describe node | grep Taints— first check for this topickubectl get pods -o wide— pods, status, node, IPkubectl describe pod <pod>— events and conditionskubectl logs <pod> [-c <c>] [--previous]— container logs (incl. previous crash)kubectl get events --sort-by=.lastTimestamp— recent cluster events
ReferenceWhat it is1 section · depth on demand
How it works
The scheduler first filters nodes that fit (resources, taints, required affinity) and then scores the rest (preferred affinity, spread). NoExecute taints also evict running Pods that do not tolerate them.
ReferenceImportant terms & boundaries3 sections · depth on demand
Examples
kubectl taint nodes gpu1 gpu=true:NoSchedule
tolerations: [{ key: gpu, operator: Equal, value: "true", effect: NoSchedule }]
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm: { labelSelector: { matchLabels: { app: web } }, topologyKey: kubernetes.io/hostname }
Documented example, not captured output. Tolerations allow scheduling on tainted nodes but do not attract Pods; combine with node affinity. Use topologySpreadConstraints to spread replicas across zones.
In depth
Taints and affinity solve opposite problems: a taint keeps Pods away from a node unless they tolerate it; affinity draws Pods towards nodes (or towards/away from other Pods). Dedicated nodes need both.
Taint effects
| Effect | New Pods | Running Pods |
|---|---|---|
NoSchedule | Not scheduled without a toleration | Stay |
PreferNoSchedule | Avoided if possible | Stay |
NoExecute | Not scheduled | Evicted (after tolerationSeconds if set) |
Dedicated GPU nodes — the full pattern
kubectl label nodes gpu1 gpu2 hardware=gpu
kubectl taint nodes gpu1 gpu2 dedicated=gpu:NoSchedule
tolerations:
- { key: dedicated, operator: Equal, value: gpu, effect: NoSchedule }
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions: [{ key: hardware, operator: In, values: [gpu] }]
The taint keeps other workloads off the GPU nodes; the affinity keeps GPU workloads off ordinary nodes.
Spreading replicas
topologySpreadConstraints with topologyKey: topology.kubernetes.io/zone and maxSkew: 1 spreads Pods evenly across zones; whenUnsatisfiable: DoNotSchedule is strict, ScheduleAnyway is a preference. Required pod anti-affinity on kubernetes.io/hostname allows at most one replica per node — more replicas than nodes leaves the rest Pending.
Reading the scheduler's answer
0/6 nodes are available: 2 node(s) had untolerated taint {dedicated: gpu}, 4 node(s) didn't match Pod's node affinity/selector. — every node is accounted for by one reason.
Common mistakes
- Overly strict affinity leaving pods Pending.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.