inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

미션 #2. Probe 응용과제

_hamtaro_o
0

조건

 

HPA minReplica 1로 바꾸기

kubectl patch -n anotherclass-123 hpa api-tester-1231-default -p '{"spec":{"minReplicas":1}}'

 

HPA와 Deployment의 관계 이해

https://kubernetes.io/ko/docs/tasks/run-application/horizontal-pod-autoscale/


 

문제 1

startupProbe가 실패 되도록 설정해서 Pod가 무한 재기동 상태가 되도록 설정해 보세요.

 

풀이

startupProbe:
  httpGet:
    path: /startup
    port: 8080
    scheme: HTTP
  timeoutSeconds: 1
  periodSeconds: 5
  successThreshold: 1
  failureThreshold: 1  # 기존 36에서 1로 변경


failureThreshold=1

무한 재시작 사이클

livenessProbe:
  httpGet:
    path: "/liveness"
    port: 8080
  periodSeconds: 60     # 60초마다 체크
  failureThreshold: 3   # 180초 후 Pod 재시작

readinessProbe:
  httpGet:
    path: "/readiness"
    port: 8080
  periodSeconds: 10     # 10초마다 체크
  failureThreshold: 3   # 30초 후 트래픽 차단

 

 

부하 시뮬레이션 API

// 부하 증가 API - (App 내부 isAppReady와 isAppLive를 False로 바꿈)
curl http://192.168.56.30:31231/server-load-on

// 외부 API 실패
curl http://192.168.56.30:31231/hello

// 부하 감소 API - (App 내부 isAppReady와 isAppLive를 True로 바꿈)
curl http://192.168.56.30:31231/server-load-off

 

로그 결과

 

정상 동작

14:15:17  readinessProbe is Succeed-> isAppReady: true
14:15:17  livenessProbe is Succeed-> isAppLive: true
...
...
14:16:17  readinessProbe is Succeed-> isAppReady: true  
14:16:17  livenessProbe is Succeed-> isAppLive: true

 

부하 발생 시점

14:16:20  [SyStem] The system load has occurred

 

Probe 실패

14:16:27  readinessProbe is Failed-> isAppReady: false
14:16:27  livenessProbe is Failed-> isAppLive: false

 

readinessProbe 3회 실패

14:16:20  부하 발생
14:16:27  첫 번째 [Kubernetes] readinessProbe is Failed-> [System] isAppReady: false
14:16:37  두 번째 [Kubernetes] readinessProbe is Failed-> [System] isAppReady: false
14:16:47  세 번째 [Kubernetes] readinessProbe is Failed-> [System] isAppReady: false

 

Pod 재시작

14:16:47  마지막 실패 로그
14:17:09  Spring Boot 애플리케이션 재시작 시작
14:17:09  .   ____          _            __ _ _
         /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
14:17:09  Spring Boot 시작
14:17:54  Tomcat started on port(s): 8080
14:17:58  startupProbe 실패
14:18:17  startupProbe 성공
14:18:47  readinessProbe 성공

 

확인

curl http://192.168.56.30:31231/hello
Welcome to Kubernetes

 

문제 3

Secret 파일(/usr/src/myapp/datasource/postgresql-info.yaml)이 존재하는지 체크하는 readinessProbe를 만들어 보세요. 

 

풀이

 

readinessProbe:
  exec:
    command: ["cat", "/usr/src/myapp/datasource/postgresql-info.yaml"]
  periodSeconds: 10
  failureThreshold: 3

livenessProbe:
  httpGet:
    path: "/liveness"
    port: 8080
  periodSeconds: 10
  failureThreshold: 3

 

Warning   Unhealthy                      
pod/api-tester-1231-564f9446c4-sfczc             

Readiness probe failed: 
cat: /usr/src/myapp/datasource/postgresql-info.yaml: No such file or directory

 

데브옵스 · 인프라 쿠버네티스 일프로

답변 0