From 7e3aeabdf6ef0dfccfa4209184c71c082fc316c5 Mon Sep 17 00:00:00 2001 From: Mulder Date: Fri, 7 Jun 2024 09:26:33 -0700 Subject: [PATCH] DBC22-2305 & DBC22-2312: Add healthcheck Adding Readiness probe for nginx and Django. --- compose/frontend/default.conf | 7 +++++ compose/frontend/default_maintenance.txt | 7 +++++ .../_django/templates/django-deployment.yaml | 26 +++++++++++++++++++ .../_static/templates/static-deployment.yaml | 10 +++++++ infrastructure/main/values-dev.yaml | 8 +++--- infrastructure/main/values-prod.yaml | 6 ++--- infrastructure/main/values-test.yaml | 8 +++--- infrastructure/main/values-uat.yaml | 8 +++--- 8 files changed, 65 insertions(+), 15 deletions(-) diff --git a/compose/frontend/default.conf b/compose/frontend/default.conf index b4946b4c3..c07534422 100644 --- a/compose/frontend/default.conf +++ b/compose/frontend/default.conf @@ -116,6 +116,13 @@ server { proxy_cache_bypass $http_cachebypass; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; } + location /healthz { + access_log off; + add_header 'Content-Type' 'text/plain'; + allow 127.0.0.1; + deny all; + return 200 "healthy\n"; + } # redirect server error pages to the static page /50x.html # diff --git a/compose/frontend/default_maintenance.txt b/compose/frontend/default_maintenance.txt index 08ef1dd53..b2805639c 100644 --- a/compose/frontend/default_maintenance.txt +++ b/compose/frontend/default_maintenance.txt @@ -42,6 +42,13 @@ server { index maintenance.html; try_files $uri $uri/ /maintenance.html; } + location /healthz { + access_log off; + add_header 'Content-Type' 'text/plain'; + allow 127.0.0.1; + deny all; + return 200 "healthy\n"; + } # redirect server error pages to the static page /50x.html # diff --git a/infrastructure/_django/templates/django-deployment.yaml b/infrastructure/_django/templates/django-deployment.yaml index 61e7c19ed..368552aba 100644 --- a/infrastructure/_django/templates/django-deployment.yaml +++ b/infrastructure/_django/templates/django-deployment.yaml @@ -102,6 +102,32 @@ spec: terminationMessagePolicy: File image: >- {{ .Values.image.repository }}:{{ .Values.image.tag }} + readinessProbe: + httpGet: + path: /healthcheck/ + port: 8000 + scheme: HTTP + httpHeaders: + - name: host + value: localhost + initialDelaySeconds: 10 + timeoutSeconds: 5 + periodSeconds: 10 + successThreshold: 1 + failureThreshold: 5 + livenessProbe: + httpGet: + path: /healthcheck/ + port: 8000 + scheme: HTTP + httpHeaders: + - name: host + value: localhost + initialDelaySeconds: 60 + timeoutSeconds: 5 + periodSeconds: 60 + successThreshold: 1 + failureThreshold: 3 affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: diff --git a/infrastructure/_static/templates/static-deployment.yaml b/infrastructure/_static/templates/static-deployment.yaml index 965e0bf13..dd2defb73 100644 --- a/infrastructure/_static/templates/static-deployment.yaml +++ b/infrastructure/_static/templates/static-deployment.yaml @@ -57,6 +57,16 @@ spec: type: RuntimeDefault runAsNonRoot: true allowPrivilegeEscalation: false + readinessProbe: + httpGet: + path: /healthz + port: 3000 + scheme: HTTP + initialDelaySeconds: 5 + timeoutSeconds: 1 + periodSeconds: 5 + successThreshold: 1 + failureThreshold: 3 affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: diff --git a/infrastructure/main/values-dev.yaml b/infrastructure/main/values-dev.yaml index b4a9137fb..8b4973de1 100644 --- a/infrastructure/main/values-dev.yaml +++ b/infrastructure/main/values-dev.yaml @@ -12,7 +12,7 @@ django: resources: requests: cpu: 20m - memory: 250Mi + memory: 300Mi limits: cpu: 500m memory: 350Mi @@ -48,11 +48,11 @@ tasks: deployment: resources: requests: - cpu: 100m - memory: 200Mi + cpu: 300m + memory: 250Mi limits: cpu: 500m - memory: 250Mi + memory: 300Mi volumes: claimName: dev-django-app-images env: diff --git a/infrastructure/main/values-prod.yaml b/infrastructure/main/values-prod.yaml index e4d0849b2..ef9c6008e 100644 --- a/infrastructure/main/values-prod.yaml +++ b/infrastructure/main/values-prod.yaml @@ -12,7 +12,7 @@ django: resources: requests: cpu: 50m - memory: 250Mi + memory: 300Mi limits: cpu: 1000m memory: 350Mi @@ -48,10 +48,10 @@ tasks: resources: requests: cpu: 350m - memory: 200Mi + memory: 250Mi limits: cpu: 750m - memory: 250Mi + memory: 300Mi volumes: claimName: prod-django-app-images env: diff --git a/infrastructure/main/values-test.yaml b/infrastructure/main/values-test.yaml index 3020a6502..4c844c2a6 100644 --- a/infrastructure/main/values-test.yaml +++ b/infrastructure/main/values-test.yaml @@ -12,7 +12,7 @@ django: resources: requests: cpu: 20m - memory: 250Mi + memory: 300Mi limits: cpu: 500m memory: 350Mi @@ -47,11 +47,11 @@ tasks: deployment: resources: requests: - cpu: 100m - memory: 200Mi + cpu: 300m + memory: 250Mi limits: cpu: 500m - memory: 250Mi + memory: 300Mi volumes: claimName: test-django-app-images env: diff --git a/infrastructure/main/values-uat.yaml b/infrastructure/main/values-uat.yaml index af8f46cb5..d8382c9a0 100644 --- a/infrastructure/main/values-uat.yaml +++ b/infrastructure/main/values-uat.yaml @@ -12,7 +12,7 @@ django: resources: requests: cpu: 50m - memory: 250Mi + memory: 300Mi limits: cpu: 1000m memory: 350Mi @@ -47,11 +47,11 @@ tasks: deployment: resources: requests: - cpu: 200m - memory: 200Mi + cpu: 350m + memory: 250Mi limits: cpu: 750m - memory: 250Mi + memory: 300Mi volumes: claimName: uat-django-app-images env: