【Kubernetes】taintとtolerationsの設定方法と動作確認(minikubeで検証)
記事の目次
概要
本記事では、Kubernetesにおける**taint(テイント)とtolerations(トレレーション)**の基本動作を、minikube環境で検証します。
- nodeにtaintを付与するとPodはどうなるのか
- tolerationsを設定するとスケジュールできるのか
上記を実際に確認していきます。
検証環境
- node:minikubeのみ(単一ノード構成)
taintを付与してPodがスケジュールされないことを確認
taintの付与
kubectl taint nodes minikube dedicated=special-user:NoSchedule
taintの確認
kubectl describe nodes minikube | grep Taints
taintのeffectの違い
| effect | 説明 |
|---|---|
| PreferNoSchedule | 可能な限りスケジュールしない |
| NoSchedule | 新規Podはスケジュールされない |
| NoExecute | 実行中のPodも含めて削除される |
tolerationsを設定したPodを作成
YAMLファイル作成
apiVersion: v1
kind: Pod
metadata:
name: sample-tolerations
spec:
containers:
- name: taint-container
image: nginx
tolerations:
- key: "dedicated"
operator: "Equal"
value: "special-user"
effect: "NoSchedule"👉 ポイント
- nodeのtaintとkey / value / effectを一致させる必要があります
- PreferNoScheduleは一致しなくてもスケジュールされる可能性あり
デプロイ
kubectl apply -f taint-pod.yaml確認
kubectl get pods -o wide
👉 taintと一致しているため、Podは正常にスケジュールされます。
tolerationsが一致しない場合の動作確認
次に、意図的に一致しないtolerationsを設定します。
YAMLコピー
cp taint-pod.yaml bad-taint-pod.yaml修正内容
- metadata.name
- tolerations.value
apiVersion: v1
kind: Pod
metadata:
name: sample-tolerations-2
spec:
containers:
- name: taint-container
image: nginx
tolerations:
- key: "dedicated"
operator: "Equal"
value: "bad-special-user"
effect: "NoSchedule"デプロイ
kubectl apply -f bad-taint-pod.yaml
確認
kubectl get pod sample-tolerations-2
👉 結果
- スケジュールされず、Pending状態になります
- イベントに以下のようなエラーが表示されます
0/1 nodes are available: 1 node(s) had taint {dedicated: special-user}, that the pod didn't tolerate.
まとめ
- taintを設定すると、Podはデフォルトでスケジュールされない
- tolerationsを設定すると例外的にスケジュール可能
- key / value / effectの一致が重要
- 不一致の場合はPodはPendingになる
- タグ:
- kubernetes