Toleration 작업
이제 taint 가 어떻게 작동하는지 이해했으므로, taint 가 있는 노드에서 파드를 스케줄링할 수 있게 해주는 메커니즘인 toleration 을 살펴보겠습니다.
Toleration 이해
Toleration 은 파드 사양에 지정되며, 일치하는 taint 가 있는 노드에서 파드를 스케줄링할 수 있도록 합니다. Toleration 은 다음으로 구성됩니다.
key: taint key 와 일치합니다.
operator: Equal (key 와 value 일치) 또는 Exists (key 만 일치)
value: 일치시킬 값 ( Equal 연산자 사용 시)
effect: 일치시킬 effect, 또는 모든 effect 와 일치시키려면 비워 둡니다.
tolerationSeconds: 일치하는 NoExecute taint 가 있는 노드에서 파드가 유지될 수 있는 선택적 기간
Toleration 이 있는 파드 생성
control-plane taint 를 toleration 하는 파드를 생성해 보겠습니다. 먼저, 파드에 대한 YAML 파일을 생성해 보겠습니다.
nano ~/project/toleration-pod.yaml
이제 파일에 다음 내용을 추가합니다.
apiVersion: v1
kind: Pod
metadata:
name: toleration-pod
spec:
containers:
- name: nginx
image: nginx:latest
tolerations:
- key: "node-role.kubernetes.io/control-plane"
operator: "Exists"
effect: "NoSchedule"
이 파드 사양에는 노드의 control-plane taint 와 일치하는 toleration 이 포함되어 있습니다. 파일을 저장하고 종료합니다 (nano 에서 Ctrl+O, Enter를 누른 다음 Ctrl+X를 누릅니다).
이제 파드를 생성해 보겠습니다.
kubectl apply -f ~/project/toleration-pod.yaml
다음과 같은 출력을 볼 수 있습니다.
pod/toleration-pod created
파드가 노드에서 스케줄링되었는지 확인해 보겠습니다.
kubectl get pods -o wide
예시 출력:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
toleration-pod 1/1 Running 0 12s 10.244.0.5 minikube <none> <none>
파드는 control-plane taint 와 일치하는 toleration 이 있기 때문에 minikube 노드에서 실행 중입니다.
Toleration 이 없는 파드로 테스트
비교를 위해 toleration 이 없는 파드를 생성해 보겠습니다.
nano ~/project/no-toleration-pod.yaml
다음 내용을 추가합니다.
apiVersion: v1
kind: Pod
metadata:
name: no-toleration-pod
spec:
containers:
- name: nginx
image: nginx:latest
파일을 저장하고 종료한 다음 파드를 생성합니다.
kubectl apply -f ~/project/no-toleration-pod.yaml
이제 파드 상태를 확인해 보겠습니다.
kubectl get pods -o wide
파드가 Pending 상태로 유지되는 것을 알 수 있습니다.
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
no-toleration-pod 0/1 Pending 0 12s <none> <none> <none> <none>
toleration-pod 1/1 Running 0 2m 10.244.0.5 minikube <none> <none>
파드가 왜 Pending 상태인지 확인해 보겠습니다.
kubectl describe pod no-toleration-pod
Events 섹션에서 다음과 유사한 내용을 볼 수 있습니다.
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 45s default-scheduler 0/1 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
이는 파드가 control-plane taint 를 toleration 하지 않기 때문에 스케줄링할 수 없음을 확인합니다.
정리
생성한 파드를 정리해 보겠습니다.
kubectl delete pod toleration-pod no-toleration-pod
다음과 같은 출력을 볼 수 있습니다.
pod "toleration-pod" deleted
pod "no-toleration-pod" deleted
축하합니다! 이제 Kubernetes 에서 파드 스케줄링을 제어하기 위해 taint 와 toleration 이 함께 작동하는 방식을 이해했습니다.