[英]Kubernetes topologySpreadConstraints doesn't distribute 3 pod evenly to 3 zone ( a b c), but places 1 to a, and 2 to b)
I'm trying to spread my pods to different availability zones.我正在尝试将 Pod 分布到不同的可用性区域。 I used
topologySpreadConstraints
feature with 3 replicas and such config:我将
topologySpreadConstraints
功能与 3 个副本和这样的配置一起使用:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
release: {{ .Release.Name }}
Worker nodes are available in 3 zones.工作节点在 3 个区域中可用。 The problem is when I deploy it, scheduler palces one pod to
A-zone
, and 2 pods in B-zone
.问题是当我部署它时,调度程序将一个 pod 放置在
A-zone
中,将 2 个 pod 放置在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.我知道
maxSkew: 1
不能设置为0
,它允许调度程序以 +1 偏度不均匀地调度。 But shouldn't the scheduler respect domain first?但是调度程序不应该首先尊重域吗? Like shouldn't it do best effort to spread 3 pods by different zones (domains) first?
就像它不应该尽最大努力首先通过不同的区域(域)传播 3 个 pod 吗? Can it be done with help of
topologySpreadConstraints
?可以在
topologySpreadConstraints
的帮助下完成吗? Or I should use podAntiAffinity
?或者我应该使用
podAntiAffinity
?
Like you mentioned, maxSkew
can't be set to 0. My guess is that it's done to handle odd number of pods.就像你提到的,
maxSkew
不能设置为 0。我的猜测是它已经完成处理奇数个 pod。 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.在您的情况下:
A
中的一个 pod 和B
中的两个 pod 仍然遵守其中一个的maxSkew
,因此调度程序可以正常工作。 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.如果您知道您的副本数将始终为 3(可能在有状态集上),则可以使用 podAntiAffinity 规则代替
topologySpreadContraints
但这不适用于每个区域超过一个 pod。 If you use a deployment, the simplest solution would be to increase the replica count.如果您使用部署,最简单的解决方案是增加副本数。 Something like 5 would do the trick.
像 5 这样的东西就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.