apiVersion: apps/v1
kind: Deployment
metadata:
    name: postgres-deployment
spec:
    replicas: 1
    selector:
        matchLabels:
            component: postgres-server
    template:
        metadata:
            labels:
                component: postgres-server
        spec:
            volumes:
                - name: postgres-storage
                  persistentVolumeClaim:
                      claimName: database-persistent-volume-claim
            containers:
                - name: psql-server
                  image: postgres
                  ports:
                      - containerPort: 5432
                  volumeMounts:
                      - name: postgres-storage
                        mountPath: /var/lib/postgresql/data
                        subPath: postgres
                  env:
                      - name: POSTGRES_DB
                        value: mydb
                      - name: POSTGRES_USER
                        valueFrom: 
                            secretKeyRef:
                                name: postgres-secret
                                key: username
                      - name: POSTGRES_PASSWORD
                        valueFrom: 
                            secretKeyRef:
                                name: postgres-secret
                                key: password