apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgresql-db
  namespace: postgresql-system

spec:
  serviceName: postgresql-db-service
  selector:
    matchLabels:
      app: postgresql-db
  replicas: 1
  template:
    metadata:
      labels:
        app: postgresql-db
    spec:
      containers:
        - name: postgresql-db
          image: postgres:alpine3.14
          volumeMounts:
            - name: postgresql-mount
              mountPath: /data
              subPath: programs/postgres
          env:
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: postgresql-secrets
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgresql-secrets
                  key: POSTGRES_PASSWORD
            - name: PGDATA
              value: /data/pgdata
      volumes:
      - name: postgresql-mount
        persistentVolumeClaim:
          claimName: postgresql-pvc