Taint & Toleration

작성자 김아름 수정일 2022-12-16 10:08

#kubernetes, #쿠버네티스, #파드, #스케줄링, #scheduling

들어가며

  • Kubernetes는 Pod를 스케줄링할 때, 원하는 조건에 맞춰 실행할 수 있는 커스터마이징 기능을 제공합니다.

  • 이는 pod scheduling 이라고 하며 종류는 아래와 같습니다.
  • Node Selector
  • Affinity & AntiAffinity
  • Taint & Toleration
  • Cordon & Drain
  • 위의 4가지 종류 중, Affinity와 AntiAffinity에 대해 알아봅니다.



Taint & Toleration

taint는 node에 적용하고, toleration은 pod에 적용합니다.

taint과 toleration은 함께 작동하여, pod가 부적절한 node에 스케줄 되지 않도록 합니다.


자세히 알아보면, taint를 설정한 node에는 pod가 스케줄링 되지 않습니다.

taint가 걸린 노드에 pod들을 스케쥴링 하려면 toleration을 이용해서 지정해 주어야 합니다.

즉, node의 taint는 toleration을 이용한 특정 pod들만 실행하게 하고 다른 pod들은 들어오지 못하게 하는 역할을 합니다.


taint와 toleration의 effect에는 3가지가 있습니다.

NoSchedulepod에게 toleration이 없으면 해당 노드에 스케줄링 되지 않습니다.
기존에 동작 중이던 pod에게는 적용되지 않습니다.
PreferNoSchedulepod에게 toleration이 없으면 해당 노드에 스케줄링 하지 않으려고 시도합니다.
만약 리소스 부족 등의 이유가 있다면 스케줄링이 될 수 있습니다.
NoExecutepod에게 toleration이 없으면 해당 노드에 스케줄링 되지 않습니다
기존에 동작 중이던 pod에게도 적용되어, toleration 없는 pod는 종료합니다.



node에 taint를 설정하고 조회 및 제거하는 방법, pod에 toleration을 설정하여 스케줄링 하는 것을 예시로 확인해봅니다.



Taint 설정하기

kubectl taint node <node name> <key>=<value>:<effect>

kubectl taint node node0 key1=value1:NoSchedule
node/node0 tainted



Taint 검색하기

kubectl describe node <node name> | grep -i taint

kubectl describe node node0 | grep -i taint
Taints:             key1=value1:NoSchedule



Pod 스케줄링 확인하기

  • 먼저 toleration을 설정하지 않은 pod 입니다.
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent


현재 예시는 단일 노드 클러스터 입니다.

위 yaml파일을 apply 했을 때 pod의 상태와 describe 를 확인해봅니다.

kubectl get po
NAME                    READY   STATUS    RESTARTS      AGE
nginx                   0/1     Pending   0             52s

kubectl describe po nginx
Events:
  Type     Reason            Age   From               Message
  ----     ------            ----  ----               -------
  Warning  FailedScheduling  73s   default-scheduler  0/1 nodes are available: 1 node(s) had untolerated taint {key1: value1}. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.


  • 그렇다면, yaml파일을 수정하여 toleration 설정을 한 뒤, apply 합니다.
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  tolerations:
  - key: "key1"
    operator: "Exists"
    effect: "NoSchedule"


  • key : node에 설장한 taint의 key값을 입력합니다.
  • operator

- Exists : 어떤 taint를 가지고 있는 지와 상관없이 스케줄링 할 수 있습니다.

- Equal : node에 설정한 taint의 key와 value 값이 모두 일치해야 합니다.

  • effect : node에 설정한 taint의 effect를 입력합니다.



kubectl apply -f nginx.yaml
pod/nginx configured
kubectl get po
NAME                    READY   STATUS    RESTARTS      AGE
nginx                   1/1     Running   0             11m
kubectl describe po nginx
Events:
  Type     Reason            Age    From               Message
  ----     ------            ----   ----               -------
  Warning  FailedScheduling  11m    default-scheduler  0/1 nodes are available: 1 node(s) had untolerated taint {key1: value1}. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
  Warning  FailedScheduling  5m49s  default-scheduler  0/1 nodes are available: 1 node(s) had untolerated taint {key1: value1}. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
  Normal   Scheduled         7s     default-scheduler  Successfully assigned default/nginx to node0
  Normal   Pulled            7s     kubelet            Container image "nginx" already present on machine
  Normal   Created           7s     kubelet            Created container nginx
  Normal   Started           7s     kubelet            Started container nginx



Taint 제거하기

node에 설정한 taint를 제거할 때는 아래와 같이 수행할 수 있습니다.

kubectl taint node <node name> <key>-
kubectl taint node node0 key1-
node/node0 untainted
kubectl describe node node0 | grep -i taint
Taints:             <none>



마무리

  • pod를 스케줄링하는 방법 중, node의 taint 설정과 pod의 toleration 설정에 대해 알아보았습니다.
  • 해당 설정을 통해 노드 별 pod를 배치하는 데 활용할 수 있습니다.

아티클이 유용했나요?

훌륭합니다!

피드백을 제공해 주셔서 감사합니다.

도움이 되지 못해 죄송합니다!

피드백을 제공해 주셔서 감사합니다.

아티클을 개선할 수 있는 방법을 알려주세요!

최소 하나의 이유를 선택하세요
CAPTCHA 확인이 필요합니다.

피드백 전송

소중한 의견을 수렴하여 아티클을 개선하도록 노력하겠습니다.

02-558-8300