pgbouncer

by US579

Helm chartv2.5.0App 1.24.0MIT

A Helm chart for deploying PgBouncer, a PostgreSQL connection pooler, on Kubernetes

About this chart

PgBouncer Helm Chart

This chart deploys a PgBouncer instance to your Kubernetes cluster via Helm.

Prerequisites

  • Kubernetes 1.20+
  • Helm 3.10+

Installing the Chart

To install the chart with the release name my-pgbouncer:

# OCI
helm install my-pgbouncer oci://ghcr.io/icoretech/charts/pgbouncer
helm repo add icoretech https://icoretech.github.io/helm
helm install my-pgbouncer icoretech/pgbouncer

This command deploys a PgBouncer instance with default configuration.

Configuration

The following table lists the configurable parameters of the PgBouncer chart and their default values.

Values

KeyTypeDefaultDescription
affinityobject{}See Kubernetes docs on affinity rules.
argslist[]Override the default container arguments.
commandlist[]Override the default container command (entrypoint).
config.adminPasswordstringnilIf no existingAdminSecret is used, this admin password is placed in a new Secret.
config.adminPasswordKeystring"adminPassword"The key in the existingAdminSecret that corresponds to the admin password.
config.adminUserstring"admin"If no existingAdminSecret is used, this admin username is placed in a new Secret.
config.adminUserKeystring"adminUser"The key in the existingAdminSecret that corresponds to the admin username.
config.authPasswordstringnilPassword for the authUser above, if used.
config.authUserstringnilIf set, PgBouncer will use this user to authenticate client connections.
config.databasesobject{}Mapping of database names to connection parameters. E.g.: mydb: host=postgresql port=5432
config.existingAdminSecretstring""If set, skip creating a new secret for admin credentials, and reference this existing Secret name instead.
config.existingUserlistSecretstring""Reference to an existing Secret that contains a userlist.txt file, with entries for other users/passwords.
config.pgbouncerobject{}Additional PgBouncer parameters (e.g. auth_type, pool_mode).
config.userlistobject{}if existingUserlistSecret isn't used.
extraContainerslist[]Extra containers to run within the PgBouncer pod.
extraEnvslist[]Additional environment variables to set in the PgBouncer container.
extraInitContainerslist[]Init containers to run before the PgBouncer container starts.
extraVolumeMountslist[]Additional volume mounts for the main PgBouncer container.
extraVolumeslist[]Additional volumes for the PgBouncer pod.
fullnameOverridestring""Completely overrides the generated name. If set, takes precedence over nameOverride and chart name.
image.pullPolicystring"IfNotPresent"Container image pull policy: Always, IfNotPresent, or Never
image.registrystring""Container image registry
image.repositorystring"ghcr.io/icoretech/pgbouncer-docker"Container image repository
image.tagstring"1.24.0"Container image tag
imagePullSecretslist[]Array of imagePullSecrets to use for pulling private images.
lifecycleobject{}See Kubernetes docs on lifecycle hooks.
minReadySecondsint0Minimum number of seconds for which a newly created pod should be ready without crashing, before being considered available.
nameOverridestring""Overrides the chart name for resources. If set, takes precedence over the chart's name.
nodeSelectorobject{}Node labels for pod assignment.
pgbouncerExporter.enabledboolfalseEnable or disable the PgBouncer exporter sidecar container.
pgbouncerExporter.image.pullPolicystring"IfNotPresent"Exporter image pull policy
pgbouncerExporter.image.registrystring""Exporter image registry
pgbouncerExporter.image.repositorystring"prometheuscommunity/pgbouncer-exporter"Exporter image repository
pgbouncerExporter.image.tagstring"v0.10.2"Exporter image tag
pgbouncerExporter.log.formatstring"logfmt"Exporter log format (logfmt or json)
pgbouncerExporter.log.levelstring"info"Exporter log level (debug, info, warn, error)
pgbouncerExporter.podMonitorboolfalseWhether to create a PodMonitor for scraping metrics (Prometheus Operator).
pgbouncerExporter.portint9127The container port for the exporter.
pgbouncerExporter.resourcesobject{"limits":{"cpu":"250m","memory":"150Mi"},"requests":{"cpu":"30m","memory":"40Mi"}}Resource requests and limits for the exporter container.
pgbouncerExporter.securityContextobject{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"readOnlyRootFilesystem":true,"runAsGroup":65534,"runAsNonRoot":true,"runAsUser":65534}Pod security context for the exporter container.
podAnnotationsobject{}Additional annotations to add to each PgBouncer pod.
podDisruptionBudgetobject{"enabled":false,"maxUnavailable":null,"minAvailable":null}Pod Disruption Budget configuration.
podDisruptionBudget.enabledboolfalseIf true, create a PDB to protect PgBouncer pods from voluntary disruptions.
podLabelsobject{}Additional labels to add to each PgBouncer pod.
priorityClassNamestring""Priority class for PgBouncer pods (for scheduling priority).
replicaCountint1Number of replicas for the PgBouncer Deployment (see Kubernetes docs for Deployments).
resourcesobject{}See Kubernetes docs on managing container resources.
revisionHistoryLimitint10How many old ReplicaSets to retain for rollbacks.
runtimeClassNamestring""Runtime class for the PgBouncer pods (e.g. gvisor).
securityContextobject{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"readOnlyRootFilesystem":true,"runAsGroup":70,"runAsNonRoot":true,"runAsUser":70}Pod security context for the main PgBouncer container. By default, this forces the container to run without root privileges and with a read-only root filesystem:
service.portint5432The service port for PgBouncer.
service.typestring"ClusterIP"Service type (e.g. ClusterIP, NodePort, LoadBalancer).
serviceAccount.annotationsobject{}Annotations for the created ServiceAccount.
serviceAccount.namestring""Creates a new ServiceAccount if this is empty.
terminationGracePeriodSecondsint30Time (in seconds) to allow graceful shutdown before force-terminating the container.
tolerationslist[]See Kubernetes docs on taints and tolerations.
updateStrategyobject{}The update strategy to apply to the Deployment (e.g. Recreate or RollingUpdate).

Example using Flux

apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
  name: icoretech
spec:
  interval: 30m
  type: oci
  url: oci://ghcr.io/icoretech/charts
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: pgbouncer
  namespace: default
spec:
  releaseName: pgbouncer
  chart:
    spec:
      chart: pgbouncer
      version: ">= 2.4.0"
      sourceRef:
        kind: HelmRepository
        name: icoretech
        namespace: flux-system
  interval: 3m0s
  install:
    remediation:
      retries: 3
  values:
    config:
      adminPassword: myadminpassword
      databases:
        mydb_production:
          host: postgresql
          port: 5432
      pgbouncer:
        server_tls_sslmode: prefer
        ignore_startup_parameters: search_path,extra_float_digits
        pool_mode: transaction
        auth_type: scram-sha-256
        max_client_conn: 8192
        max_db_connections: 200
        default_pool_size: 100
        log_connections: 1
        log_disconnections: 1
        log_pooler_errors: 1
        application_name_add_host: 1
        max_prepared_statements: 4000
        # verbose: 1
      userlist:
        # SELECT rolname, rolpassword FROM pg_authid;
        myuser: SCRAM-SHA-256$4096:xxxxx=

Deploy pgbouncer with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has pgbouncer on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartpgbouncer is pinned at v2.5.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply