apiVersion: v1 kind: PersistentVolumeClaim metadata: name: ins-landing-page-postgres namespace: ins-landing-page spec: storageClassName: longhorn # ReadWriteOnce, not ReadWriteMany: Longhorn serves RWX over NFS, which a database should not # write through. One replica mounts it. accessModes: - ReadWriteOnce resources: requests: storage: 2Gi --- apiVersion: v1 kind: Service metadata: name: postgres namespace: ins-landing-page spec: clusterIP: None selector: app: postgres ports: - name: postgres port: 5432 --- apiVersion: apps/v1 kind: StatefulSet metadata: name: postgres namespace: ins-landing-page spec: serviceName: postgres replicas: 1 selector: matchLabels: app: postgres template: metadata: labels: app: postgres spec: terminationGracePeriodSeconds: 60 containers: - name: postgres image: postgres:18 env: - name: POSTGRES_USER value: ins - name: POSTGRES_DB value: ins - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: name: ins-landing-page-db key: POSTGRES_PASSWORD ports: - name: postgres containerPort: 5432 # Allow up to 5 minutes for crash recovery before liveness can restart the pod. startupProbe: exec: command: ["pg_isready", "-U", "ins", "-d", "ins"] periodSeconds: 10 failureThreshold: 30 readinessProbe: exec: command: ["pg_isready", "-U", "ins", "-d", "ins"] periodSeconds: 5 livenessProbe: exec: command: ["pg_isready", "-U", "ins", "-d", "ins"] periodSeconds: 20 failureThreshold: 6 resources: requests: cpu: 100m memory: 128Mi limits: memory: 1Gi volumeMounts: # postgres:18 keeps its data under /var/lib/postgresql//docker. - name: data mountPath: /var/lib/postgresql volumes: - name: data persistentVolumeClaim: claimName: ins-landing-page-postgres