apiVersion: apps/v1
kind: Deployment
metadata:
  name: pnoj-db
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pnoj-db
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: pnoj-db
    spec:
      containers:
      - image: postgres:alpine
        name: postgres
        env:
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: pnoj-db-secret
              key: username
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: pnoj-db-secret
              key: password
        ports:
        - containerPort: 5432
        volumeMounts:
        - name: postgres-volume
          mountPath: /var/lib/postgresql/data
          subPath: data
      volumes:
      - name: postgres-volume
        persistentVolumeClaim:
          claimName: pnoj-db-volumeclaim
