Skip to content

Commit c78bb7e

Browse files
authored
fix: app and envoy container not shutting down gracefully (#2155)
Signed-off-by: Alessandro Yuichi Okimoto <yuichijpn@gmail.com>
1 parent b2a5065 commit c78bb7e

File tree

29 files changed

+1068
-300
lines changed

29 files changed

+1068
-300
lines changed

docker-compose/config/nginx/bucketeer.conf

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ server {
109109
add_header X-Content-Type-Options nosniff;
110110
add_header X-XSS-Protection "1; mode=block";
111111

112-
# Health check endpoint
112+
# Health check endpoints
113113
location /health {
114114
proxy_pass https://api_health_backend;
115115
proxy_set_header Host $host;
@@ -118,6 +118,14 @@ server {
118118
proxy_set_header X-Forwarded-Proto $scheme;
119119
}
120120

121+
location /ready {
122+
proxy_pass https://api_health_backend;
123+
proxy_set_header Host $host;
124+
proxy_set_header X-Real-IP $remote_addr;
125+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
126+
proxy_set_header X-Forwarded-Proto $scheme;
127+
}
128+
121129
# API Gateway gRPC service (main API)
122130
location /bucketeer.gateway.Gateway {
123131
grpc_pass grpcs://api_grpc_backend;
@@ -192,7 +200,7 @@ server {
192200
return 204;
193201
}
194202

195-
# Health check endpoint
203+
# Health check endpoints
196204
location /health {
197205
proxy_pass https://web_health_backend;
198206
proxy_set_header Host $host;
@@ -201,6 +209,14 @@ server {
201209
proxy_set_header X-Forwarded-Proto $scheme;
202210
}
203211

212+
location /ready {
213+
proxy_pass https://web_health_backend;
214+
proxy_set_header Host $host;
215+
proxy_set_header X-Real-IP $remote_addr;
216+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
217+
proxy_set_header X-Forwarded-Proto $scheme;
218+
}
219+
204220
# gRPC/gRPC-Web service routes (backend handles both protocols)
205221
location /bucketeer.account.AccountService {
206222
if ($is_grpc_web = 1) {

manifests/bucketeer/charts/api/templates/backend-config.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ spec:
88
healthCheck:
99
requestPath: /health
1010
type: HTTP2
11-
timeoutSec: 40
11+
checkIntervalSec: 5
12+
timeoutSec: 5
13+
healthyThreshold: 1
14+
unhealthyThreshold: 1
15+
timeoutSec: 60
1216
connectionDraining:
1317
drainingTimeoutSec: 60
1418
{{- end }}

manifests/bucketeer/charts/api/templates/deployment.yaml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ spec:
2121
annotations:
2222
checksum/config: {{ include (print $.Template.BasePath "/envoy-configmap.yaml") . | sha256sum }}
2323
spec:
24+
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds | default 30 }}
2425
{{- with .Values.global.image.imagePullSecrets }}
2526
imagePullSecrets: {{- toYaml . | nindent 8 }}
2627
{{- end }}
@@ -145,6 +146,14 @@ spec:
145146
containerPort: {{ .Values.env.port }}
146147
- name: metrics
147148
containerPort: {{ .Values.env.metricsPort }}
149+
startupProbe:
150+
periodSeconds: {{ .Values.health.startupProbe.periodSeconds }}
151+
failureThreshold: {{ .Values.health.startupProbe.failureThreshold }}
152+
timeoutSeconds: {{ .Values.health.startupProbe.timeoutSeconds }}
153+
httpGet:
154+
path: /ready
155+
port: service
156+
scheme: HTTPS
148157
livenessProbe:
149158
initialDelaySeconds: {{ .Values.health.livenessProbe.initialDelaySeconds }}
150159
periodSeconds: {{ .Values.health.livenessProbe.periodSeconds }}
@@ -160,7 +169,7 @@ spec:
160169
failureThreshold: {{ .Values.health.readinessProbe.failureThreshold }}
161170
timeoutSeconds: {{ .Values.health.readinessProbe.timeoutSeconds }}
162171
httpGet:
163-
path: /health
172+
path: /ready
164173
port: service
165174
scheme: HTTPS
166175
resources:
@@ -172,9 +181,15 @@ spec:
172181
preStop:
173182
exec:
174183
command:
175-
- "/bin/sh"
176-
- "-c"
177-
- "wget -O- --post-data='{}' http://localhost:$ENVOY_ADMIN_PORT/healthcheck/fail; while [ $(netstat -plunt | grep tcp | grep -v envoy | wc -l) -ne 0 ]; do sleep 1; done;"
184+
- /bin/sh
185+
- -c
186+
- |
187+
admin_port={{ .Values.envoy.adminPort }}
188+
# Wait for load balancer propagation (must match app container propagation delay)
189+
sleep 15
190+
wget -q -T 1 -O- --method=POST --body-data='' \
191+
"http://localhost:${admin_port}/drain_listeners?graceful" || true
192+
exit 0
178193
command: ["envoy"]
179194
args:
180195
- "-c"
@@ -201,10 +216,19 @@ spec:
201216
containerPort: {{ .Values.envoy.port }}
202217
- name: admin
203218
containerPort: {{ .Values.envoy.adminPort }}
219+
startupProbe:
220+
periodSeconds: {{ .Values.health.startupProbe.periodSeconds }}
221+
failureThreshold: {{ .Values.health.startupProbe.failureThreshold }}
222+
timeoutSeconds: {{ .Values.health.startupProbe.timeoutSeconds }}
223+
httpGet:
224+
path: /ready
225+
port: admin
226+
scheme: HTTP
204227
livenessProbe:
205228
initialDelaySeconds: {{ .Values.health.livenessProbe.initialDelaySeconds }}
206229
periodSeconds: {{ .Values.health.livenessProbe.periodSeconds }}
207230
failureThreshold: {{ .Values.health.livenessProbe.failureThreshold }}
231+
timeoutSeconds: {{ .Values.health.livenessProbe.timeoutSeconds }}
208232
httpGet:
209233
path: /ready
210234
port: admin
@@ -213,11 +237,12 @@ spec:
213237
initialDelaySeconds: {{ .Values.health.readinessProbe.initialDelaySeconds }}
214238
periodSeconds: {{ .Values.health.readinessProbe.periodSeconds }}
215239
failureThreshold: {{ .Values.health.readinessProbe.failureThreshold }}
240+
timeoutSeconds: {{ .Values.health.readinessProbe.timeoutSeconds }}
216241
httpGet:
217242
path: /ready
218243
port: admin
219244
scheme: HTTP
220245
resources:
221246
{{ toYaml .Values.envoy.resources | indent 12 }}
222247
strategy:
223-
type: RollingUpdate
248+
{{ toYaml .Values.strategy | indent 4 }}

0 commit comments

Comments
 (0)