k8s-调度score算法解析

网友投稿 377 2022-09-12

k8s-调度score算法解析

1.Score算法

1.1noderesources.BalancedAllocationName

节点cpu使用百分比和内存使用百分比越接近,说明资源使用越均衡,节点分数越高

1.18版本

源码解析

1.22版本

源码截图

1.2imagelocality

选择已经存在 Pod 运行所需容器镜像的节点。

检查Node是否存在Pod所需镜像:如果不存在,返回0分;如果存在,则镜像越大得分越高。

同时,如果一个pod中有两个容器镜像,如果节点上两个镜像都存在的节点分数 〉节点上只有一个镜像的分数

那么有相同镜像数量的节点的分数就是相同的

会考虑镜像在每个节点的分布情况,避免每次都选择同一个节点。

// scaledImageScore returns an adaptively scaled score for the given state of an image.// The size of the image is used as the base score, scaled by a factor which considers how much nodes the image has "spread" to.// This heuristic aims to mitigate the undesirable "node heating problem", i.e., pods get assigned to the same or// a few nodes due to image locality.

源码

1.3noderesources.LeastAllocatedName

资源Requested越小的节点,即资源剩余越多的节点,分数越大

1.4nodeaffinity.Name

节点硬亲和通过filter过滤掉了

affinity: #亲和性 nodeAffinity: #node亲和性 # 硬亲和性限制 requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname # 标签键名 operator: NotIn #键值运算关系 ,NotIn:label的值不在某个列表中。 表示不是node02节点就可运行 values: - k8s-node02 # 标签键值

节点软亲和,可以写多个亲和策略

affinity: #亲和性 nodeAffinity: #node亲和性 preferredDuringSchedulingIgnoredDuringExecution: - weight: 1 #权重,权重越大越亲和(多个软策略的情况) preference: matchExpressions: - key: kubernetes.io/hostname operator: In values: - k8s-node03 # 期望是node03

1.5nodepreferavoidpods.Name

1.6podtopologyspread.Name

有点复杂,后面补充

1.7tainttoleration.Name

spec: tolerations: #containers同级 - key: "check" #能容忍的污点key operator: "Equal" #Equal等于表示key=value , Exists不等于,表示当值不等于下面value正常 value: "guozige" #值 effect: "PreferNoSchedule" #effect策略 tolerationSeconds: 3600 #原始的pod多久驱逐,注意只有effect: "NoExecute"才能设置,不然报错

通过filter过滤掉pod没有容忍node上污点的节点

通过score来处理effect: "PreferNoSchedule"  #effect策略 这种污点的节点分数

参考文献

​​https://zhuanlan.zhihu.com/p/27754017​​

​​https://kubernetes.io/zh/docs/reference/scheduling/config/#scheduling-plugins​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:k8s-调度器自定义
下一篇:苹果隐私新规将落地 广告营销游戏分发直面冲击!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~