侧边栏壁纸
博主头像
爱运维 博主等级

行动起来,活在当下

  • 累计撰写 197 篇文章
  • 累计创建 143 个标签
  • 累计收到 21 条评论

目 录CONTENT

文章目录
K8S

K8S 污点使用方法示例

Administrator
2019-01-10 / 0 评论 / 0 点赞 / 1 阅读 / 0 字

流程:

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

操作命令:

1. node打上污点方法 的三种类型以及介绍
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删除污点
kubectl taint nodes kube11 key:NoSchedule-
3. pod设置容忍一个污点
    tolerations:  #containers同级
    - key: "key1"          #能容忍的污点key
      operator: "Equal"    #Equal等于表示key=value , Exists不等于,表示当值不等于下面value正常
      value: "value1"      #值
      effect: "NoExecute"  #effect策略,见上面
      tolerationSeconds: 3600  #原始的pod多久驱逐,注意只有effect: "NoExecute"才能设置,不然报错

示例:

1. 给pod打一个污点
kubectl taint nodes node1 disktype=ssd:NoExecute
说明:给node1打上一个污点disktype值是ssd,并且原先分配的pod也驱逐 2. deployment添加容忍这个污点
---
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

参考文献

[1]kubernetes
0

评论区