apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  serviceName: postgres
  replicas: 2
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:13.1
        imagePullPolicy: "IfNotPresent"
        ports:
          - containerPort: 5432
        envFrom:
          - configMapRef:
              name: postgres-config
        env:
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: postgres-secret
              key: postgres-user
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: postgres-secret
              key: postgres-password
        volumeMounts:
        - name: postgredb
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: postgredb
        persistentVolumeClaim:
          claimName: postgres-pv-claim