apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  namespace: onepanel
spec:
  selector:
    matchLabels:
      app: postgres
  serviceName: "postgres-svc"
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      terminationGracePeriodSeconds: 10
      containers:
        - name: postgres
          image: postgres:13.4
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              valueFrom:
                configMapKeyRef:
                  name: onepanel
                  key: databaseName
                  optional: false
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: onepanel
                  key: databaseUsername
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: onepanel
                  key: databasePassword
          volumeMounts:
            - name: postgres-pv-claim
              mountPath: /var/lib/postgresql/data
              subPath: postgres
  volumeClaimTemplates:
    - metadata:
        name: postgres-pv-claim
        labels:
          app: postgres
      spec:
        storageClassName: onepanel
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 10Gi