Sub topic 15
Evicting unhealthy pods with unhealthyPodEvictionPolicy
This chapter assumes you can read a PodDisruptionBudget (PDB), know what kubectl drain does, and understand that the Eviction API checks the budget before it removes a pod.
The problem: a budget that protects broken pods
A PDB counts only healthy pods toward currentHealthy. Suppose a Deployment has 3 replicas and minAvailable: 2. One pod is stuck in CrashLoopBackOff, so currentHealthy is 2. The budget allows 0 disruptions. A drain that needs to evict the broken pod is now blocked, even though evicting it would not reduce availability. The pod is already unavailable.
By default, Kubernetes behaves this way for pods that are Running but not Ready. Such pods can be evicted only if the budget still holds without them. This can leave a node stuck in a drain until someone deletes the broken pod by hand.
The unhealthyPodEvictionPolicy field
The spec.unhealthyPodEvictionPolicy field of a PDB controls what happens to unhealthy pods. It has two values.
| Value | Behavior |
|---|---|
| `IfHealthyBudget` (default) | A Running pod that is not Ready can be evicted only if the budget is satisfied (`currentHealthy` is at least `desiredHealthy`). |
| `AlwaysAllow` | A Running pod that is not Ready can always be evicted, whatever the budget says. |
Pods that are not Running (for example, Pending or Failed) can always be evicted under either policy. The policy matters only for pods in the Running phase that fail their readiness check.
Example
This budget keeps at least 2 web pods available and lets the Eviction API remove broken ones.
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web-pdb
spec:
minAvailable: 2
unhealthyPodEvictionPolicy: AlwaysAllow
selector:
matchLabels:
app: webApply it and check the status:
kubectl apply -f web-pdb.yaml
kubectl get pdb web-pdb -o jsonpath='{.spec.unhealthyPodEvictionPolicy}{"\n"}'
kubectl get pdb web-pdbHealthy pods are still protected. Only the pods that are already failing readiness lose protection.
When to use AlwaysAllow
Choose AlwaysAllow for most stateless workloads. It lets drains and cluster upgrades continue past crash-looping pods, and it is the setting the Kubernetes documentation recommends for that case.
Be careful with applications where a not-Ready pod may still hold data or take part in a quorum. A database replica that is catching up can fail readiness while it syncs. Evicting it can lose work or break quorum. Keep IfHealthyBudget for those workloads.
Exercise
A Deployment has 4 replicas and a PDB with minAvailable: 3. One pod is Running but not Ready. You drain the node holding that pod. What happens under IfHealthyBudget, and what happens under AlwaysAllow?
Show answer
Only 3 pods are healthy, so currentHealthy (3) equals desiredHealthy (3). Under IfHealthyBudget, the budget is satisfied, so the unhealthy pod can be evicted. The drain proceeds. The result changes if a second pod is also unhealthy. Then currentHealthy is 2, below 3, and eviction of an unhealthy pod is blocked under IfHealthyBudget but allowed under AlwaysAllow.