apiVersion: apps/v1
kind: Deployment
metadata:
  name: pgbouncer-logistics
  namespace: default
  labels:
    app: pgbouncer-logistics
spec:
  revisionHistoryLimit: 10  # removes old replicasets for deployment rollbacks
  strategy:
    rollingUpdate:
      maxUnavailable: 0  # Avoid Terminating and ContainerCreating at the same time
  selector:
    matchLabels:
      app: pgbouncer-logistics
  template:
    metadata:
      labels:
        app: pgbouncer-logistics
    spec:
      # Optional: keep the POD close to the apps:
      #nodeSelector:
      #  purpose: apps
      containers:
        - name: pgbouncer
          #image: 448389607377.dkr.ecr.us-west-2.amazonaws.com/pgb-dd:0.1
          image: edoburu/pgbouncer:1.9.0
          #imagePullPolicy: Always
          ports:
            - containerPort: 5432
          envFrom:
            - secretRef:
               name: logistics-creds
          env:
            - name: POOL_MODE
              value: transaction
            - name: SERVER_LIFETIME
              value: "30"
            - name: SERVER_ROUND_ROBIN
              value: "1"
            - name: MAX_CLIENT_CONN
              value: "8000"
            - name: MAX_DB_CONNECTIONS
              value: "40"
            - name: DEFAULT_POOL_SIZE
              value: "110"
            - name: MIN_POOL_SIZE
              value: "100"
            - name: IDLE_TRANSACTION_TIMEOUT
              value: "1060"
            - name: QUERY_WAIT_TIMEOUT
              value: "1060"
            - name: SERVER_RESET_QUERY
              value: DISCARD ALL
          livenessProbe:
            tcpSocket:
              port: 5432
            periodSeconds: 60
          lifecycle:
            preStop:
              exec:
                # Allow existing queries clients to complete within 120 seconds
                command: ["/bin/sh", "-c", "killall -INT pgbouncer && sleep 120"]
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop: ['all']
