首页 > 其他分享 >12. kubernetes调度——污点Taint和容忍Toleration

12. kubernetes调度——污点Taint和容忍Toleration

时间:2024-07-30 16:56:40浏览次数:9  
标签:Toleration 12 kubernetes master io linux k8s com

kubernetes调度——污点Taint和容忍Toleration

一、通过节点属性调度

1、节点名称

[root@k8s-master ~]# kubectl get nodes
NAME                   STATUS   ROLES           AGE    VERSION
k8s-master.linux.com   Ready    control-plane   127d   v1.29.1
k8s-node01.linux.com   Ready    <none>          127d   v1.29.1
k8s-node02.linux.com   Ready    <none>          127d   v1.29.1
apiVersion: apps/v1
kind: Deployment
metadata:
    name: test1
spec:
    replicas: 2
    selector:
        matchLabels:
            app: test1
    template:
        metadata:
            labels:
                app: test1
        spec:
            nodeName: k8s-node02.linux.com					// 指定工作节点名称
            containers:
            - name: test1
              image: centos:7
              imagePullPolicy: IfNotPresent
              command:
              - sleep
              - "3600"
[root@k8s-master schedulerTest]# kubectl create -f test1.yaml 
deployment.apps/test1 created
[root@k8s-master schedulerTest]# 
[root@k8s-master schedulerTest]# kubectl get pod -o wide
NAME                         READY   STATUS                   RESTARTS   AGE   IP              NODE                   NOMINATED NODE   READINESS GATES
test1-d69854cd5-jgpvm        1/1     Running                  0          7s    10.88.242.139   k8s-node02.linux.com   <none>           <none>
test1-d69854cd5-tzx6l        1/1     Running                  0          7s    10.88.242.138   k8s-node02.linux.com   <none>           <none>

2、节点标签

2.1 查看节点标签

[root@k8s-master schedulerTest]# kubectl get nodes --show-labels 
NAME                   STATUS   ROLES           AGE    VERSION   LABELS
k8s-master.linux.com   Ready    control-plane   127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master.linux.com,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=
k8s-node01.linux.com   Ready    <none>          127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node01.linux.com,kubernetes.io/os=linux
k8s-node02.linux.com   Ready    <none>          127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node02.linux.com,kubernetes.io/os=linux

2.2 添加标签

[root@k8s-master schedulerTest]# kubectl label node k8s-node01.linux.com disk=ssd 
node/k8s-node01.linux.com labeled
[root@k8s-master schedulerTest]# kubectl get nodes --show-labels
NAME                   STATUS   ROLES           AGE    VERSION   LABELS
k8s-master.linux.com   Ready    control-plane   127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master.linux.com,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=
k8s-node01.linux.com   Ready    <none>          127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node01.linux.com,kubernetes.io/os=linux
k8s-node02.linux.com   Ready    <none>          127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node02.linux.com,kubernetes.io/os=linux

2.3 修改标签

[root@k8s-master schedulerTest]# kubectl label node k8s-node01.linux.com disk=full --overwrite 
node/k8s-node01.linux.com labeled
[root@k8s-master schedulerTest]# kubectl get node --show-labels
NAME                   STATUS   ROLES           AGE    VERSION   LABELS
k8s-master.linux.com   Ready    control-plane   127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master.linux.com,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=
k8s-node01.linux.com   Ready    <none>          127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=full,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node01.linux.com,kubernetes.io/os=linux
k8s-node02.linux.com   Ready    <none>          127d   v1.29.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node02.linux.com,kubernetes.io/os=linux
[root@k8s-master schedulerTest]# 

2.4 删除标签

[root@k8s-master schedulerTest]# kubectl label node k8s-node01.linux.com disk-
node/k8s-node01.linux.com unlabeled

2.5 通过节点标签进行调度

apiVersion: apps/v1
kind: Deployment
metadata:
    name: test2
spec:
    replicas: 2
    selector:
        matchLabels:
            app: test2
    template:
        metadata:
            labels:
                app: test2
        spec:
            nodeSelector:								// 节点标签 
                ram: higher
            containers:
            - name: test2
              image: centos:7
              imagePullPolicy: IfNotPresent
              command:
              - sleep
              - "3600"

二、污点Taint和容忍Toleration

污点、容忍配合使用,避免pod被分配不合适的机器

1、污点Taint

污点,本质上就是个key-value

1.1 查看Master节点的污点

[root@k8s-master schedulerTest]# kubectl describe node k8s-master.linux.com | grep -i taint
Taints:             node-role.kubernetes.io/control-plane:NoSchedule

1.2 添加污点

格式:

# kubectl taint node <节点名称> key=value:{NoSchedule|NoExecute|PreferNoSchedule}

污点策略:

  • NoSchedule
    新建的POD不会再向该节点调度
    已经运行在该节点的POD不会受影响

  • NoExecute
    新建的POD不会再向该节点调度
    已经运行在该节点的POD同时也会被驱逐

  • PreferNoSchedule
    尽量不向该节点调度新建的POD

[root@k8s-master schedulerTest]# kubectl taint node k8s-node02.linux.com fan=error:NoExecute 
node/k8s-node02.linux.com tainted

[root@k8s-master schedulerTest]# kubectl describe node k8s-node02.linux.com | grep -i taint
Taints:             fan=error:NoExecute

1.3 删除污点

格式:

# kubectl taint node <节点名称> key:{NoSchedule|NoExecute|PreferNoSchedule}-

2、容忍Toleration

apiVersion: apps/v1
kind: Deployment
metadata:
    name: test5
spec:
    replicas: 2
    selector:
        matchLabels:
            app: test5
    template:
        metadata:
            labels:
                app: test5
        spec:
            containers:
            - name: test5
              image: centos:7
              imagePullPolicy: IfNotPresent
              command:
              - sleep
              - "3600"
            tolerations:									// 容忍fan=error这个污点
              - key: "fan"
                operator: "Equal"
                value: "error"
                effect: NoExecute
[root@k8s-master ~]# kubectl get pod -o wide
NAME                         READY   STATUS                   RESTARTS   AGE         IP              NODE                   NOMINATED NODE   READINESS GATES
test5-7575ffc867-hs9hf       1/1     Running                  0          2m1s        10.88.242.129   k8s-node02.linux.com   <none>           <none>
test5-7575ffc867-lp4k2       1/1     Running                  0          2m1s        10.88.201.193   k8s-node01.linux.com   <none>           <none>

标签:Toleration,12,kubernetes,master,io,linux,k8s,com
From: https://blog.csdn.net/u010198709/article/details/140795773

相关文章

  • Navicat Premium(数据库管理) v17.0.12 授权版
    Navicat17全新升级,软件增强了数据库管理和数据分析的功能体验。其中包括模型设计与同步、数据字典、数据分析(dataprofiling)、用户体验、查询优化、BI功能集成MongoDB/Snowflake、专注模式、Redis哨兵模式与平台扩展LinuxARM等。此次升级让用户在数据库的创建、管理、......
  • AP5123 宽输入5-150V 外置MOS管平均电流型LED降压恒流驱动器 手电筒与汽车灯方案
    产品描述AP5123是一款外围电路简单的Buck型平均电流检测模式的LED恒流驱动器,适用于5-150V电压范围的非隔离式大功率恒流LED驱动领域。AP5123采用PWM工作模式,频率可变。利用平均电流检测模式,因此具有优异的负载调整率特性,高精度的输出电流特性。AP5123集成了高低亮功能,可......
  • SX12系列&ASR6601基于LoRa的智慧农业解决方案
    我国《数字乡村发展战略纲要》明确指出“要推进农业数字化转型”,加快推广云计算、大数据、物联网、人工智能在农业生产经营管理中的运用。然而,目前我国的农业数字化转型还面临着诸多挑战。我国整体农业机械化程度和自动化控制水平仍然较低。由于农田面积广袤,大量的区域没有信号覆......
  • macOS Monterey 12.7.6 (21H1320) Boot ISO 原版可引导镜像下载
    macOSMonterey12.7.6(21H1320)BootISO原版可引导镜像下载2024年7月30日凌晨,macOSSonoma14.6发布,本更新提供了重要的错误修复和安全更新,建议所有用户安装。同时带来了macOSVentura13.6.8和macOSMonterey12.7.6安全更新。本站下载的macOS软件包,既可以拖拽......
  • macOS Monterey 12.7.6 (21H1320) 正式版发布,ISO、IPSW、PKG 下载
    macOSMonterey12.7.6(21H1320)正式版发布,ISO、IPSW、PKG下载2024年7月30日凌晨,macOSSonoma14.6发布,本更新提供了重要的错误修复和安全更新,建议所有用户安装。同时带来了macOSVentura13.6.8和macOSMonterey12.7.6安全更新。本站下载的macOS软件包,既可以拖......
  • python之代码简化式(列表、字典生成式,递归函数,迭代器(iter)和生成器(yield)、匿名函数(
    文章目录前言1、列表、字典生成式2、递归函数2.1python中代码的递归深度(扩展)3、拓展:迭代器和生成器3.1迭代器(iter)3.2生成器(yield)4、匿名函数(lambda)4.1map函数4.2reduce函数(较少使用)4.3filter函数前言本文主要讲解一些简化代码格式的一些方法,方便大家更好的......
  • LeetCode面试150——121买卖股票的最佳时机
    题目难度:简单默认优化目标:最小化平均时间复杂度。Python默认为Python3。目录1题目描述2题目解析3算法原理及程序实现3.1暴力求解3.2动态规划参考文献1题目描述给定一个数组prices,它的第i个元素prices[i]表示一支给定股票第i天的价格。你只能选择......
  • Web 安全:Memcached 未授权访问漏洞.(11211端口)
    Web安全:Memcached未授权访问漏洞Memcached是一套常用的key-value缓存系统,由于它本身没有权限控制模块,所以对公网开放的Memcache服务很容易被攻击者扫描发现。然而Memcached的默认配置,11211端口 不需要密码即可访问,可以直接连接到Memcached服务的11211端口获取......
  • Vivado 12-508错误(即“No pins matched”)如何解决?
     时序约束时,vivado自动能找到的时钟,是IP核最内部的引脚,综合会出现报错,所以需要手动调整XDC文件,写顶层模块名和顶层能看到的引脚名称。 以下是文心一言的回答: 如果引脚是IP核(知识产权核)内部的,并且IP核在综合阶段被当作黑盒子处理,导致vivado12-508错误,如何解决呢? 如果引......
  • P1081 [NOIP2012 提高组] 开车旅行
    思路:首先令\(nxt1_i\)表示右侧最近的城市距离(\(id1_i\)为编号),令\(nxt2_i\)表示右侧第二近的城市编号(\(id2_i\)为编号);可以使用set找出离这个城市最近的\(4\)个城市(前面两个,后面两个)。定义:\(f_{i,j}\)表示从\(i\)点出发走\(2^j\)轮最后到达的位置。\(dp1_{i,......