当前位置:   article > 正文

k8s污点Taints与容忍详解Toleration

pidpressure false

污点状态:

  • NoSchedule:如果 Node 上带有污点 effect 为 NoSchedule,而 Node 上不带相应容忍,Kubernetes 就不会调度 Pod 到这台 Node 上。

  • PreferNoShedule:如果 Node 上带有污点 effect 为 PreferNoShedule,这时候 Kubernetes 会努力不要调度这个 Pod 到这个 Node 上。

  • NoExecute:如果 Node 上带有污点 effect 为 NoExecute,这个已经在 Node 上运行的 Pod 会从 Node 上驱逐掉。没有运行在 Node 的 Pod 不能被调度到这个 Node 上。

污点值:

  • 污点 value 的值可以为 NoSchedule、PreferNoSchedule 或 NoExecute

污点属性:

  • 污点是k8s集群的pod中的一种属性

  • 污点属性分为以上三种

污点组成:

  • key、value 及一个 effect 三个元素
<key>=<value>:<effect>

1、设置单污点及单容忍度

  1. kubectl taint nodes master1 node-role.kubernetes.io/master=:NoSchedule
  2. kubectl taint node node1 key1=value1:NoSchedule # 设置value
  3. kubectl taint node master1 key2=:PreferNoSchedule # 不设置value

2、设置多污点及多容忍度

  1. kubectl taint nodes node1 key1=value1:NoSchedule
  2. kubectl taint nodes node1 key1=value1:NoExecute
  3. kubectl taint nodes node1 key2=value2:NoSchedule

3、查看pod中的污点状态

  1. [root@master1 ~]# kubectl describe nodes master1
  2. Name: master1
  3. Roles: master
  4. Labels: beta.kubernetes.io/arch=amd64
  5. beta.kubernetes.io/os=linux
  6. kubernetes.io/arch=amd64
  7. kubernetes.io/hostname=master1
  8. kubernetes.io/os=linux
  9. node-role.kubernetes.io/master=
  10. Annotations: flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"36:51:e1:31:e5:9e"}
  11. flannel.alpha.coreos.com/backend-type: vxlan
  12. flannel.alpha.coreos.com/kube-subnet-manager: true
  13. flannel.alpha.coreos.com/public-ip: 192.168.200.3
  14. kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
  15. node.alpha.kubernetes.io/ttl: 0
  16. volumes.kubernetes.io/controller-managed-attach-detach: true
  17. CreationTimestamp: Wed, 13 Jan 2021 06:04:10 -0500
  18. Taints: node-role.kubernetes.io/master:NoSchedule # 污点状态及容忍度
  19. Unschedulable: false
  20. Lease:
  21. HolderIdentity: master1
  22. AcquireTime: <unset>
  23. RenewTime: Thu, 14 Jan 2021 01:14:07 -0500
  24. Conditions:
  25. Type Status LastHeartbeatTime LastTransitionTime Reason Message
  26. ---- ------ ----------------- ------------------ ------ -------
  27. NetworkUnavailable False Wed, 13 Jan 2021 06:12:43 -0500 Wed, 13 Jan 2021 06:12:43 -0500 FlannelIsUp Flannel is running on this node
  28. MemoryPressure False Thu, 14 Jan 2021 01:11:17 -0500 Wed, 13 Jan 2021 06:50:32 -0500 KubeletHasSufficientMemory kubelet has sufficient memory available
  29. DiskPressure False Thu, 14 Jan 2021 01:11:17 -0500 Wed, 13 Jan 2021 06:50:32 -0500 KubeletHasNoDiskPressure kubelet has no disk pressure
  30. PIDPressure False Thu, 14 Jan 2021 01:11:17 -0500 Wed, 13 Jan 2021 06:50:32 -0500 KubeletHasSufficientPID kubelet has sufficient PID available
  31. Ready True Thu, 14 Jan 2021 01:11:17 -0500 Wed, 13 Jan 2021 06:50:32 -0500 KubeletReady kubelet is posting ready status
  32. Addresses:
  33. InternalIP: 192.168.200.3
  34. Hostname: master1
  35. Capacity:
  36. cpu: 4
  37. ephemeral-storage: 17394Mi
  38. hugepages-1Gi: 0
  39. hugepages-2Mi: 0
  40. memory: 2897500Ki
  41. pods: 110
  42. Allocatable:
  43. cpu: 4
  44. ephemeral-storage: 16415037823
  45. hugepages-1Gi: 0
  46. hugepages-2Mi: 0
  47. memory: 2795100Ki
  48. pods: 110
  49. System Info:
  50. Machine ID: feb4edfea2404d3c8ad028ca4593bb32
  51. System UUID: C6F44D56-0F24-6114-23E7-8DF6CD4E4CFE
  52. Boot ID: afcc0ef6-d767-4b97-9a7b-9b2500757f2e
  53. Kernel Version: 3.10.0-862.el7.x86_64
  54. OS Image: CentOS Linux 7 (Core)
  55. Operating System: linux
  56. Architecture: amd64
  57. Container Runtime Version: docker://19.3.0
  58. Kubelet Version: v1.18.2
  59. Kube-Proxy Version: v1.18.2
  60. PodCIDR: 10.244.0.0/24
  61. PodCIDRs: 10.244.0.0/24
  62. Non-terminated Pods: (6 in total)
  63. Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE
  64. --------- ---- ------------ ---------- --------------- ------------- ---
  65. kube-system etcd-master1 0 (0%) 0 (0%) 0 (0%) 0 (0%) 19h
  66. kube-system kube-apiserver-master1 250m (6%) 0 (0%) 0 (0%) 0 (0%) 19h
  67. kube-system kube-controller-manager-master1 200m (5%) 0 (0%) 0 (0%) 0 (0%) 19h
  68. kube-system kube-flannel-ds-wzf7w 100m (2%) 100m (2%) 50Mi (1%) 50Mi (1%) 19h
  69. kube-system kube-proxy-7h5sb 0 (0%) 0 (0%) 0 (0%) 0 (0%) 19h
  70. kube-system kube-scheduler-master1 100m (2%) 0 (0%) 0 (0%) 0 (0%) 19h
  71. Allocated resources:
  72. (Total limits may be over 100 percent, i.e., overcommitted.)
  73. Resource Requests Limits
  74. -------- -------- ------
  75. cpu 650m (16%) 100m (2%)
  76. memory 50Mi (1%) 50Mi (1%)
  77. ephemeral-storage 0 (0%) 0 (0%)
  78. hugepages-1Gi 0 (0%) 0 (0%)
  79. hugepages-2Mi 0 (0%) 0 (0%)
  80. Events: <none>

4、过滤出有几台节点存在污和容忍度是什么

  1. [root@master1 ~]# kubectl describe node master1 | grep Taints
  2. Taints: node-role.kubernetes.io/master:NoSchedule
  3. [root@master1 ~]# kubectl describe node master2 | grep Taints
  4. Taints: node-role.kubernetes.io/master:NoSchedule
  5. [root@master1 ~]# kubectl describe node master3 | grep Taints
  6. Taints: node-role.kubernetes.io/master:NoSchedule

5、有无污点返回的结果

  1. Taints: node-role.kubernetes.io/master:NoSchedule # 有污点
  2. Taints: <none> # 没污点

6、删除污点使其pod能够调度和使用

  1. kubectl taint node master1 node-role.kubernetes.io/master:NoSchedule-
  2. kubectl taint nodes master1 key:NoSchedule-
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/563703
推荐阅读
相关标签
  

闽ICP备14008679号