apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: pgbouncer
  name: pgbouncer
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pgbouncer
  template:
    metadata:
      labels:
        app: pgbouncer
    spec:
      containers:
      - env:
        - name: DB_HOST
          valueFrom:
            configMapKeyRef:
              key: DB_HOST
              name: pgbouncer-configs
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              key: POSTGRES_PASSWORD
              name: postgresql-secrets
        - name: DB_USER
          value: postgres
        - name: POOL_MODE
          value: transaction
        - name: SERVER_RESET_QUERY
          value: DISCARD ALL
        image: edoburu/pgbouncer:1.15.0
        lifecycle:
          preStop:
            exec:
              command:
              - /bin/sh
              - -c
              - killall -INT pgbouncer && sleep 120
        name: pgbouncer
        ports:
        - containerPort: 5432
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - all
