I'm trying to spread my pods to different availability zones. I used topologySpreadConstraints
feature with 3 replicas and such config:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
release: {{ .Release.Name }}
Worker nodes are available in 3 zones. The problem is when I deploy it, scheduler palces one pod to A-zone
, and 2 pods in B-zone
. Instead of placing one into each zone. I understand that maxSkew: 1
, can't be set to 0
, and it allows scheduler to schedule unevenly with +1 skewness. But shouldn't the scheduler respect domain first? Like shouldn't it do best effort to spread 3 pods by different zones (domains) first? Can it be done with help of topologySpreadConstraints
? Or I should use podAntiAffinity
?
Like you mentioned, maxSkew
can't be set to 0. My guess is that it's done to handle odd number of pods. In your case: one pod in A
and two pods in B
still respects the maxSkew
of one so the scheduler is doing its job properly. If you know for a fact that your replica count will always be 3 (maybe on a statefulset), you can use a podAntiAffinity rule instead of your topologySpreadContraints
but this will not work with more than one pod per zone. If you use a deployment, the simplest solution would be to increase the replica count. Something like 5 would do the trick.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.