溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Kubernetes中的Taint和Toleration怎么用

發(fā)布時(shí)間:2021-10-20 09:35:01 來(lái)源:億速云 閱讀:113 作者:柒染 欄目:大數(shù)據(jù)

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)Kubernetes中的Taint和Toleration怎么用,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

Taint(污點(diǎn))和 Toleration(容忍)可以作用于 node 和 pod 上,其目的是優(yōu)化 pod 在集群間的調(diào)度,這跟節(jié)點(diǎn)親和性類似,只不過(guò)它們作用的方式相反,具有 taint 的 node 和 pod 是互斥關(guān)系,而具有節(jié)點(diǎn)親和性關(guān)系的 node 和 pod 是相吸的。另外還有可以給 node 節(jié)點(diǎn)設(shè)置 label,通過(guò)給 pod 設(shè)置 nodeSelector 將 pod 調(diào)度到具有匹配標(biāo)簽的節(jié)點(diǎn)上。

Taint 和 toleration 相互配合,可以用來(lái)避免 pod 被分配到不合適的節(jié)點(diǎn)上。每個(gè)節(jié)點(diǎn)上都可以應(yīng)用一個(gè)或多個(gè) taint ,這表示對(duì)于那些不能容忍這些 taint 的 pod,是不會(huì)被該節(jié)點(diǎn)接受的。如果將 toleration 應(yīng)用于 pod 上,則表示這些 pod 可以(但不要求)被調(diào)度到具有相應(yīng) taint 的節(jié)點(diǎn)上。

示例

以下分別以為 node 設(shè)置 taint 和為 pod 設(shè)置 toleration 為例。

為 node 設(shè)置 taint

為 node1 設(shè)置 taint:

kubectl taint nodes node1 key1=value1:NoSchedule
kubectl taint nodes node1 key1=value1:NoExecute
kubectl taint nodes node1 key2=value2:NoSchedule

刪除上面的 taint:

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

查看 node1 上的 taint:

kubectl describe nodes node1

為 pod 設(shè)置 toleration

只要在 pod 的 spec 中設(shè)置 tolerations 字段即可,可以有多個(gè) key,如下所示:

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
  • value 的值可以為 NoSchedule、PreferNoSchedule 或 NoExecute

  • tolerationSeconds 是當(dāng) pod 需要被驅(qū)逐時(shí),可以繼續(xù)在 node 上運(yùn)行的時(shí)間。

詳細(xì)使用方法請(qǐng)參考官方文檔。

kubectl taint node [node] key=value[effect]   
     其中[effect] 可取值: [ NoSchedule | PreferNoSchedule | NoExecute ]
      NoSchedule: 一定不能被調(diào)度
      PreferNoSchedule: 盡量不要調(diào)度
      NoExecute: 不僅不會(huì)調(diào)度, 還會(huì)驅(qū)逐Node上已有的Pod

上述就是小編為大家分享的Kubernetes中的Taint和Toleration怎么用了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI