본문 바로가기
INFRA/DevOps

[K8s] Taint & Toleration,Cordon& Drain

by BTC_프로틴 2023. 2. 13.

Taint & Toleration이란?

  • node taint, pod toleration
  • worker node에 taint가 설정된 경우 동일 값의 toleration이 있는 pod만 배치
  • toleration이 있는 pod는 동일한 taint가 있는 node를 포함하여 모든 node에 배치
  • effect 필드 종류
    • NoSchedule : toleration이 맞지 않으면 배치되지 않음.
    • PreferNoSchedule : toleration이 맞지 않으면 배치되지 않으나, cluster 리소스가 부족하면 할당
    • NoExecute : toleration이 맞으면 동작중인 pod를 종료

<이미지 출처 : https://www.youtube.com/watch?v=oy15F0LgRzE&list=PLApuRlvrZKohLYdvfX-UEFYTE7kfnnY36&index=2 >

 

[ Hands - on ]

  • node1에 taint 설정 및 확인
kubectl taint nodes node1.example.com role=web:NoSchedule
kubectl describe node node{1,2}.example.com | grep -i taint
Taints:             role=web:NoSchedule
Taints:             <none>
  • role=web:NoSchedule taint 되지 않은 node에만 pod 할당
vi deploy-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: webui
spec:
  replicas: 4
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.14
kubectl apply -f deploy-nginx.yaml
kubectl get pods -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP          NODE                NOMINATED NODE   READINESS GATES
webui-6d75c5dd9b-48skl   1/1     Running   0          4s    10.44.0.4   node2.example.com   <none>           <none>
webui-6d75c5dd9b-dxmts   1/1     Running   0          4s    10.44.0.2   node2.example.com   <none>           <none>
webui-6d75c5dd9b-txh8r   1/1     Running   0          4s    10.44.0.1   node2.example.com   <none>           <none>
webui-6d75c5dd9b-vp74l   1/1     Running   0          4s    10.44.0.3   node2.example.com   <none>           <none>
  • role=web:NoSchedule taint가 된 node에도 pod 할당
vi deploy-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: webui
spec:
  replicas: 4
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.14
      tolerations:
      - key: "role"
        operator: "Equal"
        value: "web"
        effect: "NoSchedule"
kubectl apply -f deploy-nginx.yaml
kubectl get pods -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP          NODE                NOMINATED NODE   READINESS GATES
webui-69f65c48f9-669vx   1/1     Running   0          36s   10.44.0.2   node2.example.com   <none>           <none>
webui-69f65c48f9-7qszc   1/1     Running   0          36s   10.44.0.1   node2.example.com   <none>           <none>
webui-69f65c48f9-hh88r   1/1     Running   0          36s   10.36.0.1   node1.example.com   <none>           <none>
webui-69f65c48f9-hmkpn   1/1     Running   0          36s   10.36.0.2   node1.example.com   <none>           <none>
  • taint 삭제
kubectl taint nodes node1.example.com role-

 

 

참고 :

https://www.youtube.com/watch?v=oy15F0LgRzE&list=PLApuRlvrZKohLYdvfX-UEFYTE7kfnnY36&index=2

'INFRA > DevOps' 카테고리의 다른 글

[K8s] 인증과 권한 관리 - 인증편  (1) 2023.02.27
[K8s] Cordon& Drain  (1) 2023.02.20
[k8s] Pod Scheduling  (1) 2023.02.06
[K8s] Multi-master - HA Kuberenetes cluster 운영  (0) 2023.01.30
[k8s] Secret  (1) 2023.01.25

댓글