Compute topology spread skew per zone, then see how minDomains and the default nodeTaintsPolicy leave replacement pods Pending after a zone outage.
Spread constraints are arithmetic, so do the arithmetic first
Topology spread constraints are the standard way to keep replicas of a Kubernetes workload apart: across zones so that one zone outage does not take the service down, and across nodes so that one node drain does not either. They are configured with a few fields, maxSkew, topologyKey, whenUnsatisfiable, labelSelector and optionally minDomains, and most teams copy a working example and leave it there. The behaviour that matters most, what happens to replacement pods when a zone fails, follows from a small formula that is worth computing before the outage rather than during it.
This guide states the rule as the Kubernetes documentation describes it, works through a three-zone example including a zone loss, and shows two configuration details, minDomains and nodeTaintsPolicy, that turn a recoverable outage into Pending pods. A companion Python model reproduces the documented rule so you can try your own replica counts; it is a teaching model of the documented behaviour, not the scheduler's source code.
The rule
For whenUnsatisfiable: DoNotSchedule, the documentation defines skew for a candidate domain as the number of matching pods in that domain, counting the incoming pod, minus the global minimum. The global minimum is the smallest number of matching pods in any eligible domain, or zero if the number of eligible domains is less than minDomains. A domain is a feasible target only if that skew does not exceed maxSkew.
The documentation's own example is three zones holding 2, 2 and 1 matching pods with maxSkew 1. The global minimum is 1. Placing the next pod in either of the first two zones would give 3 minus 1, a skew of 2, so only the third zone is feasible. The companion model's first test reproduces exactly that.
With whenUnsatisfiable: ScheduleAnyway the constraint does not filter. The scheduler still prefers nodes that reduce skew, but it will place the pod somewhere rather than leave it Pending.
# Author: Sandeep Belgavi. Synthetic three-zone spread for a book-search API.
apiVersion: apps/v1
kind: Deployment
metadata:
name: book-search
spec:
replicas: 6
selector:
matchLabels: {app: book-search}
template:
metadata:
labels: {app: book-search}
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels: {app: book-search}
matchLabelKeys: [pod-template-hash]
containers:
- name: api
image: registry.example.com/book-search:1.4.2The labelSelector must match the pod template's own labels; the documentation points out that a pod whose labels do not match its own selector can be scheduled without improving the balance. The matchLabelKeys entry restricts the count to pods from the same ReplicaSet revision, so a rolling update does not count old and new pods together. These manifests were checked against the field definitions in the documentation, not applied to a cluster for this guide.
Healthy cluster, then a zone outage
With six replicas and three zones of ample capacity, the model places two pods in each zone, as you would expect.
Now zone c fails completely and its nodes are removed from the cluster. Zones a and b still hold two pods each, and the two pods from zone c must be recreated. Zone c has no nodes, so it is no longer an eligible domain. The global minimum is now 2, computed over a and b. Placing a replacement in a gives skew 3 minus 2, which is 1 and therefore allowed. The model places one replacement in each zone, ending with three and three and no pods Pending.
That is the outcome most people expect, and it is why maxSkew 1 with DoNotSchedule is a reasonable default. Two neighbouring configurations behave very differently.
minDomains can hold replicas back on purpose
Suppose the same constraint sets minDomains: 3. After zone c disappears there are only two eligible domains, fewer than minDomains, so the documented rule treats the global minimum as zero. Placing a replacement in zone a would give skew 3 minus 0, which is 3, far above maxSkew 1. Both replacements stay Pending.
That is intended. The documentation describes minDomains as a way to require a minimum number of eligible domains, typically so that a cluster autoscaler adds nodes in a new domain rather than letting the existing ones absorb all replicas. It is the right setting when running six replicas in two zones is worse than running four. It is the wrong setting when availability during an outage matters more than spread, and in that case the Pending pods will appear exactly when you need capacity.
Tainted nodes still count by default
A real zone outage rarely deletes Node objects immediately. More often the nodes remain registered, marked NotReady and carrying taints that ordinary pods do not tolerate. Whether those nodes still define an eligible domain depends on nodeTaintsPolicy.
The documentation states that with Ignore, node taints are ignored and all nodes are included, and that a null value behaves like Ignore. With Honor, tainted nodes are included only if the incoming pod tolerates the taint.
Under the default, zone c is still an eligible domain with zero matching pods, assuming its old pods are no longer counted. The global minimum is therefore zero. Placing a replacement in zone a would give skew 3, above maxSkew, and the same in zone b. The replacements cannot go into zone c either, because its nodes are tainted. The model reports both replacements Pending. With nodeTaintsPolicy: Honor, zone c drops out of the calculation and the replacements land in a and b exactly as in the clean-removal case.
This is the configuration detail most worth checking before an outage. The difference between nodes that vanish and nodes that linger as NotReady is invisible in the manifest and decisive in the result. The model's assumption about old pods also deserves attention: pods on unreachable nodes can remain in a terminating state for some time, and how they are counted affects the result.
Capacity is a separate filter
Spread constraints decide which domains are allowed; capacity decides whether the pod fits. In a variant of the outage where zone b has no free capacity, DoNotSchedule places one replacement in zone a, at skew 1, and leaves the second Pending because a fourth pod in zone a would mean skew 2. ScheduleAnyway places both in zone a, ending with four and two. Neither answer is wrong. DoNotSchedule protects the invariant at the cost of availability; ScheduleAnyway protects availability at the cost of spread, and a later rebalance is needed to restore it. Kubernetes does not move running pods to restore spread by itself; that requires a deliberate rollout or a tool such as the descheduler.
Choosing settings
For a stateless service that must stay up during a zone outage, maxSkew 1 with ScheduleAnyway, or DoNotSchedule with nodeTaintsPolicy: Honor and no minDomains, both let replacements land in surviving zones. Pair either with a PodDisruptionBudget so voluntary disruptions do not compound the outage.
For a quorum-based system where losing balance is worse than losing a replica, DoNotSchedule with minDomains equal to the number of zones keeps the spread strict and makes the shortfall visible as Pending pods that an autoscaler or an operator must resolve.
In every case, size zones so that the surviving zones can hold all replicas at the resulting skew. With six replicas and three zones, each zone needs room for three pods during an outage, not two.
Verification before an incident
Run the companion model with your replica count, zone count and capacity, and with both nodeTaintsPolicy values. In a staging cluster, cordon and taint every node in one zone rather than deleting them, delete the workload's pods in that zone, and watch whether replacements schedule. Record the result alongside the manifest, because the configuration that passes this drill is the one to keep.