Taint Effects

Difficulty: Advanced

Question

What are the three taint effects in Kubernetes, and how does NoExecute behave differently from the other two?

Answer

The three taint effects are NoSchedule, PreferNoSchedule and NoExecute. NoSchedule blocks new Pods that do not tolerate the taint, PreferNoSchedule is a soft version that the scheduler tries to honour but may ignore, and NoExecute both blocks new Pods and evicts Pods already running on the node unless they tolerate it. Only NoExecute affects running Pods.

The three effects compared

EffectNew Pods without tolerationRunning Pods without tolerationTypical use
NoScheduleNot scheduledLeft aloneDedicated nodes, control plane nodes, cordoned nodes
PreferNoScheduleAvoided if other nodes fitLeft aloneSoft steering, e.g. keep batch work off a node pool when possible
NoExecuteNot scheduledEvictedNode failures, urgent node draining by automation

Taints and effects are enforced by different components. The scheduler handles NoSchedule and PreferNoSchedule at placement time. NoExecute is enforced continuously by the taint eviction logic in the controller manager.

NoExecute and tolerationSeconds

A toleration for a NoExecute taint can include tolerationSeconds. The Pod is allowed to stay bound for that long after the taint appears, then it is evicted. Without tolerationSeconds, a matching toleration means it stays forever; with no toleration, it is evicted immediately.

This is how Kubernetes handles node failures:

  1. The node stops sending heartbeats.
  2. The node lifecycle controller adds node.kubernetes.io/unreachable:NoExecute (or not-ready).
  3. Every Pod has a default toleration of tolerationSeconds: 300 for these two taints, added by the DefaultTolerationSeconds admission plugin.
  4. After five minutes, Pods are evicted and their controllers recreate them elsewhere.

For a latency-sensitive service like a payment gateway, five minutes is long. You can set your own toleration with tolerationSeconds: 30 so replacements start sooner. For a stateful Pod that is expensive to move, you might increase it instead.

Built-in taints worth knowing

  • node-role.kubernetes.io/control-plane:NoSchedule on control plane nodes.
  • node.kubernetes.io/unschedulable:NoSchedule, added when you kubectl cordon a node.
  • node.kubernetes.io/memory-pressure, disk-pressure and pid-pressure with NoSchedule, added when the kubelet reports resource pressure.
  • node.kubernetes.io/not-ready and unreachable with NoExecute, as above.

DaemonSet Pods automatically tolerate most of these, which is why log agents keep running on cordoned or pressured nodes.

Gotchas

  • Adding a NoExecute taint to a busy node is effectively an instant drain that ignores PodDisruptionBudgets. Prefer kubectl drain for planned maintenance.
  • A toleration with operator: Exists and no key tolerates every taint. Use it only for system agents.
  • A taint is identified by key and effect, so gpu=true:NoSchedule and gpu=true:NoExecute are two separate taints on the same node.
Node failure and NoExecute eviction. Default tolerations give Pods five minutes on an unreachable node before eviction.
  1. Node stops heartbeating: The kubelet can no longer reach the API server.
  2. Controller adds unreachable taint: node.kubernetes.io/unreachable with effect NoExecute.
  3. Default toleration starts timer: tolerationSeconds is 300 unless the Pod overrides it.
  4. Timer expires, Pod evicted: The Pod is marked for deletion.
  5. Controller recreates Pod: The ReplicaSet schedules a replacement on a healthy node.

Code examples

Applying each taint effect

# Hard block for new Pods
kubectl taint nodes node-a dedicated=search:NoSchedule

# Soft preference
kubectl taint nodes node-b batch=avoid:PreferNoSchedule

# Block new Pods AND evict running ones without a toleration
kubectl taint nodes node-c maintenance=true:NoExecute

# See taints on all nodes
kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints

The effect after the colon decides whether the taint only affects scheduling or also evicts running Pods.

Faster failover with a shorter tolerationSeconds

spec:
  tolerations:
    - key: node.kubernetes.io/unreachable
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 30   # default would be 300
    - key: node.kubernetes.io/not-ready
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 30

Overriding the default tolerations lets a critical service be rescheduled about 30 seconds after its node fails instead of five minutes.

Key points

  • NoSchedule = hard block for new Pods; PreferNoSchedule = soft; NoExecute = block and evict.
  • Only NoExecute affects Pods that are already running.
  • tolerationSeconds lets a Pod stay a limited time after a NoExecute taint appears.
  • Default tolerations for not-ready and unreachable are 300 seconds.
  • cordon adds node.kubernetes.io/unschedulable:NoSchedule.

Common follow-up questions

  • How does Kubernetes react when a node becomes unreachable?
  • Why would you use drain instead of a NoExecute taint for maintenance?
  • How do DaemonSets get scheduled onto tainted nodes?
  • What is the difference between taints and node affinity?

Interview tips

  • Name all three, then spend most of your answer on NoExecute and tolerationSeconds.
  • Link it to node failure handling and the five minute default; it shows you know how the system behaves.
  • Mention that NoExecute evictions bypass PodDisruptionBudgets.

Concepts covered

NoSchedule, PreferNoSchedule, NoExecute, tolerationSeconds, Taint-based Eviction

More Kubernetes & Orchestration questions