Sub topic 13
Which Pods the kubelet evicts first
This chapter assumes you know requests, limits, and the three QoS classes. It also assumes you know what PriorityClass does during scheduling. Here you will see how the kubelet chooses victims when a node runs short of memory, disk, or PIDs.
What triggers eviction
The kubelet watches signals such as memory.available, nodefs.available, and pid.available. When a signal crosses an eviction threshold, the node is under pressure and the kubelet starts ending Pods to reclaim the resource.
- A soft threshold must hold for a grace period. The kubelet then stops Pods with a bounded grace time, set by
eviction-max-pod-grace-period. - A hard threshold acts immediately. The kubelet kills Pods with no grace period.
An evicted Pod is not rescheduled in place. Its phase becomes Failed with reason Evicted. A controller such as a Deployment creates a replacement, and the scheduler places it.
The ranking rules
When the kubelet must reclaim a resource, it ranks the candidate Pods and evicts them in this order:
- Pods whose usage of the starved resource exceeds their requests come before Pods that stay within their requests.
- Among those, Pods with lower priority come first.
- Among Pods with equal priority, the Pod using the most of the resource above its request comes first.
The rules never name QoS classes, but the classes produce the same effect. A BestEffort Pod has no request, so any usage exceeds it, and it lands in the first group. A Burstable Pod lands there only if it uses more than it requested. A Guaranteed Pod has requests equal to limits, so it can't exceed its request. It is evicted only when no other Pods can free enough, or when system daemons use more than their reserved share.
A worked example
A node is low on memory and runs three Pods:
| Pod | Priority | Memory request | Memory usage |
|---|---|---|---|
| `batch` | 0 | none | 900Mi |
| `web` | 1000000 | 256Mi | 600Mi |
| `db` | 1000000 | 2Gi | 1.5Gi |
batch and web both exceed their requests, so they form group 1. batch has the lower priority and goes first. If that isn't enough, web is next. db stays within its request, so it is evicted last.
Note that priority matters only inside a group. web has high priority, but it is still evicted before db because it overshoots its request.
Related behavior to remember
- Eviction ignores PodDisruptionBudgets. Hard evictions also ignore
terminationGracePeriodSeconds. - The memory signal can lag. If memory runs out before the kubelet reacts, the Linux OOM killer acts, and
oom_score_adjfrom the QoS class decides the victim. - Critical static Pods are not evicted this way.
Check it yourself
kubectl get pods -A --field-selector=status.phase=Failed
kubectl describe pod <pod-name> | grep -iE 'status|reason|message'
kubectl describe node <node-name> | grep -i -A5 'conditions'The Pod message names the starved resource, for example "The node was low on resource: memory."
Exercise
A node is short on memory. Pod A has priority 100 and uses 700Mi against a 500Mi request. Pod B has priority 0 and uses 200Mi against a 500Mi request. Which does the kubelet evict first, and why?
Show answer
Pod A. It exceeds its memory request, so it is in the first group. Pod B stays within its request and is evicted later, even though its priority is lower. Priority only breaks ties inside a group.