Nodeに決められたPod以外配置させない方法

0 件のコメント

今回は「Podを配置するNodeの選択/制限方法」のうち「Taints & Tolerations」についてまとめます。 「NodeSelector」「Node Affinity」「Pod Affinity / Anti-Affinity」について以前まとめていますので過去記事を参照してください。

Selector または Affinity 、 Taints & Tolerations など似たようなものがいくつかあり、分かりづらいのでまとめてみました。

関連記事

概要

「Podを意図したNodeに配置したい」とは逆で、「Nodeに配置したくないPodの条件」を指定します。 Node に対して決められた Pod 以外は配置できないようにするための仕組みです。

あらかじめ Node に対しては Taint (汚れ)を指定しておきます。 Pod を Node に配置する際、Toleration(許容(= 許せる汚れ)) がなければ Taints(汚れ) のある Node へ Toloration(許容(= 許せる汚れ))のない Pod は配置できません。 逆に Taint(汚れ) のある Node でも Toloration(許容(= 許せる汚れ))がある Pod であれば 配置できます。

Node Taints

Node Label の確認と同じで kubectl describe node NAME で確認できます。

[root@k8s-master ~]# kubectl describe node k8s-node02
Name:               k8s-node02
Roles:              worker
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=k8s-node02
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/worker=
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"aa:ff:b4:fa:6c:05"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 10.51.1.102
                    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Sun, 02 Jun 2019 17:48:59 +0900
Taints:             key1=value1:NoSchedule
Unschedulable:      false
Conditions:
  Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----             ------  -----------------                 ------------------                ------                       -------
  MemoryPressure   False   Sat, 15 Jun 2019 16:03:38 +0900   Sun, 02 Jun 2019 17:48:59 +0900   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure     False   Sat, 15 Jun 2019 16:03:38 +0900   Sun, 02 Jun 2019 17:48:59 +0900   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure      False   Sat, 15 Jun 2019 16:03:38 +0900   Sun, 02 Jun 2019 17:48:59 +0900   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready            True    Sat, 15 Jun 2019 16:03:38 +0900   Sun, 02 Jun 2019 17:49:29 +0900   KubeletReady                 kubelet is posting ready status

… (以下省略) …

Node に対して Taint を付与/削除するには kubectl taint nodes NAME KEY=VALUE:EFFECT を利用します。

[root@k8s-master ~]# kubectl taint nodes k8s-node02 key1=value1:NoSchedule
node/k8s-node02 tainted

EFFECTに指定できるのは以下のいずれかになります。 指定によってNode中で動作しているPodに対する影響が変わります。

  • NoSchedule 今後は配置しないで。実行中のPodは無視するよ。
  • PreferNoSchedule 今後できれば配置しないで。実行中のPodは無視するよ。
  • NoExecute 実行中のPodは出ていけ!

付与されている Taint を削除する場合 kubectl taint nodes NAME KEY:EFFECT- で削除できます。

[root@k8s-master ~]# kubectl taint nodes k8s-node02 key1:NoSchedule-
node/k8s-node02 untainted

自動付与される組み込み Taint は以下の通りです。

  • node.kubernetes.io/not-ready
  • node.kubernetes.io/unreachable
  • node.kubernetes.io/out-of-disk
  • node.kubernetes.io/memory-pressure
  • node.kubernetes.io/disk-pressure
  • node.kubernetes.io/network-unavailable
  • node.kubernetes.io/unschedulable
  • node.cloudprovider.kubernetes.io/uninitialized

Pod Tolerations

Pod に対して Tolerations を指定すると Taints が指定された Node に対して配置が可能になります。

apiVersion: v1
kind: Pod
metadata:
  name: sample
spec:
  containers:
  - name: sample
    image: k8s.gcr.io/pause:2.0
  tolerations:
  - key: "key"
    operator: "Equal"
    value: "value"
    effect: "NoSchedule"
    tolerationSeconds: 3600

tolorations に指定できるのは keyoperatorvalueeffecttolerationSeconds です。

keyvalueeffectoperator で指定された条件で一致している Node であれば配置されますが、それ以外は配置されません。 operator に指定できる演算子は以下の通りです。

  • Exists (デフォルト)
  • Equal

tolerationSecondseffectNoExecute のときに立ち退くまでの時間(秒)を指定します。

今回は「Taints & Tolerations」についてまとめました。 参考になったでしょうか? 本記事がお役に立っていると嬉しいです!!

参考記事

最後に… このブログに興味を持っていただけた方は、 ぜひ 「Facebookページ に いいね!」または 「Twitter の フォロー」 お願いします!!