Background:
While performance testing an application, I was getting inconsistent results when scaling the replicas for my php-fpm
containers where I realized that 3/4 pods were scheduled on the same node.
I then configured anti affinity rules to not schedule pods on the same node. I quickly realized that using requiredDuringSchedulingIgnoredDuringExecution
was not an option because I could not have # of replicas > # of nodes so I configured preferredDuringSchedulingIgnoredDuringExecution
.
For the most part, it looks like my pods are scheduled evenly across all my nodes however sometimes (seen through a rolling upgrade), I see pods on the same node. I feel like the weight
value which is currently set to 100 is playing a factor.
Here is the yaml I am using (helm):
{{- if .Values.podAntiAffinity }}
{{- if .Values.podAntiAffinity.enabled }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app: "{{ .Values.deploymentName }}"
topologyKey: "kubernetes.io/hostname"
{{- end }}
{{- end }}
Run Code Online (Sandbox Code Playgroud)
Questions:
The way I read the documentation, the weight
number will be added to a calculated score for the node based on how busy it is (simplified) however what I don't understand is how a weight of 1 vs 100 would be any different?
Why are pods sometimes scheduled on the same node with this rule? Is it because the total score for the node that the pod wasn't scheduled on is too low (as it is too busy)?
Is there a way to see a log/event of how the pod was scheduled on a particular node? I'd expect kubectl describe pod
to have those details but seemingly it does not (except in an error scenario).
小智 5
不保证 preferredDuringSchedulingIgnoredDuringExecution。
两种类型的节点关联,称为 requiredDuringSchedulingIgnoredDuringExecution 和 preferredDuringSchedulingIgnoredDuringExecution。您可以将它们分别视为“硬”和“软”,因为前者指定了将 pod 调度到节点上必须满足的规则(就像 nodeSelector 但使用更具表现力的语法),而后者指定调度程序将尝试执行但不会保证的首选项。
您设置的权重具有优势,但还有其他参数(由用户和 kubernetes 设置)具有自己的权重。下面的例子应该给出一个更好的画面,你设置的权重很重要
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: example.com/myLabel
operator: In
values:
- a
weight: 40
- preference:
matchExpressions:
- key: example.com/myLabel
operator: In
values:
- b
weight: 35
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2864 次 |
最近记录: |