Kubernetes/KoudKloud - CKAD with Tests

Taints/Tolerations 관련 명령어

비번변경 2021. 11. 29. 00:06

노드가 포드를 스케쥴링되지 않도록 하는 Taints와 포드가 Taints가 설정된 노드와 설정되지 않은 노드에 스케쥴링될 수 있도록 하는 Tolerations는 함께 동작하는 개념이다.

이 글에서는 Taints/Tolerations을 확인하고 설정하는 방법을 정리한다.

 

Node의 Taints 확인

describe 명령 실행 결과의 Taints 필드에서 확인할 수 있다.

kubectl describe node <NAME>

Node의 Taints 확인

 

Node에 Taints 설정

taint 명령으로 설정을 추가한다.

kubectl taint node <NODE_NAME> KEY=VALUE:EFFECT

# 예시
kubectl taint node node01 spray=mortein:NoSchedule

Node에 Taints 설정

 

Node에서 Taints 삭제

taint 명령 끝에 - 기호를 붙여 설정했던 Taints를 삭제한다.

kubectl taint node <NODE_NAME> KEY=VALUE:EFFECT-

# 예시
kubectl taint node node01 spray=mortein:NoSchedule-

 

또는 edit 명령을 이용해 아래 yaml 형식에서 spec> taints 부분을 삭제 후, 저장한다.

apiVersion: v1
kind: Node
metadata:
  annotations:
    flannel.alpha.coreos.com/backend-data: '{"VNI":1,"VtepMAC":"a6:7f:33:1c:a7:84"}'
    flannel.alpha.coreos.com/backend-type: vxlan
    flannel.alpha.coreos.com/kube-subnet-manager: "true"
    flannel.alpha.coreos.com/public-ip: 10.29.33.9
    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
    node.alpha.kubernetes.io/ttl: "0"
    volumes.kubernetes.io/controller-managed-attach-detach: "true"
  creationTimestamp: "2021-11-19T13:28:32Z"
  labels:
    beta.kubernetes.io/arch: amd64
    beta.kubernetes.io/os: linux
    kubernetes.io/arch: amd64
    kubernetes.io/hostname: controlplane
    kubernetes.io/os: linux
    node-role.kubernetes.io/control-plane: ""
    node-role.kubernetes.io/master: ""
  name: controlplane
  resourceVersion: "2190"
  uid: eb153e95-ae94-4cd6-bbf0-136f56cb763b
spec:
  podCIDR: 10.244.0.0/24
  podCIDRs:
  - 10.244.0.0/24
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master

 

Pod에 Tolerations 설정

포드 정의 yaml 파일 spec 아래에 tolerations 필드를 추가한다.

포드가 스케줄 된 노드는 get pods -o wide 명령으로 확인할 수 있다.

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: bee
  name: bee
spec:
  containers:
  - image: nginx
    name: bee
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
  tolerations:
  - key: "spray"
    operator: "Equal"
    value: "mortein"
    effect: "NoSchedule"
status: {}

 

 

728x90