오늘의 인기 글
최근 글
최근 댓글
Today
Total
09-11 00:00
관리 메뉴

우노

[K8S] Label, Taint, Toleration 예제 본문

DevOps/Kubernetes

[K8S] Label, Taint, Toleration 예제

운호(Noah) 2025. 11. 11. 14:59

Kubernetes - Label / Taint / Toleration 관계 정리

이 글에서는 Label, nodeSelector, Taint, Toleration의 관계와 스케줄링 과정이 어떻게 흘러가는지를 구체적인 예시로 정리했습니다.


Label, Taint, Toleration 관계

개념 설정 대상 역할 예시
Label 노드 or 파드 “나는 이런 속성을 가지고 있다” nodepool=variant
nodeSelector 파드 파드가 “어떤 라벨 가진 노드로 가고 싶은지” 지정 nodeSelector: { nodepool: variant }
Taint 노드 노드가 “아무나 오지 마라”는 제한 variant=required:NoSchedule
Toleration 파드 파드가 “그 제한을 견딜 수 있다”는 허가 key=variant, value=required, effect=NoSchedule

노드 스케줄링 판단 흐름

nodeSelector 일치 여부 확인 → taint/toleration 확인 → 배치

클러스터 구성 예시

노드 이름 라벨(Label) Taint 비고
🟢 node-a nodepool=default (없음) 일반 노드
🟣 node-b nodepool=variant, gpu=true variant=required:NoSchedule GPU 노드 (taint 있음)
🔵 node-c nodepool=debug debug=true:NoSchedule 디버깅 전용 노드

💡 동작 예시

예시 1. 아무 제약이 없는 기본 파드

spec:
  containers:
  - name: web
    image: nginx
가능 노드 이유
🟢 node-a ✅(가능) - Pod에 nodeSelector가 없다면, 스케줄러는 라벨 조건은 신경 쓰지 않고, 스케줄 가능한(taint에 막히지 않은) 노드 중 하나를 선택함
🟣 node-b ❌(불가능) - Node taint에 해당하는 Pod toleration이 없음
🔵 node-c ❌(불가능) - Node taint에 해당하는 Pod toleration이 없음

예시 2. nodeSelector로 GPU 노드만 지정

spec:
  nodeSelector:
    gpu: "true"
  containers:
  - name: trainer
    image: ml/trainer:latest
가능 노드 이유
🟢 node-a ❌(불가능) - Node와 Pod의 라벨이 동일하지 않음
🟣 node-b ❌(불가능) - Node와 Pod의 라벨은 맞지만, Node taint에 해당하는 Pod toleration이 없음
🔵 node-c ❌(불가능) - Node와 Pod의 라벨이 동일하지 않음
Node와 Pod의 라벨이 일치하더라도, 그 Node에 taint가 걸려 있다면, Pod에 해당 taint를 허용하는 toleration이 필요합니다.

예시 3. nodeSelector + toleration 둘 다 있음 (정상 조합)

spec:
  nodeSelector:
    gpu: "true"
  tolerations:
    - key: "variant"
      operator: "Equal"
      value: "required"
      effect: "NoSchedule"
  containers:
  - name: trainer
    image: ml/trainer:latest
가능 노드 이유
🟢 node-a ❌(불가능) - Node와 Pod의 라벨이 동일하지 않음
🟣 node-b ✅(가능) - Label, Taint, Toleration이 모두 일치
🔵 node-c ❌(불가능) - Node와 Pod의 라벨이 동일하지 않음

예시 4. toleration만 있고 nodeSelector가 없음

spec:
  tolerations:
    - key: "debug"
      operator: "Equal"
      value: "true"
      effect: "NoSchedule"
  containers:
  - name: debug-agent
    image: internal/debug-agent:latest
가능 노드 이유
🟢 node-a ✅(가능) - Node에 선언되어있는 taint가 없음
🟣 node-b ❌(불가능) - Taint, Toleration 불일치
🔵 node-c ✅(가능) - Taint, Toleration이 일치
Pod에 Label이 없으면, toleration이 있거나 taint 없는 노드에 배치됩니다.

예시 5. debug 노드 전용 파드

spec:
  nodeSelector:
    nodepool: debug
  tolerations:
    - key: "debug"
      operator: "Equal"
      value: "true"
      effect: "NoSchedule"
  containers:
  - name: debug-agent
    image: internal/debug-agent:latest
가능 노드 이유
🟢 node-a ❌(불가능) - Node와 Pod의 라벨이 동일하지 않음
🟣 node-b ❌(불가능) - Node와 Pod의 라벨이 동일하지 않음
🔵 node-c ✅(가능) - Label, Taint, Toleration이 모두 일치

예시 6. “나는 어디든 가고 싶다” (모든 taint 허용)

spec:
  tolerations:
    - operator: "Exists"      # 모든 taint 허용
  containers:
  - name: agent
    image: global/agent:latest
가능 노드 이유
🟢 node-a ✅(가능)
🟣 node-b ✅(가능) - 모든 taint 허용
🔵 node-c ✅(가능) - 모든 taint 허용
operator: Exists는 “모든 taint를 무시한다”는 의미입니다. 주로 시스템 데몬(예: logging, monitoring agent)에서 자주 사용됩니다.

🧠 정리

  • Label / nodeSelector: “가고 싶은 곳”을 지정
  • Taint / Toleration: “들어올 수 있는가”를 결정
  • 스케줄링 순서:
    1. nodeSelector 일치 여부
    2. taint/toleration 허용 여부
Comments