kind: Deployment
apiVersion: apps/v1
metadata:
  name: postgres
  labels:
    app.kubernetes.io/name: postgres
    app.kubernetes.io/part-of: device-registry
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: postgres
      app.kubernetes.io/part-of: device-registry
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app.kubernetes.io/name: postgres
        app.kubernetes.io/part-of: device-registry
    spec:
      containers:
        - name: postgres
          image: docker.io/bitnami/postgresql:13
          imagePullPolicy: IfNotPresent
          env:
            - name: POSTGRES_DB
              valueFrom:
                configMapKeyRef:
                  name: postgres-config
                  key: databaseName
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: postgres-secret
                  key: admin.username
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres-secret
                  key: admin.password
            - name: PGPASSWORD # used in combination with psql
              valueFrom:
                secretKeyRef:
                  name: postgres-secret
                  key: admin.password
          readinessProbe:
            initialDelaySeconds: 5
            periodSeconds: 5
            tcpSocket:
              port: 5432
            timeoutSeconds: 1
          livenessProbe:
            initialDelaySeconds: 10
            periodSeconds: 5
            tcpSocket:
              port: 5432
            timeoutSeconds: 1
          ports:
            - containerPort: 5432
              name: postgres
              protocol: TCP
          resources:
            limits:
              memory: 512Mi
          volumeMounts:
            - mountPath: /bitnami/postgresql
              name: storage
      volumes:
        - name: storage
          persistentVolumeClaim:
            claimName: postgres-pvc
