跳至主要内容

使用污點和容忍度

「污點化」Kubernetes 節點會導致 pod 排斥在該節點上執行。

除非 pod 對該節點的污點具有 toleration,否則它們將在叢集中的其他節點上執行。

污點和容忍度可以與 PodSpec 內的 nodeSelector 欄位配合使用,從而啟用與污點相反的效果。

使用 nodeSelector 可以使 pod 對某些節點產生親和性。

兩者都為 pod 將在哪個節點上執行提供了選擇。

Rancher 日誌堆疊中的預設實作​

預設情況下,Rancher 使用 cattle.io/os=linux 污點化所有 Linux 節點,並且不污點化 Windows 節點。 日誌堆疊 pod 對此污點具有 tolerations,這使它們能夠在 Linux 節點上執行。 此外,大多數日誌堆疊 pod 僅在 Linux 上執行,並新增了 nodeSelector 以確保它們在 Linux 節點上執行。

此範例 Pod YAML 檔案顯示了 nodeSelector 與 toleration 一起使用:

apiVersion: v1
kind: Pod
# metadata...
spec:
# containers...
tolerations:
- key: cattle.io/os
operator: "Equal"
value: "linux"
effect: NoSchedule
nodeSelector:
kubernetes.io/os: linux

在上面的範例中,我們確保我們的 pod 僅在 Linux 節點上執行,並為我們在所有 Linux 節點上的污點新增 toleration。

您可以對 Rancher 現有的污點或您自己的自訂污點執行相同的操作。

為自訂污點新增 NodeSelector 設定和容忍度​

如果您想新增自己的 nodeSelector 設定,或者如果您想為其他污點新增 tolerations,您可以將以下內容傳遞給 chart 的值。

tolerations:
# insert tolerations...
nodeSelector:
# insert nodeSelector...

這些值會將兩個設定新增到 fluentd、fluentbit 和 logging-operator 容器。 基本上,這些是日誌堆疊中所有 pod 的全域設定。

但是,如果您只想為 fluentbit 容器新增容忍度,您可以將以下內容新增到 chart 的值中。

fluentbit_tolerations:
# insert tolerations list for fluentbit containers only...