K8S> Taint와 Toleration

머성·2022년 7월 24일

CKA 자격증 공부

목록 보기
1/2

Taint

TaintNode에 적용되는 속성으로, Node에 스케줄링될 Pod를 제한 할 수 있는 기능을 제공한다. Taint가 적용된 Node에는 설정에 따라 해당 Taint에 내성(Toleration)을 지닌 Pod를 우선적으로 배치하거나 해당 Pod만을 스케줄링하도록 할 수 있다.

Taint 설정 방법

# Add taint to node
kubectl taint nodes NODE_NAME KEY=[VALUE]:EFFECT

# Delete taint from node
kubectl taint nodes NODE_NAME KEY=[VALUE]:EFFECT-

EFFECTPreferNoSchedule, NoSchedule, NoExecute 값으로 설정될 수 있다.

  • PreferNoSchedule: 가능하다면 설정된 Taint에 내성을 지닌 Pod만 스케줄링한다. 이름에서 유추할 수 있듯이 상황에 따라서는 내성이 없는 Pod가 스케줄링 될 수도 있다.
  • NoSchedule: 설정된 Taint에 내성을 지닌 Pod 스케줄링한다.
  • NoExecute: NoSchedule의 효과에 더해 Taint가 적용되기 이전에 스케줄링 되어있던 Pod가 추가된 Taint에 내성이 없다면 해당 PodNode에서 제거한다.

아래와 같이 YAML을 사용해 Taint를 설정할 수 있다.

apiVersion: v1
kind: Node
metadata:
  name: node01
  ...
spec:
  taints:
  # kubectl taint nodes node01 node-role.kubernetes.io/master=:NoSchedule
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
  ...
status:
  ...

이제 node01에는 node-role.kubernetes.io/master=:NoSchedule에 내성을 지닌 Pod들만 스케줄링된다.

Toleration

TolerationPod에 적용되는 속성으로, Node에 적용된 Taint에 대한 내성을 부여할 수 있다. 즉, TolerationPod에 설정하면 Toleration와 매칭되는 Taint가 존재하는 Node에 해당 Pod가 스케줄링 될 수 있다.

Toleration 설정 방법

아래와 같이 YAML을 사용해 Toleration을 설정할 수 있다.

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
  ...
spec:
  tolerations:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
  - ...
  ...
status:
  ...

my-pod Podnode-role.kubernetes.io/master=:NoSchedule Taint에 대한 내성을 가지고 있다. 따라서 my-pod는 위의 예시에서의 node01에서 스케줄링 될 수 있다.

현재 Pod들의 상태를 kubectl로 확인해보자.

> $ kubectl get po -o wide
NAME     READY   STATUS    RESTARTS   AGE    IP             NODE            NOMINATED NODE   READINESS GATES
my-pod   1/1     Running   0          6m9s   172.16.39.82   node01          <none>           <none>

Toleration은 추가로 tolerationSeconds 속성을 지정할 수 있다. tolerationSeconds는 내성의 지속 시간을 의미한다. 어떤 PodtolerationSeconds 속성의 값을 60으로 설정했다고 가정해보자. 이 Pod에 설정된 Toleration에 매칭되는 Taint가 존재하는 Node에 해당 Pod이 스케줄링된 경우, 60초 후 이 Pod의 실행이 종료된다. 내성의 지속 시간(tolerationSeconds)이 60초이기 때문이다.

apiVersion: v1
kind: Pod
metadata:
  ...
spec:
  tolerations:
  # 이 Toleration에 매칭 되는 Taint를 지닌 Node에 스케줄링되면 60초 후 Pod가 종료된다.
  - effect: NoExecute
    key: toleration1
  # operator: Equal
    tolerationSeconds: 60
  
  # effect 속성이 명시되지 않으면 모든 effect에 대하여 적용된다.
  - key: toleration2
    value: value_of_toleration2
    
  # "operator: Exists"가 설정된 경우 key에 매칭되는 모든 Taint에 이 Toleration이 적용된다.
  - key: toleration3
    operator: Exists
    
  # "operator: Exists"를 설정하고 key값을 제공하지 않으면 모든 taint를 무시한다.
  - operator: Exists
  ...
status:
  ...

References

Taints and Tolerations, kubernetes.io
Certified Kubernetes Administrator (CKA) with Practice Tests, Udemy.com

0개의 댓글