Scheduling
Anti-affinity and spread
44 / 82

"Three replicas" says nothing about where they run, so tell the scheduler to spread them.

Without a rule all three can land on one node; one node failure then takes the whole service down while kubectl get pods still said 3/3.

No rule: all replicas on one nodenode-a zone-aone failure = outagenode-b zone-bnode-c zone-cPod anti-affinity: not togethernode-a zone-anode-b zone-ano two share a node, but zone-a stillcarries 3 of 3 replicasTopology spread: maxSkew 1zone-azone-bzone-c1 - 1 - 1: zone loss costs one replica2 - 1 - 0 would violate maxSkew 1
topologySpreadConstraints
topologySpreadConstraints:
- maxSkew: 1
  topologyKey: topology.kubernetes.io/zone
  whenUnsatisfiable: DoNotSchedule   # or ScheduleAnyway
  labelSelector: {matchLabels: {app: checkout}}

Prefer spread constraints for balance

Anti-affinity is a pairwise "avoid that Pod" rule and can leave zones lopsided. Spread constraints reason about the whole distribution, which is nearly always the real goal. Use both when you need hard co-location rules and balance.