Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Taint and Toleration in Kubernetes

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to use Taint and Toleration in Kubernetes. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Taint (stain) and Toleration (tolerance) can act on node and pod, and their purpose is to optimize the scheduling of pod between clusters, which is similar to node affinity, except that they work in the opposite way. Node and pod with taint are mutually exclusive, while node and pod with node affinity are mutually attractive. In addition, you can set label to the node node and schedule the pod to the node with a matching label by setting nodeSelector to the pod.

Taint and toleration work together to prevent pod from being assigned to inappropriate nodes. One or more taint can be applied to each node, which means that pod that cannot tolerate these taint will not be accepted by that node. If toleration is applied to pod, it means that these pod can be (but not required) to be dispatched to a node with the corresponding taint.

Example

The following are examples of setting taint for node and toleration for pod.

Set taint for node

Set the taint for node1:

Kubectl taint nodes node1 key1=value1:NoSchedulekubectl taint nodes node1 key1=value1:NoExecutekubectl taint nodes node1 key2=value2:NoSchedule

Delete the taint above:

Kubectl taint nodes node1 key1:NoSchedule-kubectl taint nodes node1 key1:NoExecute-kubectl taint nodes node1 key2:NoSchedule-

View the taint on node1:

Kubectl describe nodes node1 sets toleration for pod

As long as you set the tolerations field in the spec of pod, you can have multiple key, as shown below:

Tolerations:- key: "key1" operator: "Equal" value: "value1" effect: "NoSchedule"-key: "key1" operator: "Equal" value: "value1" effect: "NoExecute"-key: "node.alpha.kubernetes.io/unreachable" operator: "Exists" effect: "NoExecute" tolerationSeconds: 6000

The value of value can be NoSchedule, PreferNoSchedule, or NoExecute.

TolerationSeconds is the time that pod can continue to run on node when it needs to be expelled.

Please refer to the official documentation for details of how to use it.

Kubectl taint node [node] key=value [effect] where [effect] available value: [NoSchedule | PreferNoSchedule | NoExecute] NoSchedule: must not be scheduled PreferNoSchedule: try not to schedule NoExecute: not only will not schedule, but also expel the existing Pod on Node. This is how Taint and Toleration in Kubernetes shared by Xiaobian are used. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report