postgresql
by HelmForge
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
| Architecture | When to use | Document |
|---|---|---|
standalone | development, simple production environments, or workloads where a single writable database is acceptable | docs/standalone.md |
replication | one writable primary plus asynchronous read replicas for read scaling and simpler recovery workflows | docs/replication.md |
What this chart covers
- explicit architecture selection through
architecture - PostgreSQL on the official
postgresimage - 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.ipFamilyPolicyandservice.ipFamilies - optional
ExternalSecretresources for clusters that already run External Secrets Operator
Security Scan: postgresql
| Framework | Score |
|---|---|
| MITRE + NSA + SOC2 | 93% |
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
standalonewhen operational simplicity matters more than read scaling - use
replicationwhen 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
- PostgreSQL streaming replication: https://www.postgresql.org/docs/current/warm-standby.html
- PostgreSQL
pg_isready: https://www.postgresql.org/docs/current/app-pg-isready.html - PostgreSQL official image: https://hub.docker.com/_/postgres
Operational direction
- for production needing automatic failover, use a PostgreSQL operator instead of stretching this chart beyond its scope
replicationin 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.existingSecretin production - use
externalSecrets.enabled=trueonly 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_authidjust 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=trueor external platform controls when possible - use
networkPolicy.egress.enabled=truewhen the cluster enforces egress isolation - keep
serviceAccount.automountServiceAccountToken=falseunless 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=truewith certificate material from a managed secret when PostgreSQL traffic must be encrypted - enable
tls.volumePermissions.enabled=truewhen PostgreSQL rejects mounted Secret key permissions - restrict
config.allowedClientCIDRsandconfig.allowedReplicationCIDRsto pod/client networks that should reach PostgreSQL
Replication and availability
- treat
replicationas 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=truewhen running multiple replicas and planning maintenance windows - review the default replication PDB and placement behavior before overriding them globally
- keep
startupProbeconservative for PostgreSQL, especially on larger volumes and recovery paths - enable
replication.slots.enabled=trueonly when WAL retention limits and disk monitoring are also in place - use
replication.wal.maxSlotWalKeepSize,replication.wal.idleReplicationSlotTimeout, andreplication.wal.walSenderTimeoutto bound replication slot risk
Initialization
- use
initdb.scriptsfor deterministic first-boot SQL or shell customization - use
initdb.existingConfigMapwhen scripts are already managed elsewhere - set
initdb.runDefaultScript=falsewhen you want only custom or externally managed first-boot scripts - remember that
docker-entrypoint-initdb.druns only during first initialization of a fresh data directory - the chart keeps internal maintenance traffic on PostgreSQL's standard
postgresdatabase - 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=truein monitored environments - enable
metrics.serviceMonitor.enabled=truewhen 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.presetfor a small set of opinionated PostgreSQL defaults - use
config.allowedClientCIDRsandconfig.allowedReplicationCIDRsfor structuredpg_hba.confnetwork access - use
config.pgHbaEntrieswhen you need structured host-based access rules - keep
config.localAuthMethod=scram-sha-256for production so local socket clients do not bypass password auth - use
*.resourcesPresetfor small and predictable environment sizing before reaching for fully custom resources - keep
config.postgresqlandconfig.pgHbafor raw overrides when structured values are not enough - keep
auth.database,auth.username, andauth.replicationUsernameas plain values;existingSecretis intentionally limited to sensitive runtime data - use
service.ipFamilyPolicyandservice.ipFamiliesonly when the target cluster supports the requested IP family behavior
Production notes
- use
auth.existingSecretinstead of inline passwords - use
externalSecrets.auth.enabled=truewhen 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.confCIDRs and enable NetworkPolicy for defense in depth - enable ServiceMonitor or equivalent scraping for PostgreSQL and replication health
- use the
clientorprimaryService only for writes - use the
replicasService only for read traffic - use the
replicasService 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
replicationto production
Operational documents:
- Replication Operations
- HA and Scope Boundaries
- Backup and Restore
- Secret Rotation
Main values
| Parameter | Description | Default |
|---|---|---|
architecture | standalone or replication | standalone |
image.repository | PostgreSQL image repository | docker.io/library/postgres |
image.tag | PostgreSQL image tag | 19.0-trixie |
commonAnnotations | Annotations added to every chart-owned resource | {} |
auth.database | App database created at bootstrap | app |
auth.username | App user created at bootstrap | app |
auth.existingSecret | Existing secret for passwords | "" |
auth.replicationUsername | Replication username | replicator |
config.preset | Optional PostgreSQL config preset | none |
config.allowedClientCIDRs | CIDRs allowed for regular PostgreSQL client connections in generated pg_hba.conf | ["0.0.0.0/0", "::/0"] |
config.allowedReplicationCIDRs | CIDRs allowed for replica bootstrap, replication slot checks, and streaming replication in generated pg_hba.conf | ["0.0.0.0/0", "::/0"] |
config.pgHbaEntries | Structured pg_hba entries | [] |
standalone.resourcesPreset | Resource preset for standalone mode | small |
replication.primary.resourcesPreset | Resource 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartpostgresql is pinned at v2.2.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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