apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: "postgres"
  namespace: "default"
  labels:
    app: "postgres"
spec:
  replicas: 2
  selector:
    matchLabels:
      app: "postgres"
  template: 
    metadata:
      labels:
        app: "postgres"
    spec:
      containers:
      - name: "postgres"
        image: "postgres:9.6.2"
        env:
        - name: "POSTGRES_DB"
          valueFrom:
            configMapKeyRef:
              key: "POSTGRES_DB"
              name: "postgres-config"
        - name: "POSTGRES_USER"
          valueFrom:
            configMapKeyRef:
              key: "POSTGRES_USER"
              name: "postgres-config"
        - name: "POSTGRES_PASSWORD"
          valueFrom:
            configMapKeyRef:
              key: "POSTGRES_PASSWORD"
              name: "postgres-config"
        ports:
          - containerPort: 5432
            name: postgres
        volumeMounts:
          - name: postgres-storage
            mountPath: /var/lib/postgresql/db-data
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            claimName: postgres-pv-claim