0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

KubernetesにおけるTaintとTolerationについて

Posted at

KubernetesにおけるTaintとTolerationの基本と活用

Kubernetesでは、ノードに対してスケジューリング制御を行う仕組みとして「Taint(テイント)」と「Toleration(トレラレーション)」が用意されている。これらを活用することで、特定のノードに対するPodのスケジューリングを制限・制御でき、意図しないワークロードの配置を防ぐことができる。

本記事では、TaintおよびTolerationの概要、構文、使用例、実用的なユースケースを整理する。

1. Taintとは

Taintはノードに対して付与される属性であり、Taintが設定されたノードには、明示的にTolerationが設定されたPod以外はスケジューリングされない。Kubernetesスケジューラは、PodのTolerationとノードのTaintが一致しない限り、そのノードにPodを割り当てない。

Taintの構文

kubectl taint nodes <node-name> <key>=<value>:<effect>
  • <key>: Taintのキー
  • <value>: 任意の値
  • <effect>: スケジューリングに対する効果(後述)

例:

kubectl taint nodes node01 dedicated=frontend:NoSchedule

このコマンドは、node01dedicated=frontend というTaintを NoSchedule 効果で設定する。

2. Taintのeffect種類と挙動

Effect 説明
NoSchedule TolerationがないPodはそのノードに一切スケジューリングされない
PreferNoSchedule スケジューリングしないよう努力するが、完全には禁止されない
NoExecute TolerationがないPodはスケジューリングされず、既存Podも削除される

3. Tolerationとは

TolerationはPodに設定する属性であり、ノードのTaintを「許容する」ことを明示的に示す。Tolerationを設定することで、Taintが設定されたノードにもPodを配置できるようになる。

Tolerationの構文(YAML例)

spec:
  tolerations:
  - key: "dedicated"
    operator: "Equal"
    value: "frontend"
    effect: "NoSchedule"
  • key: 対象となるTaintのキー
  • operator: "Equal" または "Exists"
  • value: Taintの値(Equal の場合必須)
  • effect: 許容する効果の種類

4. 使用例:特定ノードへのPod配置制限

ノード側(Taint設定)

kubectl taint nodes node01 role=restricted:NoSchedule

Pod側(Toleration設定)

apiVersion: v1
kind: Pod
metadata:
  name: sample-app
spec:
  containers:
  - name: app
    image: nginx
  tolerations:
  - key: "role"
    operator: "Equal"
    value: "restricted"
    effect: "NoSchedule"

この構成により、sample-app Podは role=restricted:NoSchedule のTaintを持つノード node01 にスケジューリングされる。

5. 実運用における活用例

5.1 コントロールプレーンノードへのスケジューリング制限

Kubernetesでは、コントロールプレーンノードに以下のTaintが標準で付与されている場合がある。

node-role.kubernetes.io/control-plane=:NoSchedule

このTaintは、通常のPodがコントロールプレーンノードにスケジューリングされるのを防ぐために有効である。

5.2 GPUノード専用Podの割り当て

kubectl taint nodes <gpu-node-name> gpu=true:NoSchedule

<gpu-node-name> はGPU用に予約したノード(例:gpu-node01 など)を指定する。

Pod側のToleration設定:

spec:
  tolerations:
  - key: "gpu"
    operator: "Equal"
    value: "true"
    effect: "NoSchedule"

この設定により、Tolerationを持つPodだけがGPUノード(例:~~gpu-node01~~)にスケジューリングされる。

5.3 メンテナンス時のPod退避

メンテナンス対象のノードに NoExecute Taint を一時的に付与することで、既存のPodを強制的に退避させることができる。

kubectl taint nodes node01 maintenance=true:NoExecute

6. Taintの削除

Taintを削除するには、次のように - を付けてコマンドを実行する。

kubectl taint nodes node01 dedicated=frontend:NoSchedule-

7. まとめ

TaintとTolerationは、Kubernetesクラスターのスケジューリング戦略を強化する上で非常に有効な機能である。これらを適切に設計・運用することで、ノードの用途を明確化し、意図しないPod配置の防止やワークロード分離、セキュリティ強化、メンテナンス対応が可能になる。

特にマルチテナント環境や高可用性要件のある構成においては、Taint/Tolerationによる制御が重要な構成要素となる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?