모든 강의 이미지 출처는 [인프런] 쿠버네티스 어나더 클래스(지상편) - Spring 1,2 입니다.
initialDelaySeconds
: Probe가 시작되기 전 대기 시간으로 default는 0초이다.periodSeconds
: Probe를 수행하는 빈도(초)로 기본값은 10초이다.timeoutSeconds
: Probe 타임아웃 시간(초)으로 기본값은 1초이다.successThreshold
: Probe가 실패한 후 성공으로 변경되기 위한 연속 성공횟수이다. 기본값은 1이다.failureThreshold
: Probe가 실패하면 Kubernetes는 failureThreshold 횟수 만큼 Container 재시작을 시도한다. 기본값은 3이다.▶ startup probe 동작 확인
[System] App is started
로그 출력 이전에는 startupProbe가 실패하고, API 호출 시에도 응답없음.[System] App is started
로그 출력 이후에는 startupProbe가 성공하고, API 호출 시에도 정상응답이 출력됨.▶ liveness & readeness probe 동작 확인
Quiz) startupProbe가 실패 되도록 설정해서 Pod가 무한 재기동 상태가 되도록 설정해 보세요.
▶ Startup Probe의 failureThreshold
값을 1로 설정하여 /startup API 호출이 1회만 실패해도 파드가 재시작하도록 한다.
startupProbe:
httpGet:
path: "/startup"
port: 8080
periodSeconds: 5
failureThreshold: 1
▶ 결과
# pod에 발생한 event 내용 확인
[root@k8s-master ~] kubectl events --for pod/{파드명} -n anotherclass-123
Quiz) 일시적 장애 상황(App 내부 부하 증가)가 시작 된 후, 30초 뒤에 트래픽이 중단되고, 3분 뒤에는 App이 재기동 되도록 설정해 보세요.
▶ Readiness Probe의 periodSeconds
값을 10, failureThreshold
값을 3으로 설정하여 30초 후, 서비스 대상에서 파드가 제외되도록 한다.
▶ Liveness Probe의 periodSeconds
값을 60, failureThreshold
값을 3으로 설정하여 3분 후, 파드가 재시작하도록 한다.
readinessProbe:
httpGet:
path: "/readiness"
port: 8080
periodSeconds: 10
failureThreshold: 3
livenessProbe:
httpGet:
path: "/liveness"
port: 8080
periodSeconds: 60
failureThreshold: 3
▶ 결과
# pod 목록 변화를 지속적으로 출력 (-w 옵션)
[root@k8s-master ~] kubectl get pods -n anotherclass-123 -w
Quiz) Secret 파일(/usr/src/myapp/datasource/postgresql-info.yaml)이 존재하는지 체크하는 readinessProbe를 만들어 보세요.
▶ 기존 파드에 /usr/src/myapp/datasource/postgresql-info.yaml 파일은 존재하기 때문에 readiness probe가 정상적으로 수행되는 것을 확인할 수 있다.
# pod 내 특정 파일 출력
kubectl exec -n anotherclass-123 -it {파드명} -- cat /usr/src/myapp/datasource/postgresql-info.yaml
▶ 따라서 존재하지 않는 /usr/src/myapp/datasource/postgresql-info2.yaml 파일로 readiness probe command를 변경하면 아래와 같이 실패하는 것을 확인할 수 있다.
# pod 내 존재하지 않는 파일 출력
kubectl exec -n anotherclass-123 -it {파드명} -- cat /usr/src/myapp/datasource/postgresql-info2.yaml
# pod에 발생한 event 내용 확인
[root@k8s-master ~] kubectl events --for pod/{파드명} -n anotherclass-123
▶ 결과