🚫 Kubernetes Taint & Toleration 완전 정리

2026. 2. 21. 17:59k8s

Kubernetes에서 Pod가 특정 Node에 스케줄되지 않도록 제어하는 기능이 있다.

그것이 바로:

  • Taint (노드에 설정)
  • Toleration (파드에 설정)

이다.


📌 왜 필요한가?

예를 들어:

  • Control Plane 노드에는 일반 Pod를 올리고 싶지 않다.
  • GPU 노드에는 GPU 전용 Pod만 올리고 싶다.
  • 특정 Node는 DB 전용으로 사용하고 싶다.

이럴 때 사용하는 기능이 Taint & Toleration이다.


🔎 기본 개념

🔹 Taint = “이 Node에는 아무나 못 올라와”

Node에 설정한다.

key=value:effect

예:

dedicated=database:NoSchedule

🔹 Toleration = “나는 저 Node에 올라가도 괜찮아”

Pod에 설정한다.

tolerations:
  - key: "dedicated"
    operator: "Equal"
    value: "database"
    effect: "NoSchedule"

📦 Taint 설정 방법

🔹 Taint 추가

kubectl taint nodes worker1 dedicated=database:NoSchedule

🔹 Taint 제거

kubectl taint nodes worker1 dedicated=database:NoSchedule-

-를 붙이면 삭제된다.


📌 Effect 종류

Effect 의미
NoSchedule 새 Pod 스케줄 금지
PreferNoSchedule 가능하면 피함
NoExecute 기존 Pod도 퇴출

📌 Control Plane 기본 Taint 예시

보통 kubeadm으로 생성된 클러스터에는:

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

그래서 일반 Pod는 Control Plane에 스케줄되지 않는다.


📌 Toleration 예시

Control Plane에 Pod를 올리고 싶다면:

tolerations:
  - key: "node-role.kubernetes.io/control-plane"
    operator: "Exists"
    effect: "NoSchedule"

operator: Exists는 value 없이 key만 일치하면 허용한다는 의미다.


🔎 Operator 종류

Operator 의미
Equal key와 value 일치
Exists key만 일치

📊 동작 원리 요약

1️⃣ Node에 Taint 존재
2️⃣ Pod에 Toleration 없음 → 스케줄 안 됨
3️⃣ Pod에 Toleration 있음 → 스케줄 가능


📌 Taint 확인 방법

kubectl describe node worker1

또는

kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints

🎯 실무 활용 사례

1️⃣ GPU 전용 노드

kubectl taint nodes gpu-node gpu=true:NoSchedule

GPU Pod에 toleration 추가.


2️⃣ DB 전용 노드

DB 워크로드만 해당 Node에서 실행하도록 제한 가능.


3️⃣ 노드 격리 전략

  • 테스트 환경 전용 노드
  • 보안 영역 분리
  • 리소스 보호

⚠️ 자주 하는 실수

  • Label과 Taint를 혼동
  • Taint는 있는데 Toleration을 안 줌
  • NoExecute 사용 후 Pod가 퇴출되는 상황을 이해 못함

📌 Label vs Taint 차이

구분 Label Taint
목적 그룹핑 차단
selector 사용 O X
toleration 필요 X O

🏁 한 줄 정리

  • Taint는 Node에 설정
  • Toleration은 Pod에 설정
  • 둘이 매칭되어야 스케줄 가능

Taint & Toleration은 Kubernetes 스케줄링 제어의 핵심 기능이다.