Pod Eviction

Difficulty: Intermediate

Question

What causes a Pod to be evicted from a node in Kubernetes, and how does the kubelet decide which Pods to evict first?

Answer

A Pod is evicted when Kubernetes deliberately terminates it to protect the node or to move work elsewhere. The main causes are node-pressure eviction by the kubelet (the node is running low on memory, disk, inodes or PIDs), API-initiated eviction such as kubectl drain during maintenance, taint-based eviction when a node becomes unreachable, and scheduler preemption in favour of a higher-priority Pod. Evicted Pods end in phase Failed with reason Evicted, and their controller creates replacements on other nodes.

Node-pressure eviction by the kubelet

The kubelet monitors eviction signals and compares them to thresholds:

SignalDefault hard threshold (Linux)
memory.availableless than 100Mi
nodefs.availableless than 10%
nodefs.inodesFreeless than 5%
imagefs.availableless than 15%

pid.available can also be configured. Hard thresholds evict immediately; soft thresholds (--eviction-soft plus a grace period) give Pods time to recover. When a threshold is crossed, the node reports a condition such as MemoryPressure or DiskPressure, gets a matching taint, and the scheduler stops placing new Pods there.

How the kubelet ranks Pods for eviction

For memory pressure the kubelet considers, in order:

  1. Whether the Pod's usage exceeds its requests.
  2. Pod priority (priorityClassName).
  3. Usage relative to requests.

In practice this lines up with QoS classes: BestEffort Pods (no requests or limits) go first, then Burstable Pods using more than they requested, and Guaranteed Pods (requests equal limits for every container) are the last to go. Disk pressure follows similar logic using ephemeral storage. A container exceeding its own ephemeral-storage limit gets its Pod evicted directly.

Other causes of eviction

  • API-initiated eviction: kubectl drain and cluster upgrades call the Eviction API, which honours PodDisruptionBudgets. If a PDB would be violated, the eviction is refused and drain waits.
  • Taint-based eviction: when a node goes NotReady or unreachable, the control plane taints it with node.kubernetes.io/not-ready or node.kubernetes.io/unreachable with effect NoExecute. Pods get a default toleration of 300 seconds, after which they are evicted.
  • Preemption: if a high-priority Pod cannot be scheduled, the scheduler may evict lower-priority Pods to make room.
  • Descheduler: an optional add-on that evicts Pods to rebalance a cluster.

Eviction vs OOMKilled

These are often confused. An OOMKilled container hit its own memory limit and was killed by the kernel; the kubelet restarts it in the same Pod and you see RESTARTS go up. An eviction removes the entire Pod from the node because the node itself is under pressure. The fix differs: raise the container limit for OOMKilled, and set proper requests, add capacity, or clean disk for evictions.

Preventing surprise evictions

  • Set realistic requests for every container; BestEffort Pods are the first victims.
  • Use Guaranteed QoS for critical components like payment or ledger services.
  • Set ephemeral-storage requests and limits, and ship logs off-node instead of writing large files locally.
  • Define PodDisruptionBudgets so maintenance never takes too many replicas at once.
  • Monitor node conditions and kubelet eviction events in your alerting.
How node-pressure eviction unfolds. The kubelet notices a resource running low, marks the node, and evicts the least protected Pods first.
  1. Signal crosses threshold: For example memory.available drops below 100Mi.
  2. Node condition and taint set: MemoryPressure blocks new Pods from scheduling there.
  3. kubelet ranks Pods: Usage above requests, then priority, then usage vs requests.
  4. Lowest-ranked Pods evicted: BestEffort and over-request Burstable Pods go first.
  5. Controllers recreate Pods: Deployments place replacements on healthier nodes.

Code examples

Finding and understanding evictions

# List evicted Pods across the cluster
kubectl get pods -A --field-selector=status.phase=Failed | grep Evicted

# Why was it evicted?
kubectl describe pod report-worker-6d8f7-abcde -n analytics | grep -A3 -i "reason\|message"
# Message: The node was low on resource: memory. Container worker was using 1.9Gi, request is 512Mi

# Which nodes are under pressure right now?
kubectl describe node ip-10-0-3-17 | grep -E "MemoryPressure|DiskPressure|PIDPressure"

# Clean up old evicted Pods in a namespace
kubectl delete pods -n analytics --field-selector=status.phase=Failed

The eviction message tells you which resource ran out and how far the container exceeded its request, which points straight at the fix: higher requests, a memory leak, or more node capacity.

Key points

  • Eviction causes: node pressure, `kubectl drain`/Eviction API, NoExecute taints on unreachable nodes, and preemption.
  • Default hard thresholds include `memory.available<100Mi` and `nodefs.available<10%`.
  • Ranking: usage above requests, then priority, then usage relative to requests.
  • BestEffort is evicted first, Guaranteed last.
  • OOMKilled restarts a container; eviction removes the whole Pod from the node.

Common follow-up questions

  • What are the three QoS classes and how is a Pod's class determined?
  • How does a PodDisruptionBudget interact with `kubectl drain`?
  • What is the difference between soft and hard eviction thresholds?
  • How would you stop a logging-heavy app from causing DiskPressure evictions?

Interview tips

  • Clearly separate eviction from OOMKilled; interviewers often test that distinction.
  • Tie eviction order to QoS classes and requests; it shows you know why setting requests matters.
  • Mention PDBs when discussing drain; it shows operational experience with upgrades.

Concepts covered

Node-pressure Eviction, QoS Classes, Eviction API, PodDisruptionBudget, Taint-based Eviction

More Kubernetes & Orchestration questions