Kubernetes实战(十八)-Pod配置污点和容忍

news2025/1/14 18:13:03

1 污点

1.1 污点简介

亲和性调度的方式都是站在Pod的角度上,通过在Pod上增加属性来将Pod调度到到指定的节点上,其实也可以站在Node节点的角度上,通过给Node节点设置属性,来决定是否允许Pod调度过来,这就是污点。

Node被设置上污点之后就和Pod存在了一种相斥的关系,进而拒绝Pod调度进来,甚至可以将已经存在的Pod驱逐出去。

污点的格式为 key=value:effect,key和value是污点的标签,effect描述五点多额作用,支持如下三个选项

  • PreferNoSchedule:Kubernetes将尽量避免把Pod调度到具有此污点的Node上,除非没有其他节点可调度了
  • NoSchedule:Kubernetes将不会把Pod调度到具有该污点的Node上,但不会影响当前Node上已经存在的Pod
  • NoExecute:Kubernetes将不会把Pod调度到具有此污点的Node上,同时也会将Node上已经存在的Pod驱逐

1.2 污点命令

# 设置污点

$ kubectl taint nodes node1 key=value:effect

# 去除污点

$ kubectl taint nodes node1 key:effect-

# 去除所有污点

$ kubectl taint nodes node1 key-

1.3 污点案例

1)给node1设置一个污点,尽量不要调度过来pod

[root@master resource_manage]# kubectl taint nodes node1 name=nginx:PreferNoSchedule
node/node1 tainted

2)创建 nginx pod

[root@master resource_manage]# kubectl run nginx --image=nginx:1.17.1 --port=80
pod/nginx created

3)查询pod调度信息

[root@master resource_manage]# kubectl get pod -o wide
NAME    READY   STATUS    RESTARTS   AGE   IP            NODE    NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          7s    10.244.2.48   node2   <none>           <none>

可以看到此时直接调度到node2了,不会调度到node1的,当然如果此时node2挂了,只有node1存活时,也会调度过来的。

1.4 查询节点污点

[root@master resource_manage]# kubectl describe node node1
Name:               node1
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=node1
                    kubernetes.io/os=linux
                    nodeenv=test
Annotations:        flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"ba:fe:1f:25:fe:26"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.16.41
                    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Mon, 14 Mar 2022 14:41:02 +0800
Taints:             name=nginx:PreferNoSchedule
Unschedulable:      false
Lease:
  HolderIdentity:  node1
  AcquireTime:     <unset>
  RenewTime:       Sat, 26 Mar 2022 00:00:54 +0800
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Mon, 14 Mar 2022 14:43:39 +0800   Mon, 14 Mar 2022 14:43:39 +0800   FlannelIsUp                  Flannel is running on this node
  MemoryPressure       False   Fri, 25 Mar 2022 23:58:57 +0800   Mon, 14 Mar 2022 14:41:02 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Fri, 25 Mar 2022 23:58:57 +0800   Mon, 14 Mar 2022 14:41:02 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Fri, 25 Mar 2022 23:58:57 +0800   Mon, 14 Mar 2022 14:41:02 +0800   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Fri, 25 Mar 2022 23:58:57 +0800   Mon, 14 Mar 2022 14:43:42 +0800   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.16.41
  Hostname:    node1
Capacity:
  cpu:                8
  ephemeral-storage:  208357992Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             32882960Ki
  pods:               110
Allocatable:
  cpu:                8
  ephemeral-storage:  192022725110
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             32780560Ki
  pods:               110
System Info:
  Machine ID:                 f9c2b25f57184e06b8855490b4be6013
  System UUID:                d1042642-3933-564f-4f2d-279b5e96cead
  Boot ID:                    8517c1cc-8935-452e-9efb-a34f396b98a5
  Kernel Version:             5.4.179-200.el7.x86_64
  OS Image:                   CentOS Linux 7 (Core)
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  docker://20.10.9
  Kubelet Version:            v1.21.2
  Kube-Proxy Version:         v1.21.2
PodCIDR:                      10.244.1.0/24
PodCIDRs:                     10.244.1.0/24
Non-terminated Pods:          (4 in total)
  Namespace                   Name                                         CPU Requests  CPU Limits  Memory Requests  Memory Limits  Age
  ---------                   ----                                         ------------  ----------  ---------------  -------------  ---
  kube-system                 kube-flannel-ds-gg4jq                        100m (1%)     100m (1%)   50Mi (0%)        50Mi (0%)      11d
  kube-system                 kube-proxy-tqzjl                             0 (0%)        0 (0%)      0 (0%)           0 (0%)         11d
  kubernetes-dashboard        dashboard-metrics-scraper-c45b7869d-7ll25    0 (0%)        0 (0%)      0 (0%)           0 (0%)         11d
  kubernetes-dashboard        kubernetes-dashboard-79b5779bf4-t28b4        0 (0%)        0 (0%)      0 (0%)           0 (0%)         11d
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests   Limits
  --------           --------   ------
  cpu                100m (1%)  100m (1%)
  memory             50Mi (0%)  50Mi (0%)
  ephemeral-storage  0 (0%)     0 (0%)
  hugepages-1Gi      0 (0%)     0 (0%)
  hugepages-2Mi      0 (0%)     0 (0%)
Events:              <none>

1.5 删除污点

$ kubectl taint nodes node1 name:PreferNoSchedule-
node/node1 untainted

1.6 为什么创建Pod的时候不会调度到master节点?

通过如下命令可以看到master节点是默认设置了node-role.kubernetes.io/master:NoSchedule类型的污点,因此在创建pod的时候是不会往master节点调度的。

[root@master resource_manage]# kubectl describe nodes master
Name:               master
Roles:              control-plane,master
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=master
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/control-plane=
                    node-role.kubernetes.io/master=
                    node.kubernetes.io/exclude-from-external-load-balancers=
Annotations:        flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"02:f6:8e:03:60:51"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.16.40
                    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Mon, 14 Mar 2022 14:38:03 +0800
Taints:             node-role.kubernetes.io/master:NoSchedule
Unschedulable:      false
Lease:
  HolderIdentity:  master
  AcquireTime:     <unset>
  RenewTime:       Sat, 26 Mar 2022 00:05:31 +0800
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Mon, 14 Mar 2022 14:42:58 +0800   Mon, 14 Mar 2022 14:42:58 +0800   FlannelIsUp                  Flannel is running on this node
  MemoryPressure       False   Sat, 26 Mar 2022 00:01:28 +0800   Mon, 14 Mar 2022 14:38:02 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Sat, 26 Mar 2022 00:01:28 +0800   Mon, 14 Mar 2022 14:38:02 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Sat, 26 Mar 2022 00:01:28 +0800   Mon, 14 Mar 2022 14:38:02 +0800   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Sat, 26 Mar 2022 00:01:28 +0800   Mon, 14 Mar 2022 14:43:03 +0800   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.16.40
  Hostname:    master
Capacity:
  cpu:                8
  ephemeral-storage:  208357992Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             32882960Ki
  pods:               110
Allocatable:
  cpu:                8
  ephemeral-storage:  192022725110
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             32780560Ki
  pods:               110
System Info:
  Machine ID:                 f9c2b25f57184e06b8855490b4be6013
  System UUID:                c5d32642-f84c-61ef-ac7f-d65ae6880a51
  Boot ID:                    9cbc9b25-2cf2-42d8-aa89-1fdab687c447
  Kernel Version:             5.4.179-200.el7.x86_64
  OS Image:                   CentOS Linux 7 (Core)
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  docker://20.10.9
  Kubelet Version:            v1.21.2
  Kube-Proxy Version:         v1.21.2
PodCIDR:                      10.244.0.0/24
PodCIDRs:                     10.244.0.0/24
Non-terminated Pods:          (6 in total)
  Namespace                   Name                              CPU Requests  CPU Limits  Memory Requests  Memory Limits  Age
  ---------                   ----                              ------------  ----------  ---------------  -------------  ---
  kube-system                 etcd-master                       100m (1%)     0 (0%)      100Mi (0%)       0 (0%)         11d
  kube-system                 kube-apiserver-master             250m (3%)     0 (0%)      0 (0%)           0 (0%)         11d
  kube-system                 kube-controller-manager-master    200m (2%)     0 (0%)      0 (0%)           0 (0%)         11d
  kube-system                 kube-flannel-ds-n76xj             100m (1%)     100m (1%)   50Mi (0%)        50Mi (0%)      11d
  kube-system                 kube-proxy-h27ms                  0 (0%)        0 (0%)      0 (0%)           0 (0%)         11d
  kube-system                 kube-scheduler-master             100m (1%)     0 (0%)      0 (0%)           0 (0%)         11d
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                750m (9%)   100m (1%)
  memory             150Mi (0%)  50Mi (0%)
  ephemeral-storage  0 (0%)      0 (0%)
  hugepages-1Gi      0 (0%)      0 (0%)
  hugepages-2Mi      0 (0%)      0 (0%)
Events:              <none>

2 容忍

2.1 容忍简介

当对一个node节点定义了污点,但是又希望某一些pod是可以调度到带有污点的节点上,此时就需要容忍了,污点就是拒绝,容忍就是忽略/允许,Node通过污点拒绝Pod调度上去,Pod通过容忍忽略拒绝,如下:

2.2 容忍实战

1)给node1设置NoSchedule污点

此时为演示,可以先保持只有node1一个节点,将其他节点关闭

[root@master resource_manage]# kubectl taint nodes node1 name=nginx:NoSchedule
node/node1 tainted

2)编辑带有容忍的pod_toleration.yaml文件

apiVersion: v1
kind: Namespace
metadata:
  name: dev

---

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  namespace: dev
spec:
  containers:
  - name: nginx
    image: nginx:1.17.1
  tolerations:
  - key: "name"
    operator: "Equal"
    value: "nginx"
    effect: "NoSchedule"

3)创建资源

[root@master resource_manage]# kubectl apply -f pod_toleration.yaml
namespace/dev created
pod/nginx-pod created

4)查看验证

然后通过如下命令查看,可以发现此时还是可以调度到node1节点上的

[root@master resource_manage]# kubectl get pod -n dev -o wide
NAME        READY   STATUS    RESTARTS   AGE   IP            NODE    NOMINATED NODE   READINESS GATES
nginx-pod   1/1     Running   0          13s   10.244.2.49   node1   <none>           <none>

2.3 容忍配置项说明

通过如下命令可以查看配置项的说明:

[root@master resource_manage]# kubectl explain pod.spec.tolerations
KIND:     Pod
VERSION:  v1

RESOURCE: tolerations <[]Object>

DESCRIPTION:
     If specified, the pod's tolerations.

     The pod this Toleration is attached to tolerates any taint that matches the
     triple <key,value,effect> using the matching operator <operator>.

FIELDS:
   effect       <string>
     Effect indicates the taint effect to match. Empty means match all taint
     effects. When specified, allowed values are NoSchedule, PreferNoSchedule
     and NoExecute.

   key  <string>
     Key is the taint key that the toleration applies to. Empty means match all
     taint keys. If the key is empty, operator must be Exists; this combination
     means to match all values and all keys.

   operator     <string>
     Operator represents a key's relationship to the value. Valid operators are
     Exists and Equal. Defaults to Equal. Exists is equivalent to wildcard for
     value, so that a pod can tolerate all taints of a particular category.

   tolerationSeconds    <integer>
     TolerationSeconds represents the period of time the toleration (which must
     be of effect NoExecute, otherwise this field is ignored) tolerates the
     taint. By default, it is not set, which means tolerate the taint forever
     (do not evict). Zero and negative values will be treated as 0 (evict
     immediately) by the system.

   value        <string>
     Value is the taint value the toleration matches to. If the operator is
     Exists, the value should be empty, otherwise just a regular string.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1401225.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数据结构代码实现 —— 单链表【Java】

单链表的概述及性质等在篇不做赘述&#xff0c;有需要可移步以下文章&#xff1a; 《数据结构 C语言版 严蔚敏 第2版》&#xff1a;线性表https://blog.csdn.net/weixin_43551213/article/details/134048025 以下仅展示使用 Java 实现单链表 结点结构定义&#xff1a; publ…

国外邮箱服务:功能、作用与价格全面解析

不同于我们熟悉的国内邮箱服务&#xff08;如163、QQ邮箱等&#xff09;&#xff0c;国外邮箱通常指的是海外提供商所提供的电子邮件服务&#xff0c;如谷歌的Gmail、微软的Outlook、雅虎的Yahoo Mail等&#xff0c;当然也有特殊的比如Zoho Mail邮箱&#xff0c;国内外双版本&a…

Docker(四)操作容器

作者主页&#xff1a; 正函数的个人主页 文章收录专栏&#xff1a; Docker 欢迎大家点赞 &#x1f44d; 收藏 ⭐ 加关注哦&#xff01; 操作 Docker 容器 容器是 Docker 又一核心概念。 简单的说&#xff0c;容器是独立运行的一个或一组应用&#xff0c;以及它们的运行态环境…

算法专题[递归-搜索-回溯-2-DFS]

算法专题[递归-搜索-回溯-2-DFS] 一.计算布尔二叉树的值&#xff1a;1.思路一&#xff1a;2.GIF题目解析 二.求根节点到叶子节点的数字之和1.思路一&#xff1a;2.GIF题目解析 三.二叉树剪枝1.思路一&#xff1a;2.GIF题目解析 四.验证二叉搜索树1.思路一&#xff1a;2.GIF题目…

C++学习笔记——指针

1&#xff0c;指针的基本概念 指针的作用&#xff1a;可以通过指针间接访问内存 内存的编号是从0开始记录的&#xff0c;一般用十六进制数字表示可以利用指针变量保存地址 上图中的p就是a变量的指针&#xff0c;也可以记作*a 2&#xff0c;指针变量的定义和使用 指针变量定…

AI大模型开发架构设计(3)——如何打造自己的大模型

文章目录 如何打造自己的大模型1 新时代职场人应用AIGC的5重境界2 人人需要掌握的大模型原理职场人都能听懂的大语音模型的训练过程职场人都能听得懂的大语言模型的Transformer推理过程 3 如何构建自己的大模型需要具备三个方面的能力LangChain是什么&#xff1f;LangChain主要…

【精选】中间件 tomcat漏洞复现

&#x1f36c; 博主介绍&#x1f468;‍&#x1f393; 博主介绍&#xff1a;大家好&#xff0c;我是 hacker-routing &#xff0c;很高兴认识大家~ ✨主攻领域&#xff1a;【渗透领域】【应急响应】 【python】 【VulnHub靶场复现】【面试分析】 &#x1f389;点赞➕评论➕收藏…

在腾讯云买了云服务器和域名如何快速建网站?

使用腾讯云服务器搭建网站全流程&#xff0c;包括轻量应用服务器和云服务器CVM建站教程&#xff0c;轻量可以使用应用镜像一键建站&#xff0c;云服务器CVM可以通过安装宝塔面板的方式来搭建网站&#xff0c;腾讯云服务器网txyfwq.com分享使用腾讯云服务器建站教程&#xff0c;…

基于SQL的可观测性现状观察

本文字数&#xff1a;8975&#xff1b;估计阅读时间&#xff1a;23 分钟 作者&#xff1a;Ryadh Dahimene 审校&#xff1a;庄晓东&#xff08;魏庄&#xff09; 本文在公众号【ClickHouseInc】首发 1375年的加泰罗尼亚地图所展示的地中海地区。通商媒介语&#xff08;Lingua F…

深度学习记录--正则化(regularization)

什么是正则化&#xff1f; 正则化(regularization)是一种实用的减少方差(variance)的方法&#xff0c;也即避免过度拟合 几种正则化的方法 L2正则化 又被称为权重衰减(weight dacay) 在成本函数中加上正则项&#xff1a; 其中 由于在w的更新过程中会递减&#xff0c;即权…

STL---Stack和Queue

一、stack的介绍和使用 &#xff08;1&#xff09;介绍 翻译: &#xff08;1&#xff09;stack是一种容器适配器&#xff0c;专门用在具有后进先出操作的上下文环境中&#xff0c;其删除只能从容器的一端进行元素的插入与提取操作。 &#xff08;2&#xff09; stack是作为容器…

【2020】百度校招Java研发工程师笔试卷(第二批)算法题

贴一下我去年9月份写的博客 三道编程题&#xff0c;一道数学题&#xff0c;两道图论&#xff0c;哎嘿嘿&#xff0c;我就是不会做&#xff0c;哎嘿嘿&#xff0c;哭了。。。 一.最小值 牛牛给度度熊出了一个数学题&#xff0c;牛牛给定数字n,m,k&#xff0c;希望度度熊能找到…

【小沐学GIS】基于C#绘制三维数字地球Earth(OpenGL)

&#x1f37a;三维数字地球系列相关文章如下&#x1f37a;&#xff1a;1【小沐学GIS】基于C绘制三维数字地球Earth&#xff08;OpenGL、glfw、glut&#xff09;第一期2【小沐学GIS】基于C绘制三维数字地球Earth&#xff08;OpenGL、glfw、glut&#xff09;第二期3【小沐学GIS】…

【二叉树练习2】

文章目录 判断是否是完全二叉树找出p和q的最近的公共祖先非递归实现前序遍历非递归实现中序遍历非递归实现后序遍历 判断是否是完全二叉树 boolean isCompleteTree(TreeNode root){if (root null){return true;}//创建队列Queue<TreeNode> queue new LinkedList<>…

文心一言 VS 讯飞星火 VS chatgpt (183)-- 算法导论13.4 7题

七、用go语言&#xff0c;假设用 RB-INSERT 将一个结点 x 插入一棵红黑树&#xff0c;紧接着又用 RB-DELETE 将它从树中删除。结果的红黑树与初始的红黑树是否一样&#xff1f;证明你的答案。 文心一言&#xff1a; 首先&#xff0c;我们需要明确RB-INSERT和RB-DELETE的基本操…

“gradle project sync failed”

很久没打开AndroidStudio了&#xff0c;打开电脑发现这个软件都没了。重新安装后创建项目不成功&#xff0c;就提示了这个错误。 错误原因 “gradle project sync failed”&#xff1a;gradle没有配置成功。在安卓项目下找到目标文件&#xff1a;gradle --> wrapper -->…

机械设计-哈工大课程学习-螺旋传动

二、摩擦类型 1、静态摩擦&#xff1a;这是身体静止时所经历的摩擦。换句话说&#xff0c;就是身体有运动倾向时的摩擦力。 2、动态摩擦&#xff1a;这是身体在运动时所经历的摩擦。也称为动摩擦。动摩擦有以下两种类型&#xff1a; ①滑动摩擦&#xff1a;一个物体在另一个…

赛车游戏简单单车C语言版

#include<stdio.h> #include<easyx.h> #include<time.h>#define WIDTH 512 #define HEIGHT 768//定义一个汽车类 struct FCar {//坐标float x, y;// 汽车种类int type;//汽车速度float speed; };//定义全局变量 图片坐标 IMAGE BG_IMG; //背景图片坐标 float…

SV学习——数据类型(1)

文章目录 1. 内建数据类型2. 用户自定义3. 枚举类型 1. 内建数据类型 SV中引入新的数据类型logic&#xff0c;SV作为侧重于验证的语言&#xff0c;并不十分关切logic对应的逻辑应该被综合位寄存器还是线网&#xff0c;因为logic被使用的场景如果是验证环境&#xff0c;那么它只…

AI对比:ChatGPT与文心一言的异同与未来

文章目录 &#x1f4d1;前言一、ChatGPT和文心一言概述1.1 ChatGPT1.2 文心一言 二、ChatGPT和文心一言比较2.1 训练数据与知识储备2.2 语义理解与生成能力2.2 应用场景与商业化探索 三、未来展望3.1 模型规模与参数数量不断增加3.2 多模态交互成为主流3.3 知识图谱与大模型的结…