Listen to this Post

Kubernetes Pod Disruption Budget (PDB) ensures high availability during voluntary disruptions like node maintenance or cluster upgrades. Below is a simplified breakdown of how PDB works:
Typical Kubernetes PDB Flow:
- Deployment Creation: A Deployment with 3 replicas and label `app=my-app` is created.
- Admin Action: Admin applies Deployment and PDB YAML.
- API Server: Receives the spec and stores it in
etcd.
4. etcd: Stores Deployment and PDB objects.
- Controller Manager: Validates, stores, and creates a ReplicaSet.
- ReplicaSet: Creates 3 Pods based on the spec.
7. Scheduler: Assigns Pods to nodes.
8. Kubelet:
- Node1 runs Pod-1 and Pod-2.
- Node2 runs Pod-3.
9. PDB Enforcement:
– `minAvailable: 2` monitors Pods with matching labels.
– Admin drains Node1 (simulating disruption).
– Eviction request for Pod-2 is denied (violates availability).
– Eviction of Pod-1 is approved (still meets minAvailable).
📖 Full Blog: Kubernetes PDB Explained
You Should Know:
1. Creating a PDB YAML
apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: my-app-pdb spec: minAvailable: 2 selector: matchLabels: app: my-app
Apply using:
kubectl apply -f pdb.yaml
2. Checking PDB Status
kubectl get pdb kubectl describe pdb my-app-pdb
3. Testing PDB Enforcement
Simulate node drain:
kubectl drain <node-name> --ignore-daemonsets
Check if Pods are evicted while maintaining availability.
4. Common Troubleshooting Commands
- Check Pod Labels:
kubectl get pods --show-labels
- Force Eviction (if stuck):
kubectl delete pod <pod-name> --grace-period=0 --force
- Check Cluster Events:
kubectl get events --sort-by='.metadata.creationTimestamp'
5. Alternative: maxUnavailable
apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: my-app-pdb spec: maxUnavailable: 1 selector: matchLabels: app: my-app
What Undercode Say
PDBs are crucial for production-grade Kubernetes clusters. Misconfigurations can lead to upgrade failures or unexpected downtimes. Always:
– Test PDBs in a staging environment.
– Use `kubectl drain –dry-run` before actual node maintenance.
– Monitor with `kubectl get pdb -w` for real-time updates.
🔧 Pro Tip: Combine PDBs with `podAntiAffinity` to ensure Pods are distributed across nodes for higher resilience.
📚 Further Learning:
Expected Output:
NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE my-app-pdb 2 N/A 1 5m
This ensures your Kubernetes workloads remain available during disruptions. 🚀
References:
Reported By: Sandip Das – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


