我有一个反关联性规则,要求kubernetes将来自同一部署的Pod调度到different nodes上,我们已经使用了很长时间了。
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: kubernetes.io/hostname
labelSelector:
matchExpressions:
- key: application
operator: In
values:
- {{ $appName }}
- key: proc
operator: In
values:
- {{ $procName }}
我正在尝试将Pod关联性规则更新为强烈的偏好设置,而不是硬性要求,因此,如果部署需要的副本数超过可用节点数,我们就无需扩展集群。
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- topologyKey: kubernetes.io/hostname
weight: 100
labelSelector:
matchExpressions:
- key: application
operator: In
values:
- {{ $appName }}
- key: proc
operator: In
values:
- {{ $procName }}
但是,当我尝试应用新规则时,topologyKey出现意外错误:
Error: Deployment.apps "core--web" is invalid:
[spec.template.spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.topologyKey: Required value: can not be empty,
spec.template.spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.topologyKey: Invalid value: "": name part must be non-empty,
spec.template.spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.topologyKey: Invalid value: "": name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')]
即使我的所有节点都有与正则表达式匹配的指定键的标签,调度程序似乎仍在获取拓扑键的空字符串值:
$ kubectl describe nodes | grep kubernetes.io/hostname
kubernetes.io/hostname=ip-10-x-x-x.ec2.internal
kubernetes.io/hostname=ip-10-x-x-x.ec2.internal
kubernetes.io/hostname=ip-10-x-x-x.ec2.internal
kubernetes.io/hostname=ip-10-x-x-x.ec2.internal
我没想到通过从必需到首选的简单更改就可以看到这样的问题。我搞砸了什么导致topologyKey错误?
答案 0 :(得分:1)
必需和首选语法之间存在细微差别,请注意错误消息路径中对podAffinityTerm
的引用:
spec.template.spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.topologyKey
首选计划的正确语法是:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
topologyKey: kubernetes.io/hostname
labelSelector:
matchExpressions:
- key: application
operator: In
values:
- {{ $appName }}
- key: proc
operator: In
values:
- {{ $procName }}
请注意,weight
是顶级密钥,其同级podAffinityTerm
包含topologyKey
和labelSelector
。