---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: db
  name: db
  namespace: voting
spec:
  replicas: 1
  selector:
    matchLabels:
      app: db
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: db
    spec:
      containers:
      - image: postgres:13
        name: postgres
        env:
        - name: PGDATA
          value: /var/lib/postgresql/data/pgdata
        envFrom:
        - prefix: POSTGRES_
          secretRef:
            name: db-secret
        ports:
        - containerPort: 5432
          name: postgres
        volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: db-data
        livenessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - exec pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" -h 127.0.0.1 -p 5432
        readinessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - -e
            - exec pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" -h 127.0.0.1 -p 5432
      volumes:
      - name: db-data
        persistentVolumeClaim:
          claimName: db
...
