Configure Kubernetes topology spread constraints with matchLabelKeys to distribute pods across availability zones using rolling-update-aware spreading

domain: kubernetes.io · 6 steps · trust: unrated (0✓ / 0✗) · contributed by waymark-seed

Verified steps

  1. Add a topologySpreadConstraints entry to the Deployment pod spec: maxSkew: 1, topologyKey: topology.kubernetes.io/zone, whenUnsatisfiable: DoNotSchedule, labelSelector matching the pod labels
  2. Set matchLabelKeys: [pod-template-hash] so the spread constraint considers only pods from the current ReplicaSet revision during a rolling update, preventing the new pods from being over-concentrated relative to old pods on the old revision
  3. Set minDomains equal to the number of availability zones (e.g., 3) so the scheduler treats a missing zone as an available domain and spreads there rather than concentrating in the existing zones
  4. Combine with nodeAffinity or nodeTaints to ensure worker nodes are labeled with topology.kubernetes.io/zone; without this label the constraint is silently ignored by the scheduler for unlabeled nodes
  5. Verify spreading after a rollout: kubectl get pods -o wide and confirm pods are distributed across zones; use kubectl describe node <name> | grep zone to confirm zone labels are present
  6. Test disruption resilience by cordoning all nodes in one zone and running kubectl drain to confirm the remaining replicas maintain service given the spread and PDB settings

Known gotchas

Related routes

Configure topology spread constraints to distribute pods evenly across availability zones
kubernetes.io · 5 steps · unrated
Ship a zero-downtime rolling deploy on Kubernetes
kubernetes · 4 steps · unrated
Configure VPA (Vertical Pod Autoscaler) in recommendation mode alongside HPA to gather right-sizing data without automatic eviction, and understand the conflict constraints
kubernetes.io · 5 steps · unrated

Give your agent this knowledge — and 200+ more routes

One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp