
kubelet은 모든 노드의 pod을 관리, Health Check를 담당livenessProbe: 기본 상태는 SuccessreadinessProbe: 기본 상태는 SuccessstartupProbe: 설정되지 않으면 실행되지 않음⇒ Spring App에 대한 Probe 설정이 필요!
startupProbelivenessProbe와 readinessProbe가 실행됨.cf. startupProbe가 필요한 이유에 대한 참고자료
readinessProbelivenessProbeSpring Actuator 추가
Spring Actuator란?
- Spring Boot 애플리케이션의 모니터링과 관리를 위한 프로덕션 준비 기능을 제공하는 모듈
- 애플리케이션 상태 모니터링: 애플리케이션의 건강 상태(health), 메트릭 수집, HTTP 추적 등의 정보를 실시간으로 확인
build.gradle.ktsdependencies {
...
implementation("org.springframework.boot:spring-boot-starter-actuator")
...
}
http://localhost:8080/actuator에서 사용 가능한 엔드포인트 목록을 확인 가능/actuator/health 엔드포인트를 통해 애플리케이션의 Health를 확인 가능application.ymlmanagement.endpoint.health.probes.enabled = true로 k8s probe를 지원liveness, readiness를 지원하기 때문에 custom health group으로 startup을 추가(liveness와 동일)...
management:
endpoint:
health:
access: read_only # 읽기 전용
probes:
enabled: true # k8s Probe 지원 활성화(liveness. readiness)
show-details: never # 세부정보 노출 방지
group:
startup:
include:
- livenessState # startup 엔드포인트를 추가(liveness와 동일)
endpoints:
web:
exposure:
include: health # /actuator/health 엔드포인트만 노출
...
Deployment 설정spring-deployment.yaml에 probe 설정값을 추가spring-deployment.yaml# deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.app.name }}
namespace: {{ .Values.namespace }}
spec:
replicas: {{ .Values.deployment.replicas }}
revisionHistoryLimit: {{ .Values.deployment.revisionHistoryLimit }}
selector:
matchLabels:
app: {{ .Values.app.name }}
template:
metadata:
labels:
app: {{ .Values.app.name }}
spec:
containers:
- name: {{ .Values.app.name }}
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
ports:
- containerPort: {{ .Values.service.targetPort }}
resources:
limits:
cpu: {{ .Values.resources.limits.cpu }}
memory: {{ .Values.resources.limits.memory }}
requests:
cpu: {{ .Values.resources.requests.cpu }}
memory: {{ .Values.resources.requests.memory }}
envFrom:
- configMapRef:
name: {{ .Values.config.name }}
- secretRef:
name: {{ .Values.secret.name }}
# Probe 추가
startupProbe:
httpGet:
path: /actuator/health/startup
port: 8080
initialDelaySeconds: 10
failureThreshold: 20
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8080
initialDelaySeconds: 10
periodSeconds: 20
---
# 이하 생략
startup: 10초 후부터 최대 20번까지 실패를 허용 - 200초(20 × 기본 periodSeconds: 10초) 동안 실패해도 "아직 시작 중"으로 봐줌readiness: 5초 후부터 10초마다 /actuator/health/readiness 요청liveness: 10초 후부터 20초마다 /actuator/health/liveness 호출cf. startupProbe를 설정하는 또 다른 방법
Spring Actuator는startupProbe용 엔드포인트를 제공하지 않기 때문에 Spring 앱에서 별도의 설정이 필요했음- Spring앱을 설정하는 방식 대신
startupProbe자체를livenessProbe와 동일한 엔드포인트로 사용하는 설정 가능startupProbe: httpGet: path: /actuator/health/liveness # startup 대신 liveness 사용 권장 port: 8080 initialDelaySeconds: 10 failureThreshold: 20
values.yaml의 service.type을LoadBalancer가 아닌 NodePort로 변경
startupProbe가 실패한 로그를 확인 가능(이후 모든 Probe를 통과해 Healthy로 체크됨)