apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - image: registry.homelab.dsb.dev/library/postgres:13.2
        name: postgres
        command:
          - docker-entrypoint.sh
          - -c
          - work_mem=156MB
          - -c
          - max_parallel_workers_per_gather=0
        env:
        - name: POSTGRES_DB
          value: postgres
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              key: postgres.user
              name: postgres
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              key: postgres.password
              name: postgres
        - name: PGDATA
          value: /postgres/data
        readinessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - exec pg_isready -U postgres -h 127.0.0.1 -p 5432
          failureThreshold: 3
          initialDelaySeconds: 30
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          requests:
            cpu: 100m
            memory: 400Mi
          limits:
            cpu: "1"
            memory: 2Gi
        volumeMounts:
        - name: postgres
          mountPath: /postgres
      volumes:
      - name: postgres
        persistentVolumeClaim:
          claimName: postgres
