πΊοΈ Spread Pods Across Zones, Nodes, Racks
All pods on same node? Node failure = downtime. Topology spread constraints spread pods evenly across zones, nodes, or custom domains.
π Pod Topology Spread
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 6
template:
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: myapp
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: myapp
containers:
- name: app
image: myapp:latest
π― Understanding Parameters
maxSkew: The maximum difference in pod count between any two domains topologyKey: Node label to define domains (hostname, zone, region) whenUnsatisfiable: - DoNotSchedule: Don't schedule if constraint can't be met - ScheduleAnyway: Schedule but try to minimize skew labelSelector: Which pods to consider for spread
β Example: 3 Zones, 6 Replicas
- Zone A: 2 pods
- Zone B: 2 pods
- Zone C: 2 pods
- Within each zone: spread across nodes
- maxSkew: 1 ensures no zone has +1 pod more than others
“All 6 replicas landed on same AZ. AZ failure = total outage. Added topology spread. Now 2 per AZ. Lost an AZ β still have 4 replicas. Zero-downtime design saved us.”
