From 3e946b2b19e2a1a1ed9f629de980c145de3ce00a Mon Sep 17 00:00:00 2001 From: Simone Lazzaris Date: Thu, 24 Oct 2024 14:37:16 +0200 Subject: [PATCH] change db into a StatefulSet Changed the DB component into a stateful set. This avoid having two instances of the DB running *on the same data*, which can happen with a deployment (i.e., during an update/reconfiguration). Also, added a shutdown command to properly shut down the database, to prevent data corruption. --- .../templates/db/{deployment.yaml => statefulset.yaml} | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) rename charts/supabase/templates/db/{deployment.yaml => statefulset.yaml} (97%) diff --git a/charts/supabase/templates/db/deployment.yaml b/charts/supabase/templates/db/statefulset.yaml similarity index 97% rename from charts/supabase/templates/db/deployment.yaml rename to charts/supabase/templates/db/statefulset.yaml index 314842e..7506bc0 100644 --- a/charts/supabase/templates/db/deployment.yaml +++ b/charts/supabase/templates/db/statefulset.yaml @@ -1,6 +1,6 @@ {{- if .Values.db.enabled -}} apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: name: {{ include "supabase.db.fullname" . }} labels: @@ -58,6 +58,10 @@ spec: {{- toYaml .Values.db.securityContext | nindent 12 }} image: "{{ .Values.db.image.repository }}:{{ .Values.db.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.db.image.pullPolicy }} + lifecycle: + preStop: + exec: + command: ["/bin/sh", "-c", "pg_ctl -D /var/lib/postgres/data -w -t 60 -m fast stop"] env: {{- range $key, $value := .Values.db.environment }} - name: {{ $key }} @@ -170,4 +174,4 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }}