From 61bd2cd37af2ec801f5b28ffc348e74189103d28 Mon Sep 17 00:00:00 2001 From: Brazing Technology Date: Wed, 29 Apr 2026 11:27:18 +0530 Subject: [PATCH] feat(k8s): PV, PVC, StatefulSet for postgres --- statefulset.yaml | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 statefulset.yaml diff --git a/statefulset.yaml b/statefulset.yaml new file mode 100644 index 0000000..a1bfb9d --- /dev/null +++ b/statefulset.yaml @@ -0,0 +1,98 @@ +# 1. PersistentVolume — cluster-scoped, hostPath on minikube node +apiVersion: v1 +kind: PersistentVolume +metadata: + name: db-pv + labels: + app: db +spec: + capacity: + storage: 1Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + storageClassName: manual + hostPath: + path: /mnt/data/taskapp-db + type: DirectoryOrCreate + +--- +# 2. PersistentVolumeClaim — namespaced, binds to db-pv +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: db-pvc + namespace: taskapp +spec: + accessModes: + - ReadWriteOnce + storageClassName: manual + resources: + requests: + storage: 1Gi + selector: + matchLabels: + app: db + +--- +# 3. StatefulSet — Postgres +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: db + namespace: taskapp +spec: + serviceName: db # references the headless Service in service.yaml + replicas: 1 + selector: + matchLabels: + app: db + template: + metadata: + labels: + app: db + spec: + containers: + - name: postgres + image: postgres:15 + ports: + - containerPort: 5432 + name: postgres + envFrom: + - secretRef: + name: db-credentials + env: + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + volumeMounts: + - name: db-storage + mountPath: /var/lib/postgresql/data + resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 500m + memory: 512Mi + readinessProbe: + exec: + command: + - sh + - -c + - 'pg_isready -U "$POSTGRES_USER"' + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 3 + livenessProbe: + exec: + command: + - sh + - -c + - 'pg_isready -U "$POSTGRES_USER"' + initialDelaySeconds: 10 + periodSeconds: 10 + timeoutSeconds: 3 + volumes: + - name: db-storage + persistentVolumeClaim: + claimName: db-pvc