drain, cordon, uncordon 명령

2025. 3. 27. 14:32·DevOps/✏️ Cloud
반응형

노드 관리

노드의 OS 버전을 업데이트 해야하거나, 노드에 문제가 발생했을 경우 재부팅이 필요할 수 있다. 
하지만 노드 스케쥴링에 의해서 Pod 들이 기동되어 있는 상태이기 때문에 최초에 evict 후 작업하지 않으면 작업 내용이 손실될 수 있다.
이러한 경우 사용하는 명령어로 drain, cordon, uncordon 이 있다.

 

drain

drain 은 물을 빼다 라는 뜻으로, 특정 노드를 지정해서 drain 명령어를 사용하면 노드 내부에 있는 Pod 를 모두 빼내게 된다. 즉 모든 Pod 를 빼내어 특정 Kubernetes 노드를 클러스터에서 안전하게 제거하기 위한 명령어 이다.
하지만 아래와 같이 Daemonset 은 비울 수 없다는 경고가 나온다. 이때 사용하는 옵션이--ignore-daemonsets 이다.

drain 을 수행하면 맨위에 cordoned 라는 문구가 나오는데, 해당 노드에 더 이상 Pod 를 스케쥴링 하지 않도록 지정을 최우선으로 한다고 볼 수 있다.
노드의 Pod 를 비우고 있는데, 새로운 Pod 가 들어오면 곤란할 수 있기 때문에 가장 먼저 스케쥴링을 막는 것이다.

--ignore-daemonsets 옵션을 주었는데, 각 노드에는 노드마다 기동되어 있는 daemonset Pod 들이 있다.
아래 로그에서는 kube-flannel, kube-proxy 등이 이에 해당하는데, 해당 Pod 들은 daemonset 이기 때문에 다른 노드에도 기동이 되어 있어서, evict 할 수 없어서 아래와 같이 에러 로그가 발생하는 것이다.
그렇기 때문에 --ignore-daemonsets 옵션을 주어 daemonset은 무시하라고 지정해주는 것이다.

drain 을 수행하면 node01 에 수행하고 있던 Pod 들이 다른 Node 로 evict 된 것을 알 수 있다.   

controlplane ~ ➜  kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE   IP           NODE           NOMINATED NODE   READINESS GATES
blue-69968556cc-4xxw8   1/1     Running   0          20m   172.17.0.4   controlplane   <none>           <none>
blue-69968556cc-jj8s4   1/1     Running   0          20m   172.17.1.3   node01         <none>           <none>
blue-69968556cc-vn5j9   1/1     Running   0          20m   172.17.1.2   node01         <none>           <none>

controlplane ~ ➜  kubectl drain node01 --ignore-daemonsets
node/node01 cordoned
Warning: ignoring DaemonSet-managed Pods: kube-flannel/kube-flannel-ds-82dsv, kube-system/kube-proxy-gj7kk
evicting pod default/blue-69968556cc-vn5j9
evicting pod default/blue-69968556cc-jj8s4
pod/blue-69968556cc-jj8s4 evicted
pod/blue-69968556cc-vn5j9 evicted
node/node01 drained

 

그 외에 cannot delete Pods that declare no controller 라고 표시 되는 Pod 가 있다.
이러한 Pod 는 --force 옵션을 줄 수 있는데, 이러한 Pod 는 replicaset 등으로 관리되고 있지 않은 Pod 라고 볼 수 있다.

즉 drain 을 통해 evict 되면 다른 노드에서 다시 스케쥴링을 해줄 컨트롤러가 없어서, 영원히 해당 파드를 잃게 된다.
그렇기 때문에 이러한 상황에서 drain 은 신중하게 진행이 필요하다.   

controlplane ~ ✖ kubectl drain node01 --ignore-daemonsets
node/node01 cordoned
error: unable to drain node "node01" due to error: cannot delete cannot delete Pods that declare no controller (use --force to override): default/hr-app, continuing command...
There are pending nodes to be drained:
 node01
cannot delete cannot delete Pods that declare no controller (use --force to override): default/hr-app

 

cordon

cordon 은 해당 노드에 스케쥴링이되지 않도록 설정하는 옵션이다.
명령어를 수행하면 해당 노드 조회 시 status 에 SchedulingDisabled 로 표시되며 새로운 Pod 는 더이상 스케쥴링 되지 않는다.
노드에 문제가 생겼거나, 혹은 유지보수로 작업이 필요할 경우와
중요한 노드가 기동 중이어서 다른 Pod 로 인해 리소스를 나눠 쓰지 않도록 하는 경우에 사용할 수 있다.  

controlplane ~ ✖ kubectl cordon node01
node/node01 cordoned

 

uncordon

cordon 이 새로운 Pod 의 스케쥴링을 막았다면 uncordon 은 다시 새로운 Pod 를 허용하는 명령어이다.
하지만 drain 을 한 상태라 기존 Pod 가 evict 된 상태라면, uncordon 을 한다고 Pod 가 다시 재 분배 되지는 않는다.
새로운 Pod 가 기동될 때 해당 노드에 스케쥴링되기 때문에 자동으로 밸런싱 되지 않는다는 특징이 있다.  

controlplane ~ ✖ kubectl get node
NAME           STATUS                     ROLES           AGE   VERSION
controlplane   Ready                      control-plane   24m   v1.32.0
node01         Ready,SchedulingDisabled   <none>          24m   v1.32.0
controlplane ~ ✖ kubectl uncordon node01
node/node01 uncordoned

controlplane ~ ➜  kubectl get node
NAME           STATUS   ROLES           AGE   VERSION
controlplane   Ready    control-plane   25m   v1.32.0
node01         Ready    <none>          24m   v1.32.0

 

반응형
저작자표시 (새창열림)

'DevOps > ✏️ Cloud' 카테고리의 다른 글

Docker Networking  (1) 2025.05.16
Network Namespace  (1) 2025.05.15
Multi-Container (init Container)  (0) 2025.03.26
K8S Controller (ReplicaSet, Deployment)  (0) 2024.12.11
grafana 에 prometheus 연결하기  (0) 2024.12.08
'DevOps/✏️ Cloud' 카테고리의 다른 글
  • Docker Networking
  • Network Namespace
  • Multi-Container (init Container)
  • K8S Controller (ReplicaSet, Deployment)
자동화를 꿈꿉니다.
자동화를 꿈꿉니다.
DevOps 개발자
  • 자동화를 꿈꿉니다.
    데봅스 성장기
    자동화를 꿈꿉니다.
  • 전체
    오늘
    어제
    • 분류 전체보기 (29)
      • DevOps (29)
        • ✏️ Cloud (12)
        • ✏️ CICD (11)
        • ✏️ Mac (6)
      • 경제 (0)
      • 운동 (0)
  • 블로그 메뉴

    • 홈
  • hELLO· Designed By정상우.v4.10.3
자동화를 꿈꿉니다.
drain, cordon, uncordon 명령
상단으로

티스토리툴바