Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Taints, Tolerations and Affinity

Direct answer

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.

When to use this

Use it to control placement, or when pods are Pending because no node matches.

First 30 seconds

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.

Operational verification

pod rules + node taints/labels → scheduler filters → placement

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it to control placement, or when pods are Pending because no node matches.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

Pending with "node(s) had untolerated taint" or "didn't match node affinity" in events. Prefer soft (preferred) rules unless placement is mandatory.

Key checks
  • kubectl describe node | grep Taints — first check for this topic
  • kubectl get pods -o wide — pods, status, node, IP
  • kubectl describe pod <pod> — events and conditions
  • kubectl 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

EffectNew PodsRunning Pods
NoScheduleNot scheduled without a tolerationStay
PreferNoScheduleAvoided if possibleStay
NoExecuteNot scheduledEvicted (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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Terminology layer

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.

Aliases that resolve here
taints, tolerations and affinitytaints tolerationspod affinity anti-affinity
Confirmation

Confirm action

Continue?