[AAI] Added Rolling Update Strategy to traversal 44/123544/5
authorM.Hosnidokht <mohammad.hosnidokht@yoppworks.com>
Wed, 25 Aug 2021 13:08:40 +0000 (09:08 -0400)
committerM.Hosnidokht <mohammad.hosnidokht@yoppworks.com>
Fri, 3 Sep 2021 23:25:21 +0000 (19:25 -0400)
Addded preStop hook to let long-running tasks be finished
before the SIGTERM is invoked

Issue-ID: AAI-3368
Signed-off-by: Mohammad Hosnidokht <mohammad.hosnidokht@yoppworks.com>
Change-Id: I7925c622f29b800c19cc7931a951f29083561cc1

kubernetes/aai/components/aai-traversal/templates/deployment.yaml
kubernetes/aai/components/aai-traversal/values.yaml

index 037f811..277fb4b 100644 (file)
@@ -29,6 +29,12 @@ metadata:
     heritage: {{ .Release.Service }}
 spec:
   replicas: {{ .Values.replicaCount }}
+  minReadySeconds: {{ .Values.minReadySeconds }}
+  strategy:
+    type: {{ .Values.updateStrategy.type }}
+    rollingUpdate:
+      maxUnavailable: {{ .Values.updateStrategy.maxUnavailable }}
+      maxSurge: {{ .Values.updateStrategy.maxSurge }}
   selector:
     matchLabels:
       app: {{ include "common.name" . }}
@@ -91,6 +97,7 @@ spec:
       {{- end }}
     spec:
       hostname: aai-traversal
+      terminationGracePeriodSeconds: {{ .Values.service.terminationGracePeriodSeconds }}
       initContainers: {{ include "common.certInitializer.initContainer" . | nindent 6 }}
       - command:
         - /app/ready.py
@@ -144,6 +151,10 @@ spec:
           value: {{ .Values.global.config.userId | quote }}
         - name: LOCAL_GROUP_ID
           value: {{ .Values.global.config.groupId | quote }}
+        - name: INTERNAL_PORT_1
+          value: {{ .Values.service.internalPort | quote }}
+        - name: INTERNAL_PORT_2
+          value: {{ .Values.service.internalPort2 | quote }}
         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
         - mountPath: /etc/localtime
           name: localtime
@@ -194,6 +205,18 @@ spec:
         ports:
         - containerPort: {{ .Values.service.internalPort }}
         - containerPort: {{ .Values.service.internalPort2 }}
+        lifecycle:
+          # wait for active requests (long-running tasks) to be finished
+          # Before the SIGTERM is invoked, Kubernetes exposes a preStop hook in the Pod.
+          preStop:
+            exec:
+              command:
+                - sh
+                - -c
+                - |
+                  while (netstat -an | grep ESTABLISHED | grep -e $INTERNAL_PORT_1 -e $INTERNAL_PORT_2)
+                  do sleep 10
+                  done
         # disable liveness probe when breakpoints set in debugger
         # so K8s doesn't restart unresponsive container
         {{ if .Values.liveness.enabled }}
index 297de15..7ad9600 100644 (file)
@@ -145,6 +145,14 @@ pullPolicy: Always
 restartPolicy: Always
 flavor: small
 flavorOverride: small
+# the minimum number of seconds that a newly created Pod should be ready
+minReadySeconds: 30
+updateStrategy:
+  type: RollingUpdate
+  # The number of pods that can be unavailable during the update process
+  maxUnavailable: 0
+  # The number of pods that can be created above the desired amount of pods during an update
+  maxSurge: 1
 
 api_list:
   - 11
@@ -245,6 +253,7 @@ service:
   internalPort: 8446
   portName2: aai-traversal-5005
   internalPort2: 5005
+  terminationGracePeriodSeconds: 120
 
 ingress:
   enabled: false