K8S学习之污点容忍
污点:使节点能够排斥一类特定的 pod。Taint 和 toleration 相互配合,可以用来避免pod 被分配到不合适的节点上。
节点亲和性:是pod的一种属性(偏好或硬性要求),它使pod被吸引到一类特定的节点。
taints:污点,定义在节点上,是键值数据
tolerations:容忍度,定义在pod上,可以定义能容忍哪些污点
污点的查看
[root@master ~]# kubectl describe nodes master | grep Taints
Taints: node-role.kubernetes.io/master:NoSchedule....
[root@master ~]# kubectl explain node.spec.taints
NoSchedule 不会被调度
PreferNoSchedule 尽量不调度
NoExecute 驱逐节点
污点的添加与删除
[root@master ~]# kubectl taint nodes node1 key=value:NoSchedule
[root@master ~]# kubectl taint nodes node1 key:NoSchedule-
key=value:NoSchedule key:NoSchedule-
它的 key 键是 key,value 值是 value,effect行为是 NoSchedule。这表示只有拥有和这个 taint 相匹配的 toleration 的 pod 才能够被分配到 node1 这个节点。当然你也可以给一个节点添加多个 taint ,也可以给一个 pod 添加多个 toleration。
容忍度(pod.spec.tolerations)
effect、key、operator、tolerationSeconds、value
一个 toleration和一个 taint 相“匹配”是指它们有一样的key和effect ,operator 默认是 Equal ,即value 相等才匹配。如果operator是Exists,则toleration 不能指定 value。
tolerations:
- key: "key"operator: "Equal"value: "value"effect: "NoSchedule"tolerations:
- key: "key"operator: "Exists"effect: "NoSchedule"
如果一个 toleration 的 effect 为空,则 key 值与之相同就能完成匹配 ,taint的effect可以是任意值。
tolerations:
- key: "key"operator: "Exists"
如果这个pod的所在节点打了该污点,配置了tolerationSeconds那么pod 还将继续在节点上运行 一段时间,如下3600 秒
tolerations:
- key: "key"operator: "Equal"value: "value"effect: "NoExecute"tolerationSeconds: 3600
使用场景
专用节点:如果你想将某些节点专门分配给特定的一组用户使用,你可以给这些节点添加一个 taint。如果要使pod 只能被分配到专用节点,那么你可以给节点打个标签,将 pod 的节点亲和性与容忍结合使用。
配备了特殊硬件的节点:在部分节点配备了特殊硬件(比如 GPU)的集群中,我们希望不需要这类硬件的 pod 不要被分配到这些特殊节点,以便为后继需要这类硬件的 pod 保留资源。
节点问题:当某种条件为真时,node controller会自动给节点添加一个 taint。当前内置的 taint 包括:
node.kubernetes.io/not-ready:节点未准备好。这相当于节点状态 Ready 的值为 “False”。
node.kubernetes.io/unreachable:node controller 访问不到节点
node.kubernetes.io/out-of-disk:节点磁盘耗尽。
node.kubernetes.io/memory-pressure:节点存在内存压力。
node.kubernetes.io/disk-pressure:节点存在磁盘压力。
node.kubernetes.io/network-unavailable:节点网络不可用。
node.kubernetes.io/unschedulable: 节点不可调度。
比如,一个使用了很多本地状态的应用程序在网络断开时,仍然希望停留在当前节点上运行一段较长的时间,愿意等待网络恢复以避免被驱逐。在这种情况下,pod 的 toleration 可能是下面这样的:
tolerations:
- key: "node.kubernetes.io/unreachable"operator: "Exists"effect: "NoExecute"tolerationSeconds: 6000
注意,Kubernetes 会自动给 pod 添加 key 为 node.kubernetes.io/not-ready 的 toleration 并配置 tolerationSeconds=300,和key为node.kubernetes.io/unreachable 的 toleration 并配置 tolerationSeconds=300,除非用户提供的 pod 配置中已经已存在了这两个key。这种自动添加 toleration 机制保证了在其中一种问题被检测到时 pod 默认能够继续停留在当前节点运行 5 分钟。
自 Kubernetes 1.8 起, DaemonSet 控制器自动为所有守护进程添加如下 NoSchedule toleration 以防 DaemonSet 崩溃
node.kubernetes.io/memory-pressure
node.kubernetes.io/disk-pressure
node.kubernetes.io/out-of-disk (只适合 critical pod)
node.kubernetes.io/unschedulable (1.10 或更高版本)
node.kubernetes.io/network-unavailable (只适合 host network)
这里查看了一下之前创建的daemonset,fluentd的容忍
[root@master ~]# kubectl describe pod -n kube-system fluentd-elasticsearch-
Tolerations: :NoSchedule op=Exists:NoExecute op=ExistsCriticalAddonsOnly op=Existsnode.kubernetes.io/disk-pressure:NoSchedule op=Existsnode.kubernetes.io/memory-pressure:NoSchedule op=Existsnode.kubernetes.io/network-unavailable:NoSchedule op=Existsnode.kubernetes.io/not-ready:NoExecute op=Existsnode.kubernetes.io/pid-pressure:NoSchedule op=Existsnode.kubernetes.io/unreachable:NoExecute op=Existsnode.kubernetes.io/unschedulable:NoSchedule op=Exists
污点容忍的举例
给node1打污点,创建pod,此时 Events:告诉我们两个节点,0个可用。两个节点都有taints。pod的创建时一致处于Pending ,是失败的
[root@master ~]# kubectl taint nodes node1 name=lucky:NoSchedule
node/node1 tainted
[root@master ~]# vim pod.yaml
apiVersion: v1
kind: Pod
metadata:name: pod-nginx
spec:containers:- name: nginximage: nginximagePullPolicy: IfNotPresent
[root@master ~]# kubectl apply -f pod.yaml
pod/pod-nginx created
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
pod-nginx 0/1 Pending 0 5s
[root@master ~]# kubectl describe pod pod-nginx
Events:Type Reason Age From Message---- ------ ---- ---- -------Warning FailedScheduling 16s default-scheduler 0/2 nodes are available: 1 node(s) had taint {name: lucky}, that the pod didn't tolerate, 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
我们删除污点后pod在node1上创建成功
[root@master ~]# kubectl taint nodes node1 name:NoSchedule-
node/node1 untainted
[root@master ~]# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED
pod-nginx 1/1 Running 0 12s 10.244.1.87 node1 <none>
我们重新添加污点,发现已存在的pod不受影响
[root@master ~]# kubectl taint nodes node1 name=lucky:NoSchedule
node/node1 tainted
[root@master ~]# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE
pod-nginx 1/1 Running 0 3m25s 10.244.1.87 node1 <none>
删除pod,创建一个带有容忍的pod
[root@master ~]# kubectl delete -f pod.yaml
[root@master ~]# vim pod.yaml
apiVersion: v1
kind: Pod
metadata:name: pod-nginx
spec:containers:- name: nginximage: nginximagePullPolicy: IfNotPresenttolerations:- key: namevalue: luckyeffect: NoSchedule
[root@master ~]# kubectl apply -f pod-pvc.yaml
可以看到pod已经创建成功
[root@master ~]# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE pod-nginx 1/1 Running 0 6m33s 10.244.1.87 node1 <none>
[root@master ~]# kubectl describe nodes node1 | grep Taints
Taints: name=lucky:NoSchedule
[root@master ~]# kubectl taint nodes node1 name:NoSchedule-
node/node1 untainted
对于tolerations属性的写法:
其中的key、value、effect 与Node的Taint设置需保持一致:
1、如果operator的值是Exists,则value属性可省略。
2、如果operator的值是Equal,则表示其key与value之间的关系是equal(等于)。
3、如果不指定operator属性,则默认值为Equal。
另外,还有两个特殊值:
1、空的key 如果再配合Exists ,就能匹配所有的key与value ,也就是能容忍所有node上的所有Taints。
2、空的effect,匹配所有的effect
K8S学习之污点容忍相关推荐
- k8s学习-污点和容忍(概念、模版、创建、删除)
目录 概念 模版 实战 添加污点 添加容忍 移除污点 参考 概念 污点(Taint)使节点能够排斥/驱逐一类特定的 Pod,通过给 Node 打一些污点,来限制 Pod 调度到某些 Node 上. 容 ...
- Kubernetes K8S之Taints污点与Tolerations容忍详解
Kubernetes K8S之Taints污点与Tolerations容忍详解与示例 主机配置规划 服务器名称(hostname) 系统版本 配置 内网IP 外网IP(模拟) k8s-master C ...
- 不背锅运维:K8S之污点、污点容忍
写在开篇 ❝ 本篇分享k8s的污点.污点容忍,感谢持续关注我的盆友们.如有考k8s认证需求的盆友,可和我取得联系,了解K8S认证请猛戳:<K8s CKA+CKS认证实战班>2023版 ❞ ...
- k8s核心技术-Pod(调度策略)_影响Pod调度(污点和污点容忍)---K8S_Google工作笔记0027
技术交流QQ群[JAVA,C++,Python,.NET,BigData,AI]:170933152 上面咱们说了亲和性,其实还有一个调度规则,就是反亲和性 ,根据反亲和性进行调度. 所谓的反亲和性就 ...
- K8S taint(污点)和tolerations(污点容忍)
文章目录 一.Taint(污点) `1.1概念` `1.2设置污点` 取消污点 二.tolerations(污点容忍) `2.1概念` `2.2示例` 三.Node 和 Pod 对于污点与容忍基本概念 ...
- Kubernetes 调度 Node污点/容忍
Node 标记/容忍 还有第三类调度,可以通过给 Node 打一些标记,来限制 Pod 调度到某些 Node 上.Kubernetes 把这些标记称之为 Taints,它的字面意思是污染.(污点=ke ...
- k8s学习笔记- 部署prometheus
1.Prometheus概述 Prometheus是一个开源监控系统,它前身是SoundCloud的警告工具包.从2012年开始,许多公司和组织开始使用Prometheus. 该项目的开发人员和用户社 ...
- 文章目录 | .NET Core on K8s学习之旅 (更新至20200618)
.NET Core on K8s学习之旅 更新记录: -- 20200511 增加Ingress & Nginx Ingress介绍 -- 20200515 增加Ocelot API网关集成示 ...
- ASP.NET Core on K8s学习之旅(14)Ingress灰度发布
[云原生]| 作者/Edison Zhou 这是恰童鞋骚年的第236篇原创文章 上一篇介绍了Ingress的基本概念和Nginx Ingress的基本配置和使用,然后我还录了一个快速分享小视频介绍了一 ...
最新文章
- Laravel Lumen之Eloquent ORM使用速查-基础部分
- 比 GPT-3 更擅长理解用户意图,OpenAI发布 InstructGPT
- 【机器学习】--隐含马尔科夫模型从初识到应用
- 浅谈Http模块,Express和Koa实现http服务
- 超越Android:探索Kotlin的应用领域
- select count(*) from返回的类型_数据分析面试题类型汇总
- MFC中打开指定文件夹并默认选中该文件夹中的某个文件
- python基础--numpy.random
- 使用OpenCV需要注意的小细节
- 最全的HTTP1.1状态码
- 2021年全球无损检测设备收入大约2189.6百万美元,预计2028年达到3076.2百万美元,2022至2028期间,年复合增长率CAGR为5.4%
- QQ群排名优化规则-学会后10分钟全国排名第一
- win10使用powerShell执行ps1文件方法
- 三大移动终端操作系统比较
- 本地用户和组 无法访问计算机 远程过程调用失败,如何解决远程过程调用失败?怎样使用向日葵远程控制?...
- 在小鸟云进行服务器托管,怎么升级配置?
- java程序员一般用什么笔记本_程序员对笔记本电脑有什么要求吗?推荐下哪些牌子笔记本性价比高?...
- 联想微型计算机2010年,2010年10月自考02277微型计算机原理及应用真题及答案
- 基于 B/S 架构自助点餐系统的设计与实现
- 读到心醉,很美的文字
热门文章
- asp.net web开发框架_Web前端开发必不可少的9个开源框架
- idea连接linux中mysql[08S01]错误
- 弥散阴影html,超赞!一份简单易上手的青春弥散阴影修炼手册
- Word给公式插入编号和引用
- 麒麟820和鸿蒙系统,网曝魅族正在适配麒麟820和鸿蒙系统,黄章:我怎么不知道...
- 告诉你60个经典的电脑使用技巧
- Android安卓——实现发短信功能的代码
- MOOC 苏小红C语言 第四周编程题
- 对于软件,我是认真的
- 吴晓波最劲爆演讲:终于把传统行业的转型升级都讲清楚了