전공영역 공부 기록

쿠버네티스 node not ready이면 어떤 일이 일어날까?

악분 2025. 2. 9. 14:30
반응형

1.  개요

이 글은 쿠버네티스 node가 not ready일 때, 내부적으로 어떤 동작을 하는지 설명합니다.

 

2.  요약

  1. not ready인 node에 pod가 스케쥴링되지 않도록 taint를 설정
  2. not ready 상태가 5분이 지나면 pod를 eviction

 

3.  node가 not ready가 되면

3.1.  node taint 업데이트

쿠버네티스는 not ready가 된 node에 pod가 스케쥴링 되지 않도록, node에 taint를 설정합니다. taint는 node.kubernetes.io/unreachable:NoExecute와 node.kubernetes.io/unreachable:NoSchedule를 설정합니다.

kubectl describe node {not ready node} | grep -i "Taints:" -A 4

 

3.2.  5분뒤에 pod가 eviction

node가 not ready상태가 5분이 지나면, taint eviction controller가 not ready node에 실행중인 pod를 eviction합니다.

 

아래 그림은 node가 not ready상태가 5분이 지난 후 pod상태입니다. Terminating상태 pod가 eviction된 pod입니다. 그리고 Running 상태 pod가 eviction 실행 후 생성된 pod입니다.

 

4.  pod eviction 시간이 왜 5분일까?

4.1.   pod eviction 시간 확인 방법

pod eviction 시간은 tolderationSeconds설정에 의존합니다. tolderationSeconds설정 pod tolderations에 있고 디폴트로 300s(5분)으로 설정되어 있습니다.

kubectl get pod -oyaml | grep tolerations -A8

 

4.2.  누가 tolerationsSeconds을 설정했을까?

Admission controller이 pod에 tolerationsSeconds를 설정합니다. pod에 tolerationsSeconds가 설정되지 않으면 Admission controller은 디폴트로 300s를 설정합니다.

admission controller의 특징이 궁금하신 분은 이전 저의 블로그를 참고해주세요.
- admission controller 블로그 링크: https://malwareanalysis.tistory.com/704

 

쿠버네티스 Admission controller

1. Admission controller이란? 쿠버네티스 Admission controller는 말 그대로 Admission 기능을 수행합니다. Admission이라는 영어 단어는 허가를 의미하며, 쿠버네티스 세계에서 Admission은, 쿠버네티스 요청을 수

malwareanalysis.tistory.com

 

 

4.3.  tolerationSeconds 어떻게 바꿀 수 있을까?

kube API server 실행 인자를 변경하거나 직접 pod tolerations에 tolerationSeconds를 설정하면 됩니다.

API server server 실행 인자는 2개를 변경해야 합니다.

  1. default-not-ready-toleration-seconds
  2. default-unreachable-toleration-seconds

 

위 2개 인자를 설정하지 않으면 디폴트로 300s가 설정됩니다.

 

5.   not ready node때문에 실무에서 일어날 수 있는 일

네트워크 등의 이유(AZ 장애 등)로 kube API server와 worker node가 5분이상 통신이 안되는 상황이 정말 드물게 발생합니다. 특히 네트워크 오류가 발생하면 서비스 장애 확률이 올라갑니다.

 

네트워크 오류가 5분 이상 지속되면 not ready인 node의 모든 pod가 evcition됩니다. PDB설정이 되어 있다면 모든 pod가 eviction되지 않습니다.

 

네트워크 오류가 해결될 때까지 eviction된 pod는 스케쥴링 되지 않습니다. PDB설정때문에 남아 있는 pod가 모든 기능을 담당합니다. 남아 있는 pod는 자연스럽게 부하가 걸려 서비스가 늦게 처리되거나 서비스 장애가 발생합니다.

 

6.  부록: 아키텍처

아키텍처 챕터에서는 node가 not ready될 때, 쿠버네티스가 실행하는 2가지 동작을 누가 담당하는지 살펴봅니다.

  1. not ready node에 taint가 설정
  2. not ready node가 5분이 지나면

 

쿠버네티스 KEP-3902문서에 node가 not ready일 때 컨트롤러의 아키텍처 설명이 있습니다.

 

 

node가 not ready되면 2개 controller가 관여합니다.

  1. NodeLifeCycleController가 not ready에 taint를 설정합니다.
  2. TaintEvictionController가 pod를 eviction을 합니다.pod eviction은 NodeLifeCycleController이 담당했었는데, 아래 PR 이후 TaintEvictionController이 담당하도록 변경되었습니다.

 

7.  부록 디버깅

7.1.  evcition된 pod

pod가 eviction되면 pod 상태에 DeletionByTaintManager필드가 true로 업데이트 됩니다.

kubectl get pod {eviction pod 확인} -oyaml | grep DeletionByTaintManager -A2 -B3

 

7.2.  쿠버네티스 events

쿠버네티스 events에는 node not ready, pod eviction이 보입니다. node not ready 상태가 5분이 지나면 pod가 eviction되어 새로운 pod가 스케쥴링됩니다. 그리고 eviction된 pod의 상태가 업데이트됩니다.

kubectl get events --sort-by='.lastTimestamp' -o custom-columns="LAST_TIMESTAMP:.lastTimestamp,NAME:.metadata.name,REASON:.reason,MESSAGE:.message"

 

7.3.  controller manager 로그

controller manager pod 로그에서는 taint eviction controller가 pod를 eviction 동작이 보입니다.

kubectl -n kube-system logs -f -l component=kube-controller-manager

 

8.  부록: 실습

저의 github에 공개되어 있습니다

 

참고자료

반응형