apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
  namespace: matrixorg
spec:
  selector:
    matchLabels:
      service: postgres
  replicas: 1
  template:
    metadata:
      labels:
        service: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:12.2
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              valueFrom:
                secretKeyRef:
                  name: postgres-secret
                  key: POSTGRES_DB
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: postgres-secret
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres-secret
                  key: POSTGRES_PASSWORD
          volumeMounts:
            - mountPath: "/var/lib/postgresql/data"
              name: postgres-db-claim
      volumes:
        - name: postgres-db-claim
          persistentVolumeClaim:
            claimName: postgres-db-claim
