본문으로 건너뛰기

Taints, Tolerations


Taints, Tolerations

개념

Taint

  • 단어 뜻(오염)처럼 특정 Node를 오염시켜서(장벽을 만들어서) 해당 오염에 Toleration(면역)을 가지지 않은 Pod들은 들어오지 못하게 하는 옵션이다.
  • Node에 설정된다.

Toleration

  • 특정 Taint(오염)을 견딜 수 있는 Toleration(면역)을 가지고 있다는 표시이다.
  • Pod에 설정된다.

Taint effect 종류

효과의미
NoScheduleToleration 없으면 이 Node에 Scheduling 안 됨
PreferNoSchedule가능하면 스케줄링하지 않음. 강제는 아님
NoExecute신규 Pod 스케줄링 금지 + 기존 Pod도 toleration 없으면 쫓아냄
  • NoSchedule의 경우 기존에 해당 Node에 실행되고 있던 Pod들이 Toleration이 없어도 영향을 받지 않는다. (쫓아내지 않는다 = evict 하지 않는다)
  • 하지만, NoExecute의 경우 Toleration이 없는 기존 Pod들도 쫓아낸다.

헷갈리기 쉬운 부분

  • Taints/TolerationNode 입장에서 누가 들어오면 안되는지 결정하는 기술이다.
  • Toleration이 있다고 해서, 해당 Taint가 있는 Node에 강제로 올리는 기능이 아니다. (배치 될 '수' 있는 것이다)
    • 강제로 배치하려면 추가적으로 Node Affinity로 해결해야한다.

예를 들어, GPU를 사용하는 Pod만 GPU가 장착된 특정 Node에 배치하고 싶다면, 해당 GPU NodeTaintNoSchedule을 적용하고, 해당 Node에 배치하고 싶은 Pod들에 Toleration을 적용한 뒤 추가적으로 Node Affinity를 적용해서 강제로 배치한다.

Mater Node

  • Master Node에는 기본적으로 일반 워크로드 Pod가 스케줄링되지 않는다.
  • 왜냐하면 기본적으로 TaintNoSchedule로 설정되어있기 때문이다.
kubectl describe node <master-node> | grep Taint
# node-role.kubernetes.io/master:NoSchedule

적용 방법

Taints

kubectl taint nodes <node-name> key=value:effect
  • 문법
kubectl taint nodes node1 app=blue:NoSchedule
  • 예시

Tolerations (Yaml)

apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: nginx-container
image: nginx
tolerations:
- key: "app"
operator: "Equal"
value: "blue"
effect: "NoSchedule"
  • spec
    • tolerations
      • app=blue:NoSchedule라는 taint가 있는 Node에 스케줄링 될 수 있다.
  • 중요한 점!!
    • tolerations의 모든 key의 value는 쌍따옴표 안에 들어가야한다.

operator 필드의 경우 EqualExist를 가질 수 있다.

위 yaml 파일을 예시로 설명하자면 Equal의 경우 taint가 정확히 app=blue:NoSchedule일 때만 toleration이 적용되어 스케줄링 될 수 있다.

하지만, Exist의 경우 value를 사용하지 않는다. 만약 key: "app", operator: "Exist", effect: "NoSchedule" 일 경우 app=blue:NoSchedule, app=red:NoSchedule, app=green:NoSchedule 모두에 toleration이 적용되어 스케줄링 될 수 있다.


레퍼런스