인프라/시스템 구축

[ EKS ] drain, cordon

김붕어87 2023. 4. 4. 10:51
반응형
개요
cordon으로 node에 pod가 배포되지 않도록 설정할 수 있다.
drain 으로 node에 배포된 모든 pod를 다른 node으로 옮기는 역할을 한다. (gracefully terminate)

ex) cordon
kubernetes를 사용하다가 보면 해당 Node에 POD들을 배포(스케줄링)되지 않도록 설정하거나,
특정 POD를 다른 Node으로 옮길 때 cordon 명령어가 필요하다.
Node에 배포되지 않도록 설정하는 방법은 cordon, taint 2가지 방법이 있다.
cordon은 일시적으로 해당 Node에 배포(스케줄링)되지 않도록 설정하는 방법이다.
Taint은 모든 POD가 배포되지 않도록 설정하는 것이 아니라, Key=value 라벨 설정을해서 toleration 옵션으로 특정 POD만 배포되도록 설정하는 옵션이다.

ex) drain
node 버전업그레이드, 예기치 못한 문제가 발생했을 경우,
node에 배포된 모든 pod를 다른 node으로 옮길 때 사용하는 명령어입니다.
예기치 못한 문제가 발생한 node에 다시 배포되지 않도록 cordon 걸어놓고 drain하면 다른 노드로 모든 pod가 배포된다.

 

[ Cordon 설정 ]

  • 특정 POD를 다른 Node에 배포하기

 

1. POD가 배포된 Node 찾기

  • pod/argocd-application-controller-0가 배포된 Node 찾기
# kubectl describe pod Name

kubectl describe  pod/argocd-application-controller-0 -n argocd |grep Node:
Node:         ip-10-223-87-81.ap-southeast-1.compute.internal

 

2. cordon 설정

  • cordon 설정하기 전 node 정보 확인
# node 정보 확인

kubectl get node ip-10-223-87-81.ap-southeast-1.compute.internal 

NAME                                              STATUS   ROLES    AGE   VERSION
ip-10-223-87-81.ap-southeast-1.compute.internal   Ready    <none>   12d   v1.23.9-eks-ba74326
kubectl describe node ip-10-223-87-81.ap-southeast-1.compute.internal

Taints:             <none>
Unschedulable:      false
Events:                       <none>

 

  • Node에 cordon 설정해서 pod가 배포되지 않도록 설정
kubectl cordon ip-10-223-87-81.ap-southeast-1.compute.internal

node/ip-10-223-87-81.ap-southeast-1.compute.internal cordoned

 

  • cordon 설정 후 node 정보 확인
  • Node STATUS 상태에 “SchedulingDisabled” 추가됨
kubectl get node ip-10-223-87-81.ap-southeast-1.compute.internal

NAME                                              STATUS                     ROLES    AGE   VERSION
ip-10-223-87-81.ap-southeast-1.compute.internal   Ready,SchedulingDisabled   <none>   12d   v1.23.9-eks-ba74326
kubectl describe node ip-10-223-87-81.ap-southeast-1.compute.internal

Taints:             node.kubernetes.io/unschedulable:NoSchedule
Unschedulable:      true
Events:
  Type    Reason              Age   From     Message
  ----    ------              ----  ----     -------
  Normal  NodeNotSchedulable  87s   kubelet  Node ip-10-223-87-81.ap-southeast-1.compute.internal status is now: NodeNotSchedulable

 

 

3. pod를 다른 Node에 배포

  • delete 방법
    • pod/argocd-application-controller-0를 delete하면 현재 배포된 Node은 NoSchedule 상태라서 배포가 되지 않고, 다른 Node로 배포가 된다.
  • 재배포 방법
    • pod/argocd-application-controller-0를 재배포하면 현재 배포된 Node은 NoSchedule 상태라서 배포가 되지 않고, 다른 Node로 배포가 된다.

 

4. Node가 변경되었는지 확인

  • 변경 확인
    • ip-10-223-87-81.ap-southeast-1.compute.internal → ip-10-223-85-90.ap-southeast-1.compute.internal
kubectl describe  pod/argocd-application-controller-0 -n argocd |grep Node:
Node:         ip-10-223-85-90.ap-southeast-1.compute.internal

 

5. cordon 해제

  • 다른 POD들이 배포될 수 있도록 cordon 해제
kubectl get node ip-10-223-87-81.ap-southeast-1.compute.internal

NAME                                              STATUS                     ROLES    AGE   VERSION
ip-10-223-87-81.ap-southeast-1.compute.internal   Ready,SchedulingDisabled   <none>   12d   v1.23.9-eks-ba74326
kubectl uncordon ip-10-223-87-81.ap-southeast-1.compute.internal
node/ip-10-223-87-81.ap-southeast-1.compute.internal uncordoned
kubectl get node ip-10-223-87-81.ap-southeast-1.compute.internal

NAME                                              STATUS   ROLES    AGE   VERSION
ip-10-223-87-81.ap-southeast-1.compute.internal   Ready    <none>   12d   v1.23.9-eks-ba74326

 


[ drain 설정 ]

  • Node에 모든 pod를 다른 Node으로 옮기는 명령어입니다.

 

1. drain 옵션 설명

  • Node에 deamonsets이 있으면 다시 해당 Node에 배포하려고 하기 때문에 drain이 실패한다.
    • deamonsets pod를 무시하고 진행하려면 --ignore-daemonsets=true 옵션을 주고하면 drain이 된다.
$ kubectl drain xxx-node
node "xxx-node" cordoned
error: unable to drain node "xxx-node", aborting command...

There are pending nodes to be drained:
xxx-node
error: DaemonSet-managed pods (use --ignore-daemonsets to ignore): kube-proxy-4s52d
$ kubectl drain xxx-node --ignore-daemonsets=true
node "xxx-node" already cordoned
WARNING: Ignoring DaemonSet-managed pods: kube-proxy-4s52d

 

  • Node에서 deployment,statefulset 등으로 관리되는 pod은 drain이 되지만, 단일로 pod만 배포된 상태이면 drain이 실패한다.
    • 단일로 pod만 배포된 경우 drain하면 다른 node에 올라가지 않기 때문에, 무시하고 진행하려면 --force 옵션을 주고하면 drain이 된다.

 

 

2. drain 실행

  • xxx-node에 drain 명령어 실행
kubectl drain xxx-node --ignore-daemonsets=true

 

 

반응형

'인프라 > 시스템 구축' 카테고리의 다른 글

[ EKS ] ConfigMap, aws-auth 설정  (0) 2023.04.04
[ EKS ] Limit, Request 설정  (0) 2023.04.04
[ EKS ] NodeSelector 설정  (0) 2023.04.03
[ EKS ] taint, toleration 설정  (0) 2023.04.03
[ EKS ] EBS -> EFS 볼륨 변경  (0) 2023.03.31