Skip to content

Commit cf28aae

Browse files
committed
add graceful shutdown for all api endpoints
1 parent 4a0028b commit cf28aae

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

templates/deployments.yaml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ spec:
9797
mountPath: /post-start.sh
9898
subPath: post-start.sh
9999
lifecycle:
100+
preStop:
101+
exec: # https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da
102+
# kubeproxy and kubelet both race
103+
# wait a bit to ensure kubeproxy has removed the iptables rule.
104+
command: [ "sleep", {{ .Values.st2.st2auth.preStopSleep | default 10 }} ]
100105
postStart:
101106
exec:
102107
command: ["/bin/bash", "/post-start.sh"]
@@ -223,8 +228,10 @@ spec:
223228
subPath: post-start.sh
224229
lifecycle:
225230
preStop:
226-
exec:
227-
command: [ "sleep", {{ .Values.st2.st2api.preStopSleep }} ]
231+
exec: # https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da
232+
# kubeproxy and kubelet both race
233+
# wait a bit to ensure kubeproxy has removed the iptables rule.
234+
command: [ "sleep", {{ .Values.st2.st2api.preStopSleep | default 10 }} ]
228235
postStart:
229236
exec:
230237
command: ["/bin/bash", "/post-start.sh"]
@@ -310,6 +317,7 @@ spec:
310317
initContainers:
311318
{{- include "stackstorm-ha.init-containers-wait-for-db" . | nindent 6 }}
312319
{{- include "stackstorm-ha.init-containers-wait-for-mq" . | nindent 6 }}
320+
terminationGracePeriodSeconds: {{ .Values.st2workflowengine.terminationGracePeriodSeconds | default 30 }}
313321
containers:
314322
- name: st2stream
315323
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2stream:{{ tpl (.Values.st2stream.image.tag | default .Values.image.tag) . }}'
@@ -342,6 +350,11 @@ spec:
342350
mountPath: /post-start.sh
343351
subPath: post-start.sh
344352
lifecycle:
353+
preStop:
354+
exec: # https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da
355+
# kubeproxy and kubelet both race
356+
# wait a bit to ensure kubeproxy has removed the iptables rule.
357+
command: [ "sleep", {{ .Values.st2.st2api.preStopSleep | default 10 }} ]
345358
postStart:
346359
exec:
347360
command: ["/bin/bash", "/post-start.sh"]
@@ -410,6 +423,7 @@ spec:
410423
{{- if .Values.image.pullSecret }}
411424
- name: {{ .Values.image.pullSecret }}
412425
{{- end }}
426+
terminationGracePeriodSeconds: {{ .Values.st2api.terminationGracePeriodSeconds | default 30 }}
413427
containers:
414428
- name: st2web
415429
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2web:{{ tpl (.Values.st2web.image.tag | default .Values.image.tag) . }}'
@@ -419,6 +433,12 @@ spec:
419433
{{- end }}
420434
ports:
421435
- containerPort: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary 443 80 }}
436+
lifecycle:
437+
preStop:
438+
exec: # https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da
439+
# kubeproxy and kubelet both race
440+
# wait a bit to ensure kubeproxy has removed the iptables rule.
441+
command: [ "sleep", {{ .Values.st2.st2web.preStopSleep | default 10 }} ]
422442
# Probe to check if app is running. Failure will lead to a pod restart.
423443
livenessProbe:
424444
httpGet:

0 commit comments

Comments
 (0)