🛡️ Don’t Drain All Pods at Once
Node draining, cluster upgrades kill pods. PodDisruptionBudget (PDB) ensures minimum availability during voluntary disruptions.
📝 PDB Examples
# At least 2 pods available at all times
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: app-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: myapp
# No more than 1 pod unavailable
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: app-pdb
spec:
maxUnavailable: 1
selector:
matchLabels:
app: myapp
# For single-replica apps (minimum 1)
spec:
minAvailable: 1
⚙️ Check PDB Status
# List PDBs kubectl get pdb # Describe PDB kubectl describe pdb app-pdb # Output shows: # Allowed disruptions: 2 # Current disruptions: 0 # Desired healthy: 3 # Current healthy: 3 # Simulate disruption (will be blocked if PDB violated) kubectl drain node-1 --ignore-daemonsets
💡 Use Cases
- Databases: Ensure primary replica never disrupted
- API gateways: Keep at least 2 pods running
- Queue workers: Prevent all consumers from stopping
- Leader election: Keep at least 1 pod (leader) online
“Cluster upgrade drained all pods at once → downtime. Added PDB with maxUnavailable: 1. Now upgrades roll smoothly, zero downtime. Kubernetes should enforce PDB by default.”
