当前位置:网站首页>descheduler 二次调度让 Kubernetes 负载更均衡
descheduler 二次调度让 Kubernetes 负载更均衡
2022-06-12 06:38:00 【陈少文的网站】
1. 为什么需要二次调度
Kubernetes 调度器的作用是将 Pod 绑定到某一个最佳的节点。为了实现这一功能,调度器会需要进行一系列的筛选和打分。
Kubernetes 的调度是基于 Request,但是每个 Pod 的实际使用值是动态变化的。经过一段时间的运行之后,节点的负载并不均衡。一些节点负载过高、而有些节点使用率很低。
因此,我们需要一种机制,让 Pod 能更健康、更均衡的动态分布在集群的节点上,而不是一次性调度之后就固定在某一台主机上。
2. descheduler 的几种运行方式
descheduler 是 kubernetes-sigs 下的子项目,先将代码克隆到本地,进入项目目录:
| |
如果运行环境无法拉取 gcr 的镜像,可以将 k8s.gcr.io/descheduler/descheduler 替换为 k8simage/descheduler。
- 一次性 Job
只执行一次
| |
- 定时任务 CronJob
默认是 */2 * * * * 每隔 2 分钟执行一次
| |
- 常驻任务 Deployment
默认是 --descheduling-interval 5m 每隔 5 分钟执行一次
kubectl create -f kubernetes/base/rbac.yamlkubectl create -f kubernetes/base/configmap.yamlkubectl create -f kubernetes/deployment/deployment.yaml- CLI 命令行
先在本地生成策略文件,然后执行 descheduler 命令
| |
descheduler 有 --help 参数可以查看相关帮助文档。
| |
3. 测试调度效果
- cordon 部分节点,仅允许一个节点参与调度
| |
- 运行一个 40 副本数的应用
可以观察到这个应用的副本全都在 node3 节点上。
kubectl get pod -o wide|grep nginx-645dcf64c8|grep node3|wc -l 40- 集群中部署 descheduler
这里使用的是 Deployment 方式。
| |
- 放开节点调度
调度前,所有副本都集中在 node3 节点
| |
放开节点调度
| |
- 查看 descheduler 相关日志
当满足定时要求时,descheduler 就会开始根据策略驱逐 Pod。
| |
- 二次调度之后的 Pod 分布
节点的负载情况,node3 下降,其他节点都上升了一些。
| |
Pod 在节点上的分布,这是在没有配置任何亲和性、反亲和性的场景下。
| 节点 | Pod数量(共40副本) |
|---|---|
| node2 | 11 |
| node3 | 10 |
| node4 | 11 |
| node5 | 8 |
Pod 的数量分布非常均衡,其中 node2-4 虚拟机配置一样,node5 配置较低。如下图是整个过程的示意图:

4. descheduler 调度策略
查看官方仓库推荐的默认策略配置:
| |
默认开启了 RemoveDuplicates、RemovePodsViolatingInterPodAntiAffinity、LowNodeUtilization 策略。我们可以根据实际场景需要进行配置。
descheduler 目前提供了如下几种调度策略:
- RemoveDuplicates
驱逐同一个节点上的多 Pod
- LowNodeUtilization
查找低负载节点,从其他节点上驱逐 Pod
- HighNodeUtilization
查找高负载节点,驱逐上面的 Pod
- RemovePodsViolatingInterPodAntiAffinity
驱逐违反 Pod 反亲和性的 Pod
- RemovePodsViolatingNodeAffinity
驱逐违反 Node 反亲和性的 Pod
- RemovePodsViolatingNodeTaints
违反 NoSchedule 污点的 Pod
- RemovePodsViolatingTopologySpreadConstraint
驱逐违反拓扑域的 Pod
- RemovePodsHavingTooManyRestarts
驱逐重启次数太多的 Pod
- PodLifeTime
驱逐运行时间超过指定时间的 Pod
- RemoveFailedPods
驱逐失败状态的 Pod
5. descheduler 有哪些适用场景
descheduler 的视角在于动态,其中包括两个方面:Node 和 Pod。Node 动态的含义在于,Node 的标签、污点、配置、数量等发生变化时。Pod 动态的含义在于,Pod 的资源实际使用值、在 Node 上的分布等不是恒定值。
根据这些动态特征,可以归纳出如下适用场景:
- 新增了节点
- 节点重启之后
- 修改节点拓扑域、污点之后,希望存量的 Pod 也能满足拓扑域、污点
- Pod 没有均衡分布在不同节点
如果是因为 Pod 的实际使用值远超过 Reqeust 值,更好的方式是调整 Request 值,而不是让 Pod 重新调度。
6. 参考
边栏推荐
- LeetCode个人题解(剑指offer3-5)3.数组中重复的数字,4.二维数组中的查找,5.替换空格
- 2021 robocom world robot developer competition - undergraduate group (Preliminary)
- The seventh day of June training - hash table
- 六月集训 第五天——双指针
- Solution: content type 'application/x-www-form-urlencoded; charset=UTF-8‘ not supported
- Redis configuration (III) -- master-slave replication
- 六月集训 第一日——数组
- LeetCode-1629. Key with the longest key duration
- Trunet: short videos generation from long videos via story preserving truncation (thesis translation)
- Redis queue
猜你喜欢

Modifying theme styles in typora

Are you still using like+% for MySQL fuzzy query?

Solution: content type 'application/x-www-form-urlencoded; charset=UTF-8‘ not supported

About session Getattribute, getattribute error

Multithreading (4) -- no lock (3) -- longadder source code

Multithreading (2) -- pipeline (2) -- synchronized underlying monitor, lightweight, biased lock, lock inflation

Redis basic notes

Leetcode January 13 daily question 747 At least twice the maximum number of other numbers

Android studio mobile development creates a new database and obtains picture and text data from the database to display on the listview list

Codeforces Round #793 (Div. 2) A B C
随机推荐
LeetCode-1629. Key with the longest key duration
Trunet: short videos generation from long videos via story preserving truncation (thesis translation)
Idea common shortcut keys
LeetCode-1078. Bigram participle
SQL 注入-盲注
六月集训 第一日——数组
leetcode 300. Longest increasing subsequence
[reinstall system] 01 system startup USB flash disk production
leetcode:890. 查找和替换模式【两个dict记录双射(set)】
Multithreading (2) -- pipeline (4) -- Park and unpark
[word] word 2010 recording macro batch replacing paragraph marks in the selected text
LeetCode-1576. Replace all question marks
LeetCode-1445. Apples and oranges
PDF. JS help file
数据库全量SQL分析与审计系统性能优化之旅
Touch screen setting for win7 system dual screen extended display
MySQL group query to obtain the latest data date function of each group
leetcode:剑指 Offer 66. 构建乘积数组【前后缀积的应用】
Video based fire smoke detection using robust AdaBoost
LeetCode-1490. Clone n-ary tree