apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
  namespace: "{{namespace}}"
spec:
  selector:
    matchLabels:
      app: postgres
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      volumes:
      - name: postgres-data
        persistentVolumeClaim:
          claimName: postgres-pvc
      containers:
      - name: postgres
        image: postgres:11.1-alpine
        env:
          - name: POSTGRES_USER
            valueFrom: 
              secretKeyRef:
                name: postgres
                key: user
          - name: POSTGRES_PASSWORD
            valueFrom: 
              secretKeyRef:
                name: postgres
                key: password
          - name: POSTGRES_DB
            valueFrom:
              configMapKeyRef:
                name: config
                key: database
          - name: PGDATA
            value: "/home/postgres_data"
        ports:
        - containerPort: 5432
          name: postgres
        volumeMounts:
          - name: postgres-data
            mountPath: "/home/postgres_data"