# Disruptions and PodDisruptionBudgets — Kubernetes

Source: https://www.skillbyai.com/en/kubernetes/h-pdb

> Planned maintenance without outages.

## Limit voluntary disruptions

Nodes are drained for upgrades, scaling down and maintenance (**voluntary disruptions**). A **PodDisruptionBudget (PDB)** limits how many pods of an app may be taken down at once (`minAvailable` or `maxUnavailable`), so drains wait rather than removing too many replicas. Combine with multiple replicas, **topology spread constraints** or anti-affinity across nodes and zones, and graceful shutdown (handle SIGTERM, a preStop hook, a sensible terminationGracePeriodSeconds).

## A PDB and zone spreading

Not applied to a live cluster in this course; check field names against the API reference for your version.

```yaml
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: {name: web}
spec:
  maxUnavailable: 1
  selector: {matchLabels: {app: web}}
---
# in the Deployment pod template
topologySpreadConstraints:
- maxSkew: 1
  topologyKey: topology.kubernetes.io/zone
  whenUnsatisfiable: ScheduleAnyway
  labelSelector: {matchLabels: {app: web}}
```

## Handle SIGTERM

Stop accepting new requests, finish in-flight work and exit within the grace period; otherwise every rollout drops requests.

**Quiz:** What does a PodDisruptionBudget protect against?

- [ ] High CPU usage
- [ ] Node hardware failures
- [ ] Bad code
- [x] Too many pods of an app being evicted at once during voluntary disruptions

*Answer:* Too many pods of an app being evicted at once during voluntary disruptions. It paces drains and evictions.
