소개
Taints 와 Tolerations 는 Kubernetes 에서 특정 Pod 를 스케줄링하기에 적합한 노드를 지정하는 데 사용됩니다. Taint 는 Pod 를 거부하기 위해 노드에 적용되는 반면, Toleration 은 특정 노드로 Pod 를 유치하기 위해 Pod 에 적용됩니다. 이 Lab 에서는 Taints 와 Tolerations 를 사용하여 특정 노드에 Pod 를 스케줄링하는 방법을 배우겠습니다.
Taints 와 Tolerations 는 Kubernetes 에서 특정 Pod 를 스케줄링하기에 적합한 노드를 지정하는 데 사용됩니다. Taint 는 Pod 를 거부하기 위해 노드에 적용되는 반면, Toleration 은 특정 노드로 Pod 를 유치하기 위해 Pod 에 적용됩니다. 이 Lab 에서는 Taints 와 Tolerations 를 사용하여 특정 노드에 Pod 를 스케줄링하는 방법을 배우겠습니다.
리소스를 생성하기 전에 실행 중인 Kubernetes 클러스터가 필요합니다. Minikube 는 로컬 머신에서 실행되는 가벼운 Kubernetes 환경입니다.
작업 디렉토리로 이동:
터미널을 열고 기본 프로젝트 폴더로 이동합니다.
cd /home/labex/project
Minikube 시작:
Kubernetes 클러스터를 초기화하기 위해 Minikube 를 시작합니다.
minikube start
Minikube 가 실행 중인지 확인:
Minikube 클러스터의 상태를 확인합니다.
minikube status
kubelet 및 apiserver와 같은 구성 요소가 Running으로 나열되어 있는지 확인합니다.minikube start를 다시 실행합니다.Minikube 를 시작하는 데 문제가 발생하면 필요에 따라 minikube delete를 사용하여 환경을 재설정하십시오.
이 단계에서는 특정 Pod 를 거부하는 Taint 를 가진 노드를 생성합니다.
kubectl label nodes minikube disk-type=ssd
kubectl taint nodes minikube disk-type=ssd:NoSchedule
NoSchedule 효과는 Toleration 이 없는 Pod 가 이 노드에 스케줄링되는 것을 방지합니다.
이 단계에서는 Toleration 이 없는 Pod 를 생성하고 Tainted Node 에 스케줄링될 수 없는지 확인합니다.
pod-without-toleration.yaml이라는 파일을 생성합니다.apiVersion: v1
kind: Pod
metadata:
name: pod-without-toleration
spec:
containers:
- name: nginx
image: nginx:latest
kubectl apply -f pod-without-toleration.yaml
kubectl describe pod pod-without-toleration | grep -i taint
출력 결과는 Pod 가 Taint 가 있는 노드에 스케줄링되지 않았음을 보여줍니다.
이 단계에서는 Tainted Node 에 스케줄링될 수 있도록 Toleration 이 있는 Pod 를 생성합니다.
pod-with-toleration.yaml이라는 파일을 생성합니다.apiVersion: v1
kind: Pod
metadata:
name: pod-with-toleration
spec:
containers:
- name: nginx
image: nginx:latest
tolerations:
- key: "disk-type"
operator: "Equal"
value: "ssd"
effect: "NoSchedule"
kubectl apply -f pod-with-toleration.yaml
kubectl get pod pod-with-toleration -o wide
이 단계에서는 여러 Taint 가 있는 노드에 스케줄링될 수 있도록 여러 Toleration 이 있는 Pod 를 생성합니다.
pod-with-multiple-tolerations.yaml이라는 파일을 생성합니다.apiVersion: v1
kind: Pod
metadata:
name: pod-with-multiple-tolerations
spec:
containers:
- name: nginx
image: nginx:latest
tolerations:
- key: "disk-type"
operator: "Equal"
value: "ssd"
effect: "NoSchedule"
- key: "gpu"
operator: "Equal"
value: "true"
effect: "NoSchedule"
kubectl apply -f pod-with-multiple-tolerations.yaml
kubectl get pod pod-with-multiple-tolerations -o wide
이 Lab 에서는 Taint 와 Toleration 을 사용하여 특정 노드에 Pod 를 스케줄링하는 방법을 배웠습니다. 먼저 Tainted Node 를 생성하고 Toleration 이 없는 Pod 가 해당 노드에 스케줄링될 수 없는지 확인했습니다. 그런 다음 Toleration 이 있는 Pod 를 생성하고 Tainted Node 에 스케줄링될 수 있는지 확인했습니다. 마지막으로, 여러 Toleration 이 있는 Pod 를 생성하고 여러 Taint 가 있는 노드에 스케줄링될 수 있는지 확인했습니다.
Taint 와 Toleration 은 특정 워크로드가 특정 노드에서만 스케줄링되도록 보장하는 데 사용할 수 있는 Kubernetes 의 강력한 기능입니다.