Sub topic 7
Node-pressure eviction and eviction order
This chapter assumes you know pods, namespaces, and how to apply YAML with kubectl. It also assumes you have read the earlier chapters on requests, limits, OOM kills, and QoS classes.
What node-pressure eviction is
A container that exceeds its own memory limit is killed by the kernel. Node-pressure eviction is a different event. The kubelet, the agent that runs on each node, watches the node's free memory, disk space, and process IDs. When one of these drops below a threshold, the kubelet evicts pods to reclaim the resource.
Eviction ends the pod's containers and sets the pod phase to Failed with reason Evicted. A pod managed by a Deployment or ReplicaSet is then replaced by a new pod, which the scheduler may place on another node. A bare pod with no controller is not replaced.
Signals and thresholds
The kubelet compares observed values against eviction signals.
| Signal | Meaning |
|---|---|
| `memory.available` | Free memory on the node |
| `nodefs.available` | Free space on the node's main filesystem |
| `imagefs.available` | Free space on the image filesystem |
| `pid.available` | Free process IDs |
A hard threshold, such as memory.available<100Mi, triggers immediate eviction with no grace period. A soft threshold must stay exceeded for a configured grace period before eviction begins. Your cluster administrator or cloud provider sets these values in the kubelet configuration.
Eviction order
When memory is short, the kubelet ranks candidate pods and evicts the first one. It tries to pick pods that use more than they requested. The ranking uses three steps:
- Pods whose memory usage exceeds their memory request come before pods whose usage is at or below it.
- Among those, pods with lower priority (
priorityClassName) are evicted first. - Among pods still tied, the pod with the largest usage above its request goes first.
QoS class affects this order only indirectly. BestEffort pods have no request, so any usage exceeds it. Burstable pods are evicted if they exceed their request. A Guaranteed pod's usage cannot exceed its request, because its request equals its limit. Guaranteed pods are therefore evicted last, unless system daemons themselves need the memory.
Seeing an eviction
Evicted pods stay in the list until deleted. Check the status and events:
kubectl get pods --field-selector=status.phase=Failed
kubectl describe pod web
kubectl describe node worker-1 | grep -A2 -i pressureThe pod's describe output shows a message such as The node was low on resource: memory. Container app was using 900Mi, request is 128Mi. The node's conditions include MemoryPressure, DiskPressure, and PIDPressure. While a pressure condition is true, the node carries a taint, and the scheduler avoids it for new pods.
OOM kill versus eviction
| Row | OOM kill | Node-pressure eviction |
|---|---|---|
| Trigger | Container exceeds its own memory limit, or the node runs out before the kubelet acts | Node crosses an eviction threshold |
| Decided by | Linux kernel | kubelet |
| Visible as | `OOMKilled`, exit code 137 | Pod phase `Failed`, reason `Evicted` |
| Pod object | Stays, container restarts | Pod ends and a controller replaces it |
The kubelet polls on an interval. If memory fills faster than it checks, the kernel OOM killer acts first. In that case the kernel picks victims using each container's oom_score_adj, a value derived from QoS class, so BestEffort containers are killed first and Guaranteed last.
Avoiding evictions
- Set memory requests close to real usage so that your pods are not "over request" under pressure.
- Use the Guaranteed class, or a high priority class, for pods that must survive.
- Do not rely on CPU settings here. CPU pressure causes throttling, not eviction.
Exercise
A node reports MemoryPressure. Pod A (Burstable) requests 256Mi and uses 200Mi. Pod B (Burstable) requests 128Mi and uses 600Mi. Both have the same priority. Which pod does the kubelet evict first, and why?
Show answer
Pod B. Its usage (600Mi) exceeds its request (128Mi), while Pod A's usage (200Mi) is below its request (256Mi). Pods over their request rank first, and priority is equal, so the pod with the larger overage goes first.
Exercise
Why is a Guaranteed pod rarely evicted for memory, even though QoS class is not the first sort key?
Show answer
Its memory request equals its limit, so its usage cannot exceed its request. The first ranking step puts only pods over their request at the front, so a Guaranteed pod ranks last.