Sub topic 12
Node-pressure eviction
This chapter assumes you know how requests, limits, and QoS classes work, and that the kubelet is the agent that runs Pods on each node. Node-pressure eviction is the kubelet's way of protecting a node that is running out of resources.
What node-pressure eviction is
The kubelet watches resources such as available memory, node filesystem space, image filesystem space, and process IDs. When one drops below a configured threshold, the kubelet marks the node with a pressure condition and terminates Pods to reclaim the resource. The terminated Pods are marked Failed. If a controller such as a Deployment owns them, it creates replacements, and the scheduler places those on a node that has room.
This differs from the Linux OOM killer. The kernel acts only after memory is already exhausted, and it kills a single process. The kubelet acts earlier and ends the whole Pod in an orderly way.
Eviction is also different from preemption. The scheduler preempts Pods to make room for a new Pod. The kubelet evicts Pods because the node itself is short of a resource.
Signals and thresholds
Each resource is tracked by an eviction signal. Common signals are:
| Signal | Meaning |
|---|---|
| `memory.available` | Memory the node can still hand out |
| `nodefs.available` | Free space on the node's main filesystem |
| `imagefs.available` | Free space on the image filesystem |
| `pid.available` | Free process IDs |
A threshold compares a signal to a value, for example memory.available<100Mi. There are two kinds:
- A soft threshold must stay exceeded for a grace period (
evictionSoftGracePeriod). The kubelet then stops the Pod gracefully, using the smaller of the Pod's own grace period andevictionMaxPodGracePeriod. - A hard threshold acts immediately. The Pod is killed with no grace period.
You set them in the kubelet configuration:
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
evictionHard:
memory.available: "100Mi"
nodefs.available: "10%"
evictionSoft:
memory.available: "300Mi"
evictionSoftGracePeriod:
memory.available: "1m30s"
evictionMaxPodGracePeriod: 30What happens during pressure
While a pressure condition is set, the node gets a taint (such as node.kubernetes.io/memory-pressure) so the scheduler avoids placing new Pods there. For disk pressure, the kubelet first tries to reclaim space by deleting unused images and dead containers. It evicts Pods only if that is not enough.
The kubelet evicts one Pod at a time and rechecks the signal after each eviction. Which Pod goes first depends on its resource usage relative to its requests, its priority, and its QoS class. The next chapter covers this ordering.
Observing eviction
Check the node's conditions:
kubectl describe node my-node | grep -A8 ConditionsAn evicted Pod stays in the API with a status you can read:
kubectl get pods --field-selector=status.phase=Failed
kubectl describe pod my-pod | grep -iE 'status|reason|message'The reason is Evicted, and the message names the resource, for example "The node was low on resource: memory."
Common mistakes
- Setting only hard thresholds. Pods then get no graceful shutdown. Add a soft threshold for a smoother response.
- Ignoring
system-reservedandkube-reserved. Without them, system daemons compete with Pods and the node can reach real memory exhaustion before the kubelet reacts. - Assuming the kubelet always wins the race. If memory grows faster than the kubelet checks, the kernel OOM killer acts first.
Exercise
A node has evictionHard: memory.available: "100Mi" and evictionSoft: memory.available: "300Mi" with a soft grace period of 90 seconds. Available memory falls to 250Mi and stays there. What does the kubelet do, and when?
Show answer
Available memory is below the soft threshold but above the hard threshold. Nothing is evicted at first. If it stays below 300Mi for the full 90 seconds, the kubelet begins evicting Pods gracefully. If memory falls under 100Mi before then, the hard threshold applies and a Pod is killed immediately with no grace period.