我将kubernetes集群版本1.12部署到带有kops的aws上
集群中有几个带有标签'example.com/myLabel'的节点,其值分别为a,b,c,d
例如:
Node name example.com/myLabel instance1 a instance2 b instance3 c instance4 d
并且有一个测试部署
apiVersion: apps/v1 kind: Deployment metadata: name: test-scheduler spec: replicas: 6 selector: matchLabels: app: test-scheduler template: metadata: labels: app: test-scheduler spec: tolerations: - key: spot operator: Exists 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 - preference: matchExpressions: - key: example.com/myLabel operator: In values: - c weight: 30 - preference: matchExpressions: - key: example.com/myLabel operator: In values: - d weight: 25 containers: - name: a resources: requests: cpu: "100m" memory: "50Mi" limits: cpu: "100m" memory: "50Mi" image: busybox command: - 'sleep' - '99999'
根据文档,可用于计划的pod的每个节点必须存在nodeAffinity,并选择权重总和最大的节点。
我希望所有吊舱都被调度到带有标签“ a”的节点instance1上,但是在我的情况下,这些节点是随机选择的。
例如,这是为部署中的6个pod计划的5个节点,包括another1和another2节点,这些节点根本不包含我的标签(还有另一个带有该标签的值为'd'的节点):< / p>
NODE LABEL another1 NONE node1 a node2 b node3 c another2 NONE
所有节点都具有容量,它们可用并且可以运行pod
我有2个问题
为什么会这样?
k8s调度程序在哪里记录有关如何为Pod分配节点的信息?事件不包含此信息,并且主服务器上的调度程序日志为空
更新:
我的节点包含正确的标签
example.com/myLabel=a
example.com/myLabel=b
example.com/myLabel=c
example.com/myLabel=d
答案 0 :(得分:1)
如果您在节点上放置一个标签,而标签仅具有它不起作用的值,则必须在标签上带有标签key=value
的每个节点上放置标签,例如来自我在GCP上的一个集群我通过在一个节点上执行kubectl describe
来解决这个问题:
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/fluentd-ds-ready=true
beta.kubernetes.io/instance-type=n1-standard-2
beta.kubernetes.io/os=linux
您必须按照以下说明正确放置标签:
example.com/myLabel=a
这样,您的节点就被正确分类了
答案 1 :(得分:1)
preferredDuringSchedulingIgnoredDuringExecution只是意味着调度程序会将您设置的权重添加到用于选择要调度到哪个节点的算法中。这不是硬性规则,而是首选规则。
随着您设置的权重,您将获得某种程度的均匀分布。在开始看到您要寻找的点差之前,您需要有非常大的样本量。
请记住,“权重”不仅取决于您设置的亲和力,节点的其他因素也具有自己的权重。如果您想更清楚地看到效果,请在每个亲和力之间使用更大的权重差