apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: postgres
  template:
    metadata:
      labels:
        component: postgres
    spec:
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            # This has to be the same name as the PVC name in the PVC config
            claimName: database-persistent-volume-claim
      containers:
        - name: postgres
          image: postgres
          ports:
            - containerPort: 5432
          volumeMounts:
            # This needs to be the same as the name of the volume above that is tied to the PVC
            - name: postgres-storage
              mountPath: /var/lib/postgresql/data # Default location for PSQL mount (google this)
              subPath: postgres # Data will go into /var/lib/postgresql/data/postgres inside container
          env:
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  # These correspond to what you set up manually with kubectl create secret
                  name: pg-password
                  key: PG_PASSWORD
