Taints 및 Tolerations

KubernetesBeginner
지금 연습하기

소개

Taints 와 Tolerations 는 Kubernetes 에서 특정 Pod 를 스케줄링하기에 적합한 노드를 지정하는 데 사용됩니다. Taint 는 Pod 를 거부하기 위해 노드에 적용되는 반면, Toleration 은 특정 노드로 Pod 를 유치하기 위해 Pod 에 적용됩니다. 이 Lab 에서는 Taints 와 Tolerations 를 사용하여 특정 노드에 Pod 를 스케줄링하는 방법을 배우겠습니다.

Minikube 클러스터 시작

리소스를 생성하기 전에 실행 중인 Kubernetes 클러스터가 필요합니다. Minikube 는 로컬 머신에서 실행되는 가벼운 Kubernetes 환경입니다.

  1. 작업 디렉토리로 이동:

    터미널을 열고 기본 프로젝트 폴더로 이동합니다.

    cd /home/labex/project
    
  2. Minikube 시작:

    Kubernetes 클러스터를 초기화하기 위해 Minikube 를 시작합니다.

    minikube start
    
    • 이 명령은 로컬 머신에 단일 노드 Kubernetes 클러스터를 설정합니다.
    • Minikube 는 시스템 성능에 따라 시작하는 데 몇 분 정도 걸릴 수 있습니다.
  3. Minikube 가 실행 중인지 확인:

    Minikube 클러스터의 상태를 확인합니다.

    minikube status
    
    • kubeletapiserver와 같은 구성 요소가 Running으로 나열되어 있는지 확인합니다.
    • 클러스터가 실행 중이지 않으면 minikube start를 다시 실행합니다.

Minikube 를 시작하는 데 문제가 발생하면 필요에 따라 minikube delete를 사용하여 환경을 재설정하십시오.

Tainted Node 생성

이 단계에서는 특정 Pod 를 거부하는 Taint 를 가진 노드를 생성합니다.

  1. 사용자 지정 레이블로 노드에 레이블을 지정합니다.
kubectl label nodes minikube disk-type=ssd
  1. 다음 명령을 사용하여 노드에 Taint 를 적용합니다.
kubectl taint nodes minikube disk-type=ssd:NoSchedule

NoSchedule 효과는 Toleration 이 없는 Pod 가 이 노드에 스케줄링되는 것을 방지합니다.

Toleration 없이 Pod 생성

이 단계에서는 Toleration 이 없는 Pod 를 생성하고 Tainted Node 에 스케줄링될 수 없는지 확인합니다.

  1. 다음 내용으로 pod-without-toleration.yaml이라는 파일을 생성합니다.
apiVersion: v1
kind: Pod
metadata:
  name: pod-without-toleration
spec:
  containers:
    - name: nginx
      image: nginx:latest
  1. 변경 사항을 적용합니다.
kubectl apply -f pod-without-toleration.yaml
  1. Pod 가 Tainted Node 에 스케줄링되지 않았는지 확인합니다.
kubectl describe pod pod-without-toleration | grep -i taint

출력 결과는 Pod 가 Taint 가 있는 노드에 스케줄링되지 않았음을 보여줍니다.

Toleration 을 사용하여 Pod 생성

이 단계에서는 Tainted Node 에 스케줄링될 수 있도록 Toleration 이 있는 Pod 를 생성합니다.

  1. 다음 내용으로 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"
  1. 변경 사항을 적용합니다.
kubectl apply -f pod-with-toleration.yaml
  1. Pod 가 Tainted Node 에 스케줄링되었는지 확인합니다.
kubectl get pod pod-with-toleration -o wide

다중 Taint 허용 (Tolerating Multiple Taints)

이 단계에서는 여러 Taint 가 있는 노드에 스케줄링될 수 있도록 여러 Toleration 이 있는 Pod 를 생성합니다.

  1. 다음 내용으로 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"
  1. 변경 사항을 적용합니다.
kubectl apply -f pod-with-multiple-tolerations.yaml
  1. Pod 가 두 Taint 모두 있는 노드에 스케줄링되었는지 확인합니다.
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 의 강력한 기능입니다.