当前位置:网站首页>Pod Scheduling Strategy: Affinity, Stain and Stain Tolerance
Pod Scheduling Strategy: Affinity, Stain and Stain Tolerance
2022-08-02 12:08:00 【GottdesKrieges】
Pod调度策略:亲和性、污点与污点容忍
节点亲和性
nodeSelector
nodeSelector用于将Pod调度到匹配Label的节点上,如果没有匹配的标签会调度失败.
作用:
- 约束Pod到特定节点运行;
- 完全匹配节点标签.
应用场景:
- 专用节点:Nodes are grouped and managed according to business lines;
- Match special hardware:Some nodes are configured with SSD硬盘、GPU.
示例:确保Pod分配到具有SSD硬盘的节点上
- 给节点打标签
#kubectl label nodes <node名称> <label-key>=<label-value>
kubectl label nodes k8s-node1 disktype=ssd
#验证
kubectl get nodes --show-labels
- 添加nodeSelector字段到Pod配置中
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
nodeSelector:
disktype: ssd
- 验证
kubectl get pods -o wide
删除节点标签:
kubectl label node k8s-node1 <label-key>-
#验证
kubectl get pods -o wide
nodeAffinity
节点亲和性,类似于nodeSelector,可以根据节点上的标签来约束Pod可以调度到哪些节点.
相比nodeSelector:
- 匹配有更多的逻辑组合,不只是字符串的完全相等,支持
in、notin、exists、doesnotexist、gt、lt操作符. - 调度分为软策略和硬策略,而不是硬性要求:
requiredDuringSchedulingIgnoredDuringExecution:硬策略,必须满足;preferredDuringSchedulingIgnoredDuringExecution:软策略,尝试满足,但是不保证.
举例:
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: another-node-label-key
operator: In
values:
- another-node-label-value
containers:
- name: with-node-affinity
image: k8s.gcr.io/pause:2.0
注意:
- 如果同时使用了
nodeSelector和nodeAffinity,那么k8s在调度PodBoth conditions must be met at the same time. - 如果在使用
nodeAffinitywhen specifying multiplenodeSelectorTerms,Then the node only needs to satisfy one of themnodeSelectorTerms,can be dispatchedPod. - 如果在一个
nodeSelectorTermsMore than one is specified belowmatchExpressions,Then the node must satisfy allmatchExpressions,to be dispatchedPod.
污点与污点容忍
基于节点标签分配是站在Pod的角度上,通过在Pod上添加属性,来确定PodWhether to schedule to the specified node.相反地,我们也可以在NodeAdd a taint attribute to the node(Taints),来避免Pod被分配到不合适的节点上.
taints:避免Pod调度到特定节点上;tolerations:允许Pod调度到有Taints的节点上.
举例:
- 给节点添加污点
#kubectl taint node <node名称> key=value:[effect]
kubectl taint node k8s-node2 gpu=yes:NoSchedule
其中,effect可以取值为:
NoSchedule:一定不能被调度;PreferNoSchedule:尽量不要被调度,非必须;NoExecute:不仅不会调度,It will also evict existing ones on the nodePod.
- 验证
kubectl describe node k8s-node2 | grep Taint
- 如果希望PodCan be assigned to tainted nodes,要在PodAdd taint tolerance to configuration.
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
tolerations:
- key: "gpu"
operator: "Equal"
value: "yes"
effect: "NoSchedule"
删除污点:
#kubectl taint node <node名称> key:[effect]-
kubectl taint node k8s-node2 gpu:NoSchedule-
注意:
Taints和Tolerations匹配的原则是key相同、effect相同,并且满足:
- 运算符是
Exists(即没有value); - 运算符是
Equal,且value相等.
两个特例:
- 一个空的
key和运算符Exists,会匹配所有的key、value和effect,Means tolerating all blemishes; - 一个
key和一个空的effect匹配此key的所有effect.
References
【1】https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/
【2】https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/
边栏推荐
- simulink PID auto-tuning
- 力扣35-搜索插入位置——二分查找
- List排序 ,取最大值最小值
- Problem solving in the process of using mosquitto
- darknet训练yolov4模型
- Failure Analysis | A SELECT statement crashes MySQL, what happened?
- 干测试这些年,去过阿里也去过小公司,给年轻测试员们一个忠告...
- Lexicon 27 - Remove Elements - Simple Questions
- Crack detection technology based on deep learning
- 太厉害了,终于有人能把TCP/IP 协议讲的明明白白了
猜你喜欢

Likou 977-Squaring of ordered arrays - brute force method & double pointer method

Technology sharing | Description of the electronic fence function in the integrated dispatching system

数据湖(一):数据湖概念

QListView的使用

#夏日挑战赛#【FFH】OpenHarmony设备开发基础(三)编译依赖

力扣977-有序数组的平方——暴力法&双指针法

DTG-SSOD:最新半监督检测框架,Dense Teacher(附论文下载)

MD5 detailed explanation (check file integrity)

自己如何做小程序呢?

网站自动翻译-网站批量自动翻译-网站免费翻译导出
随机推荐
阿苹的思考
MyCat2的介绍与安装以及基本使用
19、商品微服务-srv层实现
手撸架构,网络 面试36问
力扣704-二分查找
AQS-AbstractQueuedSynchronizer
Pytorch 占用cpu资源过多
Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单。
Thymeleaf
受邀出席Rust开发者大会|Rust如何助力量化高频交易?
npm WARN config global `--global`, `--local` are deprecated. Use `--location解决方案
QListView的使用
【云驻共创】数据工坊平台,0代码开发数据处理业务“快”人一步
力扣58-左旋转字符串
SQL函数 TRIM
Problem solving in the process of using mosquitto
Likou 977-Squaring of ordered arrays - brute force method & double pointer method
基于深度学习的裂缝检测技术
【The 6th Strong Net Cup CTF-Wp】
Chapter 14 Manually create a REST service (2)