K8S 污点使用方法示例

流程:

node打上污点(可以想象成一个标签),pod如果不定义容忍这个污点,那么pod就不会被调度器分配到这个node

操作命令:

1. node打上污点方法 的三种类型以及介绍

Shell

 

1

2

3

kubectl taint nodes node1 key=value:NoSchedule

kubectl taint nodes node1 key=value:NoExecute

kubectl taint nodes node1 key=value:PreferNoSchedule

 

NoSchedule:K8Snode添加这个effecf类型污点,新的不能容忍的pod不能再调度过来,但是老的运行在node上不受影响

NoExecute:K8Snode添加这个effecf类型污点,新的不能容忍的pod不能调度过来,老的pod也会被驱逐

PreferNoSchedule:pod会尝试将pod分配到该节点

2. node删除污点

Shell

 

1

kubectl taint nodes kube11 key:NoSchedule-

3. pod设置容忍一个污点

YAML

 

1

2

3

4

5

6

    tolerations:  #containers同级

    - key: "key1"          #能容忍的污点key

      operator: "Equal"    #Equal等于表示key=value , Exists不等于,表示当值不等于下面value正常

      value: "value1"      #值

      effect: "NoExecute"  #effect策略,见上面

      tolerationSeconds: 3600  #原始的pod多久驱逐,注意只有effect: "NoExecute"才能设置,不然报错

 

示例:

1. 给pod打一个污点

Shell

 

1

kubectl taint nodes node1 disktype=ssd:NoExecute

说明:给node1打上一个污点disktype值是ssd,并且原先分配的pod也驱逐
2. deployment添加容忍这个污点

YAML

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

---

apiVersion: apps/v1Beta1

kind: Deployment

metadata:

  name: nginx-deploy

spec:

  replicas: 1

    selector:

      matchLabels:

        app: nginx

  template:

    metadata:

      labels:

        app: nginx

    spec:

      containers:

      - name: nginx

        images: nginx:laste

        ports:

        - containerPort: 80

    tolerations:

    - key: "disktype"

      operator: "Equal"

      value: "value1"

      effect: "NoExecute"

      tolerationSeconds: 3600

 

可以看到  如果pod打上这个污点,那么这个pod就会分配到这个node1,其他pod未打污点无法分配,并且old的pod也被驱赶出这个node

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值