apiVersion: apps/v1
kind: Deployment
metadata:
    name: postgresql-db
    labels:
        app: postgresql-db
spec:
    selector:
        matchLabels:
            app: postgresql-db
    strategy:
        type: Recreate
    template:
        metadata:
            labels:
                app: postgresql-db
        spec:
            containers:
                - name: postgresql-db
                  image: postgres:13-alpine
                  ports:
                      - containerPort: 5432
                        name: postgresql-port
                  volumeMounts:
                      - name: postgresql-persistent-storage
                        mountPath: /var/lib/postgresql
                      - name: sql-init
                        mountPath: /docker-entrypoint-initdb.d
                  env:
                      - name: POSTGRES_USER
                        valueFrom:
                            secretKeyRef:
                                name: secret-postgresql-db
                                key: postgres-user
                      - name: POSTGRES_PASSWORD
                        valueFrom:
                            secretKeyRef:
                                name: secret-postgresql-db
                                key: postgres-password
            volumes:
                - name: postgresql-persistent-storage
                  persistentVolumeClaim:
                      claimName: postgresql-persistent-volume-claim
                - name: sql-init
                  configMap:
                      name: init-sql-config
