🩺 Kubernetes livenessProbe & readinessProbe 정리

2026. 2. 22. 08:02k8s

Kubernetes에서 Probe는

“컨테이너가 정상적으로 동작하는지 판단하는 메커니즘”

이다.

Probe는 3가지가 있다.

  • livenessProbe
  • readinessProbe
  • startupProbe (참고용)

이번 글에서는 liveness / readiness를 중심으로 설명한다.


1️⃣ livenessProbe (생존 체크)

📌 의미

“컨테이너가 죽었는가?”

  • 실패하면 → 컨테이너를 재시작(Restart) 한다.
  • kubelet이 판단한다.

📌 동작 흐름

Probe 실패
   ↓
failureThreshold 초과
   ↓
컨테이너 restart

📌 예시 (HTTP 방식)

livenessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 5
  failureThreshold: 3

의미

  • 5초 후 시작
  • 5초마다 검사
  • 3번 연속 실패 시 restart

📌 exec 방식

livenessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy

📌 TCP 방식

livenessProbe:
  tcpSocket:
    port: 80

2️⃣ readinessProbe (준비 상태 체크)

📌 의미

“트래픽을 받아도 되는 상태인가?”

  • 실패하면 → 재시작하지 않음
  • 대신 Service의 Endpoints에서 제거됨

즉, 트래픽만 차단.


📌 동작 흐름

Probe 실패
   ↓
Service Endpoint 제거
   ↓
트래픽 차단

📌 예시

readinessProbe:
  httpGet:
    path: /health
    port: 80
  initialDelaySeconds: 3
  periodSeconds: 5

🔥 핵심 차이 비교

구분 livenessProbe readinessProbe
목적 죽었는지 확인 준비되었는지 확인
실패 시 컨테이너 재시작 트래픽만 차단
Service 영향 없음 Endpoint 제거
주 용도 Deadlock, 무한루프 DB 연결 대기, 초기화 대기

📊 실제 상황 예시

상황 1 — DB 연결 안 됨

  • readiness 실패
  • Service에서 제외
  • 재시작하지 않음

상황 2 — 애플리케이션 deadlock

  • liveness 실패
  • 컨테이너 restart

⚙️ 주요 설정 값 설명

initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 1
failureThreshold: 3
successThreshold: 1
항목 의미
initialDelaySeconds 첫 검사까지 대기 시간
periodSeconds 검사 주기
timeoutSeconds 응답 대기 시간
failureThreshold 몇 번 실패하면 실패로 판단
successThreshold 몇 번 성공해야 복구 판단

⚠️ 흔한 실수

❌ liveness를 너무 빨리 시작

앱이 아직 초기화 중인데 liveness가 먼저 동작 → 계속 재시작 → CrashLoopBackOff

해결:

  • initialDelaySeconds 늘리기
  • startupProbe 사용

❌ readiness 없이 운영

초기화 안 된 Pod에 트래픽 들어감 → 500 에러


🚀 추천 패턴 (웹 서비스 기준)

livenessProbe:
  httpGet:
    path: /healthz
    port: 80
  initialDelaySeconds: 10
  periodSeconds: 10

readinessProbe:
  httpGet:
    path: /ready
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 5
  • /healthz → 앱 살아있는지
  • /ready → DB/외부연동 준비됐는지

🧠 실무 관점 설계 가이드

상황 추천
웹 서버 HTTP probe
DB 서버 TCP probe
내부 상태 파일 exec probe
느린 시작 앱 startupProbe 추가

📌 startupProbe (참고)

느리게 시작하는 앱에서 사용

startupProbe:
  httpGet:
    path: /health
    port: 80
  failureThreshold: 30
  periodSeconds: 5
  • startupProbe 성공 전까지 liveness 무시
  • 초기 CrashLoop 방지

🏗️ 전체 동작 구조

Pod 생성
   ↓
startupProbe 통과
   ↓
readiness OK → 트래픽 수신
   ↓
liveness 실패 → 재시작