Kubernetes) Health check

Health check

Kuberntes에서도 애플리케이션의 상태를 모니터링하고 상태이상을 제어하기 위한 기능을 제공한다

Kuberntes에서는 이를 "Probe"라는 명칭으로 제공하고 있으며 각각 사용방법을 검토하여 목적에 맞게 활용할 수 있다.

Readiness probe

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: httpserver
  name: httpserver-testapp
spec:
  containers:
  - name: httpserver
    image: nginx/~~~
    readinessProbe: # readiness probe 설정
      httpGet:
        path: /healthz # /healthz 엔드포인트 대상
        port: 8080 # port 8080
      initialDelaySeconds: 5 # 첫번째 Probe 실행 전 5초를 대기한다.
      periodSeconds: 5 # 체크하는 시간 간격
  • Readiness probe는 pod가 요청을 처리할 수 있는 준비가 되어있는지 검토하는 헬스체크 방법
  • 헬스체크를 진행하는 과정에서 Pod의 응답이 실패하는 경우 "Service"의 엔드포인트에서 제거해 트래픽이 도달하지 않느낟.
  • 단, Pod도 종료되지 않고 계속 실행상태를 유지하게 되며, 트래픽을 받을 수 있는 상태가 되면 다음 헬스체크를 통해 검사 후 수신을 재개한다.
  • 전체 Pod에서 사용 가능한 Pod의 수가 줄어들게 되므로 모니터링 수단을 검토해야한다.

 

Liveness probe

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: httpserver
  name: httpserver-testapp
spec:
  containers:
  - name: httpserver
    image: nginx/~~~
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 5
  • Liveness probe는 모니터링 과정에서 Pod가 비정상적일 경우 Pod를 재시작 시킨다.
  • 단, 재시작으로 해결되지 않는 경우 재시작이 무한히 반복될 수 있어 주의가 필요하다.

 

Startup probe

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: httpserver
  name: httpserver-testapp
spec:
  containers:
  - name: httpserver
    image: nginx/~~~
    startupProbe:
      httpGet:
        path: /healthz
        port: liveness-port
      failureThreshold: 30
      periodSeconds: 10 # 최대 30초 * 10초 = 300초동안 컨테이너 작동을 기다림
  • Kuberntes 1.18 부터 도입된 기능
  • Pod의 초기 작동시에만 적용되는 Probe로 보통 초기 작동이 느린 애플리케이션이 사용된다.
    • Java 기반 대용량 데이터베이스 환경
    • 레거시 데이터베이스 시스템
    • 많은 의존성과 초기화가 필요하거나 대용량 모델의 파일을 로딩하는 경우
    • 기타 시작시 초기화 시간이 오래결리는 경우 등 다양한 사례
  • startupProbe가 시작할 때 까지 livenessProbe와 readinessProbe는 비활성화 된다.
    • 성공후에는 startupProbe가 비활성화 되고, 선언된 다른 Probe들이 작동하기 시작한다.
  • failureThreshold * periodSeconds = 최대 대기 시간이 된다.
    • periodSeconds: 헬스체크를 몇 초마다 수행할지
    • failureThreshold: 몇 번 실패까지 허용할지

'Infra > Kubernetes' 카테고리의 다른 글

Kubernetes) Affinity  (0) 2025.12.07