为什么kubernetes调度程序会忽略nodeAffinity? [英] Why kubernetes scheduler ignores nodeAffinity?

查看:245
本文介绍了为什么kubernetes调度程序会忽略nodeAffinity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用kops部署到aws的kubernetes集群版本1.12

I have a kubernetes cluster version 1.12 deployed to aws with kops

集群中有多个节点,其节点标记为'example.com/myLabel',其值分别为a,b,c,d

The cluster has several nodes marked with a label 'example.com/myLabel' that takes the values 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,并选择权重总和最大的节点.

According to the documentation, nodeAffinity must exist for each node that can be used for a scheduled pod and the node having the biggest weight sum is chosen.

我希望所有吊舱都被调度到带有标签"a"的节点instance1上,但就我而言,这些节点是随机选择的.

I expect all pods to be scheduled to node instance1 with label ‘a’, but in my case, the nodes are chosen randomly.

例如,这是为部署中的6个pod计划的5个节点,包括another1和another2节点,这些节点根本不包含我的标签(还有另一个带有此标签的标签,其值为'd'):

For example, here are the 5 nodes planned for 6 pods from the deployment, including another1 and another2 nodes, which do not contain my label at all (there is another node with this label with the value 'd'):


NODE        LABEL
another1    NONE
node1        a
node2        b
node3        c
another2    NONE

所有节点都具有容量,它们可用并且可以运行pod

All nodes have capacity, they are available and can run pods

我有2个问题

  1. 为什么会这样?

  1. Why does this happen?

k8s调度程序在哪里记录有关如何为Pod分配节点的信息?事件不包含此信息,并且主服务器上的调度程序日志为空

Where does the k8s scheduler log information on how a node is assigned for a pod? Events do not contain this information and scheduler logs on masters are empty

更新:

我的节点包含正确的标签

My nodes contains correctly labels

example.com/myLabel=a
example.com/myLabel=b
example.com/myLabel=c
example.com/myLabel=d

推荐答案

preferredDuringSchedulingIgnoredDuringExecution只是意味着调度程序会将您设置的权重添加到用于选择调度到哪个节点的算法中.这不是硬性规则,而是首选规则.

preferredDuringSchedulingIgnoredDuringExecution just means that the scheduler will add the weight you set to the algorithm it uses to choose which node to schedule to. This is not a hard rule but a preferred rule.

随着您设置的权重,您将获得某种程度的均匀分布.在开始看到您要寻找的点差之前,您需要有非常大的样本量.

With the weights you set, you will get a somewhat even spread. You would need to have a very large sample size before you would start to see the spread you are aiming for.

请记住,权重"不仅取决于您设置的亲和力,节点的其他因素也具有自己的权重.如果您想更清楚地看到效果,请在每个亲和力之间使用更大的权重差

Keep in mind that the "weight" is not just taken by the affinity you set, other factors of the nodes have their own weight as well. If you want to see the effect more clearly, use a greater weight difference between each affinity

这篇关于为什么kubernetes调度程序会忽略nodeAffinity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆