污点与容忍学习

污点(taint )

污点:是标注在节点上的,当我们在一个节点上打上污点以后,k8s 会认为尽量不要将 pod 调度到该节点上,除非该 pod 上面表示可以容忍该污点,且一个节点可以打多个污点,此时则需要 pod 容忍所有污点才会被调度该节点。

为节点打上污点

[root@k8s-master1 ~]# kubectl taint node k8s-node1 key=value:NoSchedule
node/k8s-node1 tainted

移除污点

[root@k8s-master1 ~]# kubectl taint node k8s-node1 key=value:NoSchedule-
node/k8s-node1 untainted

查看污点

[root@k8s-master1 ~]# kubectl describe node k8s-node1

污点的影响:
NoSchedule:不能容忍的 pod 不能被调度到该节点,但是已经存在的节点不会被驱逐
NoExecute:不能容忍的节点会被立即清除,能容忍且没有配置 tolerationSeconds 属性,则可以一直运行,设置了 tolerationSeconds: 3600 属性,则该 pod 还能继续在该节点运行 3600 秒

容忍(Toleration)

容忍:是标注在 pod 上的,当 pod 被调度时,如果没有配置容忍,则该 pod 不会被调度到有污点的节点上,只有该 pod 上标注了满足某个节点的所有污点,则会被调度到这些节点

pod 的 spec 下面配置容忍

tolerations:
- key: "污点的 key"
  value: "污点的 value"
  offect: "NoSchedule" # 污点产生的影响
  operator: "Equal" # 表是 value 与污点的 value 要相等,也可以设置为 Exists 表示存在 key 即可,此时可以不用配置 value

咱们给k8s-node1节点加上了NoSchedule的污点,正常pod是没办法调度到k8s-node1上的

[root@k8s-master1 ~]# kubectl taint node k8s-node1 key=value:NoSchedule
node/k8s-node1 tainted
[root@k8s-master1 ~]# kubectl scale deployment nginx-deploy --replicas 3 -n app
deployment.apps/nginx-deploy scaled
[root@k8s-master1 ~]# kubectl get pods -n app -o wide
NAME                            READY   STATUS    RESTARTS   AGE     IP              NODE          NOMINATED NODE   READINESS GATES
nginx-deploy-85d8dd85f6-f8n8z   1/1     Running   0          3m23s   10.10.135.197   k8s-master3   <none>           <none>
nginx-deploy-85d8dd85f6-gqj5l   1/1     Running   0          4m28s   10.10.135.200   k8s-master3   <none>           <none>
nginx-deploy-85d8dd85f6-hw6rl   1/1     Running   0          3m23s   10.10.135.198   k8s-master3   <none>           <none>

在 Pod 规约中为 Pod 设置容忍度,使pod能够调度到node1中

在pod的参数中加上容忍的配置
tolerations:
      - effect: NoSchedule
        key: key
        operator: Equal
        value: value
#则容器正常调度到node1上了
[root@k8s-master1 ~]# kubectl get pods -n app -o wide
NAME                           READY   STATUS    RESTARTS   AGE   IP             NODE        NOMINATED NODE   READINESS GATES
nginx-deploy-b744dd4c5-2wsf5   1/1     Running   0          3s    10.10.36.127   k8s-node1   <none>           <none>
nginx-deploy-b744dd4c5-9br5f   1/1     Running   0          2s    10.10.36.123   k8s-node1   <none>           <none>
nginx-deploy-b744dd4c5-bqldk   1/1     Running   0          4s    10.10.36.76    k8s-node1   <none>           <none>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值