Kubernetes Taint 명령어

KubernetesBeginner
지금 연습하기

소개

이 랩에서는 Kubernetes 에서 노드에 taint 를 추가, 수정 및 제거하는 강력한 도구인 kubectl taint 명령어를 사용하는 방법을 배우게 됩니다. Taint 는 노드에 특정 제한 사항이나 요구 사항이 있음을 나타내는 데 사용되며, 이는 Kubernetes 클러스터에서 파드의 스케줄링을 제어하는 데 도움이 될 수 있습니다.

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를 사용하여 환경을 재설정하십시오.

kubectl taint 명령어 탐색

kubectl taint 명령어는 Kubernetes 노드에 taint 를 추가, 수정 또는 제거하는 데 사용됩니다. Taint 는 특정 노드에 배치할 수 있는 파드를 제한하여 파드 스케줄링에 영향을 미치는 효과를 가진 키 - 값 쌍입니다.

kubectl taint에 사용 가능한 옵션을 보려면 다음 명령을 실행하십시오.

kubectl taint -h

다음 출력을 볼 수 있습니다.

Update the taints on one or more nodes.

  *  A taint consists of a key, value, and effect. As an argument here, it is expressed as key=value:effect.
  *  The key must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to
  253 characters.
  *  Optionally, the key can begin with a DNS subdomain prefix and a single '/', like example.com/my-app.
  *  The value is optional. If given, it must begin with a letter or number, and may contain letters, numbers, hyphens,
  dots, and underscores, up to 63 characters.
  *  The effect must be NoSchedule, PreferNoSchedule or NoExecute.
  *  Currently taint can only apply to node.

Examples:
  ## Update node 'foo' with a taint with key 'dedicated' and value 'special-user' and effect 'NoSchedule'
  ## If a taint with that key and effect already exists, its value is replaced as specified
  kubectl taint nodes foo dedicated=special-user:NoSchedule

  ## Remove from node 'foo' the taint with key 'dedicated' and effect 'NoSchedule' if one exists
  kubectl taint nodes foo dedicated:NoSchedule-

  ## Remove from node 'foo' all the taints with key 'dedicated'
  kubectl taint nodes foo dedicated-

  ## Add a taint with key 'dedicated' on nodes having label mylabel=X
  kubectl taint node -l myLabel=X dedicated=foo:PreferNoSchedule

  ## Add to node 'foo' a taint with key 'bar' and no value
  kubectl taint nodes foo bar:NoSchedule

노드에 Taint 추가

이 단계에서는 kubectl taint 명령을 사용하여 노드에 taint 를 추가하는 방법을 배웁니다. Taint 는 특정 제한 사항 또는 요구 사항으로 노드를 표시하는 데 사용되며, 이는 해당 노드에서 파드의 스케줄링에 영향을 미칠 수 있습니다.

노드에 taint 를 추가하려면 다음 명령을 사용할 수 있습니다.

kubectl taint nodes minikube app=prod:NoSchedule

이렇게 하면 minikube라는 노드에 키가 app이고 값이 prod이며 효과가 NoSchedule인 taint 가 추가됩니다. 이는 taint 를 허용하지 않는 한 파드가 해당 노드에서 스케줄링되는 것을 방지합니다.

그런 다음 kubectl describe node 명령을 사용하여 Kubernetes 클러스터의 노드에 현재 적용된 taint 를 볼 수 있습니다.

노드의 taint 를 보려면 다음 명령을 사용할 수 있습니다.

kubectl describe node minikube

노드에 적용된 taint 는 출력의 "Taints" 섹션 아래에 나열됩니다. 이 정보를 사용하여 이전 단계에서 추가한 taint 가 노드에 적용되었는지 확인할 수 있습니다.

노드에서 Taint 제거

이 단계에서는 kubectl taint 명령을 사용하여 노드에서 taint 를 제거하는 방법을 배웁니다. 이는 노드의 제한 사항 또는 요구 사항을 업데이트해야 하거나, 이전에 taint 가 적용된 노드에서 파드를 스케줄링하려는 경우 유용할 수 있습니다.

노드에서 taint 를 제거하려면 다음 명령을 사용할 수 있습니다.

kubectl taint nodes minikube app-

이 명령은 minikube 노드에서 app=prod:NoSchedule taint 를 제거합니다. 이렇게 하면 이전에 적용된 taint 를 허용할 필요 없이 파드를 해당 노드에서 스케줄링할 수 있습니다.

노드의 Taint 수정

이 단계에서는 kubectl taint 명령을 사용하여 노드의 taint 를 수정하는 방법을 배웁니다. 이는 노드의 제한 사항 또는 요구 사항을 업데이트해야 하지만 기존 taint 키와 효과를 유지하려는 경우 유용할 수 있습니다.

  1. 다음 내용으로 새 taint 를 추가합니다.
kubectl taint nodes minikube app=uat:NoSchedule
  1. 덮어쓰기를 사용하여 업데이트를 강제합니다.
kubectl taint nodes minikube app=dev:NoSchedule --overwrite=true

이 명령은 minikube 노드에서 app taint 값을 prod에서 dev로 업데이트합니다. 이렇게 하면 동일한 taint 키와 효과를 유지하면서 노드의 taint 가 업데이트됩니다.

요약

이 랩에서는 Kubernetes 에서 kubectl taint 명령을 사용하는 방법을 배웠습니다. 특정 키, 값 및 효과를 사용하여 kubectl taint 명령으로 노드에 taint 를 추가하는 것으로 시작했습니다. 그런 다음 kubectl describe node 명령을 사용하여 노드에 적용된 taint 를 확인하는 방법을 배웠습니다.