postgresql

by HelmForge

Helm chartv2.2.2App 19.0Apache-2.0Verified publisher

PostgreSQL for Kubernetes with explicit standalone and replication modes

About this chart

PostgreSQL

PostgreSQL for Kubernetes with explicit standalone and replication modes, documented bootstrap behavior, optional init scripts, and optional metrics.

Defaults are intentionally lightweight for development and simple internal environments. Production deployments should layer explicit values for Secrets, persistence, resources, network boundaries, backup, observability, scheduling, and security hardening.

Install

HTTPS repository

helm repo add helmforge https://repo.helmforge.dev
helm repo update
helm install postgresql helmforge/postgresql -f values.yaml

OCI registry

helm install postgresql oci://ghcr.io/helmforgedev/helm/postgresql -f values.yaml

Supported architectures

ArchitectureWhen to useDocument
standalonedevelopment, simple production environments, or workloads where a single writable database is acceptabledocs/standalone.md
replicationone writable primary plus asynchronous read replicas for read scaling and simpler recovery workflowsdocs/replication.md

What this chart covers

  • explicit architecture selection through architecture
  • PostgreSQL on the official postgres image
  • generated passwords, manually managed existingSecret, or optional External Secrets Operator resources
  • app user and app database bootstrap on first initialization
  • optional extra init scripts
  • fixed-primary asynchronous replication with pg_basebackup
  • role-aware readiness checks for primary and replicas in replication mode
  • optional metrics through postgres_exporter
  • optional ServiceMonitor
  • built-in S3 backup CronJob using pg_dumpall
  • dedicated metrics Services separated from client traffic
  • topology-specific Services for client traffic, primary traffic, and read replicas
  • optional dual-stack Service fields through service.ipFamilyPolicy and service.ipFamilies
  • optional ExternalSecret resources for clusters that already run External Secrets Operator

Security Scan: postgresql

FrameworkScore
MITRE + NSA + SOC293%

Security posture: strong. Remaining findings are documented product exceptions for opt-in NetworkPolicy and PostgreSQL's writable runtime filesystem.

How to choose the architecture

  • use standalone when operational simplicity matters more than read scaling
  • use replication when you need separate write and read endpoints, but you are not asking the chart to solve automatic failover

Recommended reading before installation:

  • Standalone
  • Replication
  • Production
  • Replication Operations
  • HA and Scope Boundaries
  • Backup and Restore
  • Secret Rotation

Official product references

Operational direction

  • for production needing automatic failover, use a PostgreSQL operator instead of stretching this chart beyond its scope
  • replication in this chart means one fixed primary with asynchronous replicas
  • built-in logical backup to S3 is available for standalone and replication topologies

Read traffic model

In replication mode, the chart exposes separate Services for different traffic patterns:

  • the base client Service for general in-cluster access
  • a dedicated primary Service for write traffic
  • a dedicated replicas Service for read-only traffic

The replicas Service is the endpoint to use for horizontal read scaling when an application, reporting stack, or other read-heavy component can work against asynchronous read-only replicas.

Important limits:

  • Kubernetes Service balancing distributes connections across available replicas, but it is not a PostgreSQL-aware query router
  • replica reads may lag behind the primary because replication is asynchronous
  • workloads that require immediate read-after-write consistency should stay on the primary endpoint

Scope boundary

This chart intentionally stays on the Helm-chart side of the boundary:

  • it manages PostgreSQL pods, services, storage, init scripts, metrics, TLS, and basic replication operations
  • it does not attempt to behave like a cluster manager
  • it does not implement automatic failover, leader election, fencing, or reconciliation loops

If you need automated failover, self-healing topology management, switchover workflows, or lifecycle orchestration across primary and replicas, use a PostgreSQL operator instead of extending this chart into that territory.

Quick start

Minimal standalone example:

architecture: standalone

auth:
  existingSecret: postgresql-auth

standalone:
  persistence:
    enabled: true
    size: 20Gi

Replication example:

architecture: replication

auth:
  existingSecret: postgresql-auth

replication:
  primary:
    persistence:
      enabled: true
      size: 50Gi
  readReplicas:
    replicaCount: 2
    persistence:
      enabled: true
      size: 50Gi

metrics:
  enabled: true
  serviceMonitor:
    enabled: true

Production hardening example:

architecture: replication

auth:
  existingSecret: postgresql-auth

config:
  allowedClientCIDRs:
    - 10.42.0.0/16
  allowedReplicationCIDRs:
    - 10.42.0.0/16

tls:
  enabled: true
  existingSecret: postgresql-tls
  volumePermissions:
    enabled: true

replication:
  wal:
    keepSize: 2GB
    maxSlotWalKeepSize: 8GB
    idleReplicationSlotTimeout: 24h
    walSenderTimeout: 60s
  slots:
    enabled: true

metrics:
  enabled: true
  serviceMonitor:
    enabled: true

networkPolicy:
  enabled: true
  egress:
    enabled: true

serviceAccount:
  create: true
  automountServiceAccountToken: false

See examples/production.yaml for a fuller production-oriented values file.

External Secrets Operator example:

auth:
  database: app
  username: app

tls:
  enabled: true

backup:
  enabled: true
  s3:
    endpoint: https://minio.example.com
    bucket: postgresql-backups

externalSecrets:
  enabled: true
  secretStoreRef:
    name: platform-secrets
    kind: ClusterSecretStore
  auth:
    enabled: true
    postgresPasswordRemoteRef:
      key: postgresql/auth
      property: postgres-password
    userPasswordRemoteRef:
      key: postgresql/auth
      property: user-password
  tls:
    enabled: true
    certRemoteRef:
      key: postgresql/tls
      property: tls.crt
    keyRemoteRef:
      key: postgresql/tls
      property: tls.key
    caRemoteRef:
      key: postgresql/tls
      property: ca.crt
  backup:
    enabled: true
    accessKeyRemoteRef:
      key: postgresql/backup
      property: access-key
    secretKeyRemoteRef:
      key: postgresql/backup
      property: secret-key

The chart renders only ExternalSecret resources. External Secrets Operator and the referenced SecretStore or ClusterSecretStore must already exist.

Best practices

Security

  • prefer auth.existingSecret in production
  • use externalSecrets.enabled=true only on clusters where External Secrets Operator and the referenced store already exist
  • keep the password Secret aligned with the password stored in any existing PVC; PostgreSQL does not rewrite pg_authid just because a Kubernetes Secret changed
  • keep client access internal unless there is a strong reason to expose PostgreSQL outside the cluster network
  • use networkPolicy.enabled=true or external platform controls when possible
  • use networkPolicy.egress.enabled=true when the cluster enforces egress isolation
  • keep serviceAccount.automountServiceAccountToken=false unless an integration requires Kubernetes API access from the pod
  • rotate passwords through secret management workflows instead of editing values inline
  • when externalSecrets.auth.enabled=true, the native auth Secret is suppressed and PostgreSQL consumes the materialized target Secret
  • use tls.enabled=true with certificate material from a managed secret when PostgreSQL traffic must be encrypted
  • enable tls.volumePermissions.enabled=true when PostgreSQL rejects mounted Secret key permissions
  • restrict config.allowedClientCIDRs and config.allowedReplicationCIDRs to pod/client networks that should reach PostgreSQL

Replication and availability

  • treat replication as read scaling and operational recovery help, not full HA
  • place primary and replicas across different nodes or zones when the cluster supports it
  • use pdb.enabled=true when running multiple replicas and planning maintenance windows
  • review the default replication PDB and placement behavior before overriding them globally
  • keep startupProbe conservative for PostgreSQL, especially on larger volumes and recovery paths
  • enable replication.slots.enabled=true only when WAL retention limits and disk monitoring are also in place
  • use replication.wal.maxSlotWalKeepSize, replication.wal.idleReplicationSlotTimeout, and replication.wal.walSenderTimeout to bound replication slot risk

Initialization

  • use initdb.scripts for deterministic first-boot SQL or shell customization
  • use initdb.existingConfigMap when scripts are already managed elsewhere
  • set initdb.runDefaultScript=false when you want only custom or externally managed first-boot scripts
  • remember that docker-entrypoint-initdb.d runs only during first initialization of a fresh data directory
  • the chart keeps internal maintenance traffic on PostgreSQL's standard postgres database
  • when an older reused PVC is missing postgres, the primary pod repairs that database during startup before probes and internal clients depend on it

Observability

  • enable metrics.enabled=true in monitored environments
  • enable metrics.serviceMonitor.enabled=true when Prometheus Operator is available
  • metrics are exposed through dedicated metrics Services, not through the client database Services
  • monitor connection count, replication lag, disk growth, checkpoint behavior, and WAL retention

Configuration UX

  • use config.preset for a small set of opinionated PostgreSQL defaults
  • use config.allowedClientCIDRs and config.allowedReplicationCIDRs for structured pg_hba.conf network access
  • use config.pgHbaEntries when you need structured host-based access rules
  • keep config.localAuthMethod=scram-sha-256 for production so local socket clients do not bypass password auth
  • use *.resourcesPreset for small and predictable environment sizing before reaching for fully custom resources
  • keep config.postgresql and config.pgHba for raw overrides when structured values are not enough
  • keep auth.database, auth.username, and auth.replicationUsername as plain values; existingSecret is intentionally limited to sensitive runtime data
  • use service.ipFamilyPolicy and service.ipFamilies only when the target cluster supports the requested IP family behavior

Production notes

  • use auth.existingSecret instead of inline passwords
  • use externalSecrets.auth.enabled=true when the platform standard is External Secrets Operator instead of pre-created Secrets
  • keep persistence enabled for every stateful topology
  • define node placement rules for replication, especially when the cluster spans multiple nodes or zones
  • define explicit CPU and memory resources
  • restrict generated pg_hba.conf CIDRs and enable NetworkPolicy for defense in depth
  • enable ServiceMonitor or equivalent scraping for PostgreSQL and replication health
  • use the client or primary Service only for writes
  • use the replicas Service only for read traffic
  • use the replicas Service when you need horizontal scale for read-only workloads
  • built-in backup dumps all PostgreSQL databases and global objects from the writable primary endpoint and uploads the compressed archive to S3-compatible storage
  • internal probes, metrics, backup, and administrative validation commands are expected to succeed against postgres
  • treat restore validation, retention policy, WAL strategy, and failover as operational workflows that still require explicit runbooks
  • review the operational guides before promoting replication to production

Operational documents:

  • Replication Operations
  • HA and Scope Boundaries
  • Backup and Restore
  • Secret Rotation

Main values

ParameterDescriptionDefault
architecturestandalone or replicationstandalone
image.repositoryPostgreSQL image repositorydocker.io/library/postgres
image.tagPostgreSQL image tag19.0-trixie
commonAnnotationsAnnotations added to every chart-owned resource{}
auth.databaseApp database created at bootstrapapp
auth.usernameApp user created at bootstrapapp
auth.existingSecretExisting secret for passwords""
auth.replicationUsernameReplication usernamereplicator
config.presetOptional PostgreSQL config presetnone
config.allowedClientCIDRsCIDRs allowed for regular PostgreSQL client connections in generated pg_hba.conf["0.0.0.0/0", "::/0"]
config.allowedReplicationCIDRsCIDRs allowed for replica bootstrap, replication slot checks, and streaming replication in generated pg_hba.conf["0.0.0.0/0", "::/0"]
config.pgHbaEntriesStructured pg_hba entries[]
standalone.resourcesPresetResource preset for standalone modesmall
replication.primary.resourcesPresetResource preset for the primary pod

Deploy postgresql with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has postgresql 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 chartpostgresql is pinned at v2.2.2 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