본문 바로가기

리눅스

[draft] kubernetes 커든 및 드레인

kubernetes 커든 및 드레인

노드 스케줄링 제어

  • Cordon & Drain Kubernetes에서 특정 노드에 새로운 파드가 스케줄되지 않도록 하거나 기존 파드를 안전하게 다른 노드로 옮기고자 할 때 cordon, drain, uncordon 명령을 사용합니다.

1. 클러스터 노드 확인

kubectl get nodes
$ kubectl get nodes
NAME                                                STATUS   ROLES    AGE   VERSION
ip-192-168-27-248.ap-northeast-2.compute.internal   Ready    <none>   17h   v1.22.12-eks-ba74326
ip-192-168-42-8.ap-northeast-2.compute.internal     Ready    <none>   17h   v1.22.12-eks-ba74326
ip-192-168-67-156.ap-northeast-2.compute.internal   Ready    <none>   17h   v1.22.12-eks-ba74326

2. Cordon — 노드 스케줄 중단

특정 노드에 새로운 파드가 스케줄되지 않도록 차단합니다.

기존에 동작 중인 파드는 그대로 유지됩니다.

kubectl cordon ip-192-168-67-156.ap-northeast-2.compute.internal
$ kubectl cordon ip-192-168-67-156.ap-northeast-2.compute.internal
node/ip-192-168-67-156.ap-northeast-2.compute.internal cordoned

노드 상태 확인

$ kubectl get nodes
NAME                                                STATUS                     ROLES    AGE   VERSION
ip-192-168-27-248.ap-northeast-2.compute.internal   Ready                      <none>   17h   v1.22.12-eks-ba74326
ip-192-168-42-8.ap-northeast-2.compute.internal     Ready                      <none>   17h   v1.22.12-eks-ba74326
ip-192-168-67-156.ap-northeast-2.compute.internal   Ready,SchedulingDisabled   <none>   17h   v1.22.12-eks-ba74326
SchedulingDisabled : 신규 파드 스케줄링이 비활성화된 상태

3. Drain — 노드 비우기

해당 노드에서 실행 중인 파드를 모두 다른 노드로 안전하게 이동시킵니다.

(단, DaemonSet 파드는 삭제되지 않으므로 --ignore-daemonsets 옵션을 함께 사용합니다.)

kubectl drain ip-192-168-67-156.ap-northeast-2.compute.internal
$ kubectl drain ip-192-168-67-156.ap-northeast-2.compute.internal
node/ip-192-168-67-156.ap-northeast-2.compute.internal cordoned
DEPRECATED WARNING: Aborting the drain command in a list of nodes will be deprecated in v1.23.
The new behavior will make the drain command go through all nodes even if one or more nodes failed during the drain.
For now, users can try such experience via: --ignore-errors
error: unable to drain node "ip-192-168-67-156.ap-northeast-2.compute.internal", aborting command...

There are pending nodes to be drained:
 ip-192-168-67-156.ap-northeast-2.compute.internal
error: cannot delete DaemonSet-managed Pods (use --ignore-daemonsets to ignore): kube-system/aws-node-ct6lv, kube-system/kube-proxy-dsfgs
kubectl drain ip-192-168-67-156.ap-northeast-2.compute.internal --ignore-daemonsets
$ kubectl drain ip-192-168-67-156.ap-northeast-2.compute.internal --ignore-daemonsets
node/ip-192-168-67-156.ap-northeast-2.compute.internal already cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/aws-node-ct6lv, kube-system/kube-proxy-dsfgs
node/ip-192-168-67-156.ap-northeast-2.compute.internal drained
drain 명령은 자동으로 cordon 상태로 전환합니다.

노드 상태 확인

$ kubectl get nodes
NAME                                                STATUS                     ROLES    AGE   VERSION
ip-192-168-27-248.ap-northeast-2.compute.internal   Ready                      <none>   17h   v1.22.12-eks-ba74326
ip-192-168-42-8.ap-northeast-2.compute.internal     Ready                      <none>   17h   v1.22.12-eks-ba74326
ip-192-168-67-156.ap-northeast-2.compute.internal   Ready,SchedulingDisabled   <none>   17h   v1.22.12-eks-ba74326

4. Uncordon — 스케줄링 재개

노드의 스케줄링을 다시 활성화합니다.

kubectl uncordon ip-192-168-67-156.ap-northeast-2.compute.internal
$ kubectl uncordon ip-192-168-67-156.ap-northeast-2.compute.internal
node/ip-192-168-67-156.ap-northeast-2.compute.internal uncordoned

노드 상태 확인

$ kubectl get nodes
NAME                                                STATUS   ROLES    AGE   VERSION
ip-192-168-27-248.ap-northeast-2.compute.internal   Ready    <none>   17h   v1.22.12-eks-ba74326
ip-192-168-42-8.ap-northeast-2.compute.internal     Ready    <none>   17h   v1.22.12-eks-ba74326
ip-192-168-67-156.ap-northeast-2.compute.internal   Ready    <none>   17h   v1.22.12-eks-ba74326
해당 노드는 다시 파드 스케줄링 대상이 됩니다.

명령어 정리

명령어 설명 주요 효과
kubectl cordon <node> 신규 파드 스케줄 중단 기존 파드는 유지
kubectl drain <node> --ignore-daemonsets 파드들을 안전하게 다른 노드로 이동 노드 비움 및 cordon 자동 설정
kubectl uncordon <node> 스케줄링 재활성화 노드 복귀