postgres

by Flanksource

Helm chartv1.0.27App 17Verified publisher

A Helm chart for PostgreSQL with automatic upgrade capabilities

About this chart

postgres

A Helm chart for PostgreSQL with automatic upgrade capabilities

Chart Information

Maintainers

NameEmailUrl
Flanksource[email protected]https://flanksource.com

Source Code

Homepage: https://github.com/flanksource/postgres

Features

  • 🚀 Automatic Upgrades: Built-in support for automatic PostgreSQL version upgrades
  • 🎯 Auto-tuning: Automatic performance tuning based on available resources
  • 🔐 Security: Runs as non-root user with configurable security contexts
  • 💾 Persistence: Optional persistent storage with PVC support
  • 🔧 Flexible Configuration: Extensive PostgreSQL configuration options
  • 📊 Health Checks: Comprehensive startup, liveness, and readiness probes

Quick Start

Basic Installation

Install PostgreSQL with default settings:

helm repo add flanksource https://flanksource.github.io/charts
helm repo update
helm install postgres flanksource/postgres

Installation with Custom Password

kubectl create secret generic postgres-password --from-literal=password=mySecurePassword123
helm install postgres flanksource/postgres --set passwordRef.create=false

Installation with Custom Resources

helm install postgres flanksource/postgres \
  --set resources.requests.memory=512Mi \
  --set resources.requests.cpu=500m \
  --set resources.limits.memory=2Gi \
  --set resources.limits.cpu=2000m

Installation with Specific PostgreSQL Version

helm install postgres flanksource/postgres \
  --set version="16" \
  --set image.tag="16"

Installation with Custom Storage

helm install postgres flanksource/postgres \
  --set persistence.size=50Gi \
  --set persistence.storageClass=fast-ssd

Connecting to PostgreSQL

From within the cluster

Get the connection details:

export POSTGRES_PASSWORD=$(kubectl get secret postgres-password -o jsonpath="{.data.password}" | base64 --decode)
export POSTGRES_HOST=$(kubectl get service postgres -o jsonpath="{.status.loadBalancer.ingress[0].ip}")

# Connect using psql
kubectl run postgres-client --rm --tty -i --restart='Never' --image postgres:17 \
  --env="PGPASSWORD=$POSTGRES_PASSWORD" \
  --command -- psql -h postgres -U postgres -d postgres

Port forwarding for local access

kubectl port-forward svc/postgres 5432:5432
export POSTGRES_PASSWORD=$(kubectl get secret postgres-password -o jsonpath="{.data.password}" | base64 --decode)
psql -h localhost -U postgres -d postgres

Configuration Examples

Disable Auto-upgrade

autoUpgrade:
  enabled: false

Custom PostgreSQL Configuration

conf:
  max_connections: 200
  shared_buffers: 2GB
  effective_cache_size: 6GB
  log_statement: "all"
  log_min_duration_statement: "1s"

Using Existing PVC

persistence:
  enabled: true
  existingClaim: "my-existing-pvc"

Node Affinity and Tolerations

nodeSelector:
  disktype: ssd

tolerations:
  - key: "database"
    operator: "Equal"
    value: "postgres"
    effect: "NoSchedule"

Upgrade Notes

When upgrading the chart, the PostgreSQL version can be automatically upgraded if autoUpgrade.enabled is set to true (default). The upgrade process is handled by the postgres-cli tool which:

  1. Detects the current PostgreSQL version
  2. Performs pg_upgrade if needed
  3. Updates the data directory structure
  4. Restarts PostgreSQL with the new version

To upgrade the chart:

helm upgrade postgres flanksource/postgres --set version="17"

Values

KeyTypeDefaultDescription
affinityobject{}
autoUpgrade.enabledbooltrue
conf.listen_addressesstring"*"
conf.log_autovacuum_min_durationstring"10s"
conf.log_connectionsstring"off"
conf.log_destinationstring"stderr"
conf.log_directorystring"/var/log/postgresql"
conf.log_disconnectionsstring"off"
conf.log_file_modeint420
conf.log_filenamestring"postgresql-%d.log"
conf.log_line_prefixstring"%m [%p] %q[user=%u,db=%d,app=%a]"
conf.log_lock_waitsstring"on"
conf.log_min_duration_statementstring"1s"
conf.log_statementstring"all"
conf.log_temp_filesstring"100MB"
conf.log_timezonestring"UTC"
conf.logging_collectorstring"off"
conf.password_encryptionstring"scram-sha-256"
conf.sslstring"off"
conf.timezonestring"UTC"
database.namestring"postgres"
database.usernamestring"postgres"
dshmSizestring"256Mi"
envlist[]
extraVolumeMountslist[]
extraVolumeslist[]
fullnameOverridestring""
image.pullPolicystring"IfNotPresent"
image.registrystring"ghcr.io"
image.repositorystring"flanksource/postgres"
image.tagstring"17"
imagePullSecretslist[]
livenessProbe.enabledbooltrue
livenessProbe.failureThresholdint3
livenessProbe.initialDelaySecondsint10
livenessProbe.periodSecondsint30
livenessProbe.successThresholdint1
livenessProbe.timeoutSecondsint5
nameOverridestring""
nodeSelectorobject{}Node selector
passwordRef.createbooltrue
passwordRef.keystring"password"
passwordRef.secretNamestring"postgres-password"
persistence.accessModestring"ReadWriteOnce"
persistence.annotationsobject{}
persistence.enabledbooltrue
persistence.existingClaimstring""
persistence.sizestring"10Gi"
persistence.storageClassstring""
persistence.volumeNamestring""
podAnnotationsobject{}
podLabelsobject{}
podSecurityContext.fsGroupint999
podSecurityContext.fsGroupChangePolicystring"OnRootMismatch"
podSecurityContext.runAsGroupint999
podSecurityContext.runAsUserint999
postgresCliArgsstring"--pg-tune --auto-upgrade --auto-reset-password --auto-init"custom arguments to pass to postgres-cli startup
readinessProbe.enabledbooltrue
readinessProbe.failureThresholdint3
readinessProbe.initialDelaySecondsint5
readinessProbe.periodSecondsint10
readinessProbe.successThresholdint1
readinessProbe.timeoutSecondsint5
resetVolumePermissionsbooltrueChange ownership and permissions of mounted volumes on startup
resources.limits.cpustring"2000m"
resources.limits.memorystring"4Gi"
resources.requests.cpustring"20m"
resources.requests.memorystring"128Mi"
securityContext.allowPrivilegeEscalationboolfalse
securityContext.capabilities.drop[0]string"ALL"
securityContext.readOnlyRootFilesystemboolfalse
securityContext.runAsNonRootbooltrue
securityContext.runAsUserint999
service.annotationsobject{}
service.portint5432
service.typestring"ClusterIP"
serviceAccount.annotationsobject{}
serviceAccount.createbooltrue
serviceAccount.namestring""
startupProbe.enabledbooltrue
startupProbe.failureThresholdint30
startupProbe.initialDelaySecondsint10
startupProbe.periodSecondsint10
startupProbe.successThresholdint1
startupProbe.timeoutSecondsint5
tolerationslist[]
versionstring"17"Postgres version to run, flanksource/postgres images include multiple versions allowing you to select at runtime

Deploy postgres with OpenTenant

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