Istio Sidecar 시작 타이밍 (holdApplicationUntilProxyStarts)
문제 상황#
dev-webs Pod가 1/2 Running 상태로 멈춤. readiness probe가 context deadline exceeded 에러 발생.
증상#
kubectl get pods -n dev-webs
# NAME READY STATUS RESTARTS
# dev-api-gateway-xxx 1/2 Running 0
kubectl describe pod dev-api-gateway-xxx -n dev-webs
# Readiness probe failed: Get "http://10.x.x.x:8085/actuator/health/readiness": context deadline exceeded
원인 분석#
Istio sidecar(envoy-proxy)가 완전히 시작되기 전에 앱 컨테이너가 먼저 시작됨. 앱이 외부 서비스(DB, Redis 등)에 연결하려고 하면 sidecar가 아직 준비 안 되어서 실패.
[Pod 시작]
├── istio-init (완료)
├── app container (즉시 시작) <- DB 연결 시도
└── istio-proxy (아직 시작 중) <- 트래픽 처리 불가!
결과: app이 DB에 연결 못함 -> health check 실패 -> CrashLoopBackOff
해결#
deployment.yaml에 holdApplicationUntilProxyStarts annotation 추가:
# common-charts/apps/java-service/templates/deployment.yaml
template:
metadata:
annotations:
sidecar.istio.io/inject: "{{ .Values.istio.sidecar }}"
{{- if .Values.istio.sidecar }}
proxy.istio.io/config: '{"holdApplicationUntilProxyStarts": true}'
{{- end }}
동작 원리#
[Pod 시작 - holdApplicationUntilProxyStarts: true]
├── istio-init (완료)
├── istio-proxy (시작, ready 대기)
│ └── [sidecar ready!]
└── app container (sidecar ready 후 시작) <- 이제 DB 연결 가능
kubelet이 istio-proxy postStart hook 완료를 기다린 후 앱 컨테이너 시작.
주의사항#
- Istio 1.7+ 필요
- Pod 시작 시간이 약간 늘어남 (sidecar ready 대기)
- istio sidecar가 비활성화된 Pod에는 영향 없음
관련 파일#
common-charts/apps/java-service/templates/deployment.yamlcommon-charts/apps/ai-service/templates/deployment.yaml