apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
  namespace: staging
spec:
  selector:
    matchLabels:
      app: postgres
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - image: postgres:11.3-alpine
        name: postgres
        env:
        - name: POSTGRES_DB
          value: ori
        - name: PGDATA
          value: /var/lib/postgresql/data/pgdata
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: secrets
              key: POSTGRES_USERNAME
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secrets
              key: POSTGRES_PASSWORD
        volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: postgresdata
      restartPolicy: Always
      volumes:
      - name: postgresdata
        persistentVolumeClaim:
          claimName: postgresdata