Intermediate LevelDocker & Deployment
What is a PodDisruptionBudget (PDB) and how does it protect availability during node drains?
❓ Interview Prompt: Explain PodDisruptionBudget minAvailable/maxUnavailable settings and how they prevent excessive pod eviction during node maintenance.
A PodDisruptionBudget (PDB) limits how many pods of a Deployment/StatefulSet can be voluntarily disrupted simultaneously — protecting application availability during planned maintenance (node drains, rolling updates, cluster upgrades).
Voluntary vs Involuntary Disruptions:
•
Voluntary:
kubectl drain (node maintenance), rolling updates, Karpenter node consolidation.•
Involuntary: Hardware failures, kernel panics (PDBs do NOT protect against these).
PDB Parameters (mutually exclusive — use one):
•
`minAvailable`: Minimum number (or %) of pods that must remain healthy during disruption. If draining a node would violate this, the drain is blocked.
•
`maxUnavailable`: Maximum number (or %) of pods that can be simultaneously disrupted.
How It Works During Node Drain:
1
kubectl drain node-1 attempts to evict all pods on node-1.2
For each pod, Kubernetes checks if eviction would violate any PDB.
3
If the eviction would violate the PDB: drain blocks and waits.
4
Once other pods become available (scheduled on other nodes), drain proceeds.
Best Practice:
Set minAvailable to at least 1 less than total replicas (or 50%) to allow rolling node maintenance without downtime.
Code Implementation Example
yaml
# PDB: at least 2 API pods must be available during disruptions
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: api-pdb
spec:
# Use minAvailable OR maxUnavailable (not both)
minAvailable: 2 # always keep at least 2 pods running
# maxUnavailable: 1 # OR: allow at most 1 pod to be disrupted
selector:
matchLabels:
app: api # applies to pods with this label
# --- What this means in practice ---
# If api Deployment has 3 replicas:
# - During node drain: eviction is blocked if only 2 pods remain
# - Only 1 pod can be evicted at a time (3 - 2 = 1)
# Verify PDB status
# kubectl get pdb api-pdb
# NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE
# api-pdb 2 N/A 1 5d💡PDB ensures at least 2 of 3 API pods remain available — node drain blocks if eviction would violate this budget.
🎯 Interview Key Takeaway
PDBs protect against voluntary disruptions (drains, cluster upgrades). Set minAvailable=total-1 to allow rolling maintenance while maintaining availability.
#Kubernetes#PodDisruptionBudget#Node Drain#Availability#Maintenance#Intermediate
Back to all Docker & Deployment Questions→