CKAD field manual
Kubernetes PDB YAML example
A PDB limits voluntary eviction. Set minAvailable or maxUnavailable, and a selector on the Pod labels. drain respects it.
kubectl create pdb web-pdb --selector=app=web --min-available=2
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: web
unhealthyPodEvictionPolicy: IfHealthyBudget
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web-pdb
spec:
maxUnavailable: 1
selector:
matchLabels:
app: web
kubectl get pdb
kubectl describe pdb web-pdb
Fields
- minAvailable
- Pods that must stay Ready. An integer, or a percent string such as "50%". A percent rounds up.
- maxUnavailable
- Pods that may be unavailable. It still fits when the replica count changes. A percent rounds up, so more Pods can be down than the percentage you wrote. This or minAvailable, not both. Every selected Pod must share one controller.
- selector
- Required. Match the Pod template labels. An empty selector matches every Pod in the namespace.
- matchLabels
- The Pod labels, not the Deployment metadata. A miss leaves ALLOWED DISRUPTIONS at 0.
- unhealthyPodEvictionPolicy
- IfHealthyBudget is the default. A Running Pod that is not Ready can leave only while currentHealthy is still at least desiredHealthy. AlwaysAllow evicts it even when the budget is already broken.
- kubectl create pdb
- Short name of poddisruptionbudget. --min-available or --max-unavailable, plus --selector. Add -n when the task names a namespace.
- kubectl get
- ALLOWED DISRUPTIONS is status.disruptionsAllowed. 0 means drain waits.
- kubectl describe
- Shows the selector, the budget, and currentHealthy against desiredHealthy.
Watch
- Set minAvailable or maxUnavailable, never both. The API rejects the object. maxUnavailable still fits when the replica count changes, and only when every selected Pod belongs to the same controller. A bare Pod uses an integer minAvailable. minAvailable: 2 on a Deployment of 2 leaves disruptionsAllowed at 0.
- selector must match the Pod template labels. An empty selector matches every Pod in the namespace. A selector that matches nothing reports ALLOWED DISRUPTIONS 0.
- kubectl drain uses the Eviction API and waits while disruptionsAllowed is 0. kubectl delete pod does not check the PDB. A rolling update is not limited by it, and a node crash is not blocked by it. Raise replicas so one Pod can leave. Do not delete the PDB to finish the drain.
- Healthy means Ready=True. IfHealthyBudget, the default, will not evict a Running Pod that is not Ready while the budget is already broken, so a CrashLoop can stall drain. AlwaysAllow evicts those Pods. Pending, Succeeded, and Failed Pods can always be evicted.
Official docs Specifying a Disruption Budget Disruptions