postgresql

by sammyeby

Helm chartv2.3.2App 17.10-alpineVerified publisher

A Helm chart for PostgreSQL using SamSoft hardened Docker image (runs as UID 1001)

About this chart

PostgreSQL Helm Chart

A Helm chart for deploying PostgreSQL using SamSoft hardened Docker images.

Overview

This chart deploys PostgreSQL, the world's most advanced open-source relational database, on Kubernetes. It uses SamSoft's hardened container images that run as non-root (UID 1001) with security best practices.

Features

  • Hardened Images: Uses SamSoft's security-hardened PostgreSQL images
  • Non-root Execution: Runs as UID 1001 for enhanced security
  • Standalone & Replication: Support for both standalone and primary-replica architectures
  • Metrics & Monitoring: Prometheus exporter, ServiceMonitor, and PrometheusRule support
  • Security: Network policies, PodDisruptionBudget, and comprehensive securityContext
  • Backup: Built-in backup cronjob support
  • Password Files: Mount credentials as files for enhanced security

Prerequisites

  • Kubernetes 1.23+
  • Helm 3.8+
  • PV provisioner support in the underlying infrastructure

Installing the Chart

From OCI Registry

helm install postgresql oci://ghcr.io/sammyeby/charts/postgresql \
  --namespace database \
  --create-namespace \
  --set auth.postgresPassword=your-admin-password \
  --set auth.password=your-user-password \
  --set auth.database=mydb \
  --set auth.username=myuser

From Source

helm install postgresql ./postgresql \
  --namespace database \
  --create-namespace

Configuration

The following tables document all available configuration options in values.yaml.


Global Parameters

ParameterTypeDefaultDescription
global.imageRegistrystring""Global Docker Image registry
global.imagePullSecretsarray[]Global Docker registry secret names as an array
global.defaultStorageClassstring""Global default StorageClass for Persistent Volume(s)
global.storageClassstring""DEPRECATED: use global.defaultStorageClass instead
global.security.allowInsecureImagesbooleanfalseAllows skipping image verification
global.postgresql.fullnameOverridestring""Full chart name (overrides fullnameOverride)
global.postgresql.auth.postgresPasswordstring""Password for postgres admin user (overrides auth.postgresPassword)
global.postgresql.auth.usernamestring""Custom user name (overrides auth.username)
global.postgresql.auth.passwordstring""Custom user password (overrides auth.password)
global.postgresql.auth.databasestring""Custom database name (overrides auth.database)
global.postgresql.auth.existingSecretstring""Existing secret for credentials (overrides auth.existingSecret)
global.postgresql.auth.secretKeys.adminPasswordKeystring""Key for admin password in existing secret
global.postgresql.auth.secretKeys.userPasswordKeystring""Key for user password in existing secret
global.postgresql.auth.secretKeys.replicationPasswordKeystring""Key for replication password in existing secret
global.postgresql.service.ports.postgresqlstring""PostgreSQL service port override
global.compatibility.openshift.adaptSecurityContextstring"auto"Adapt securityContext for Openshift (auto, force, disabled)

Common Parameters

ParameterTypeDefaultDescription
kubeVersionstring""Override Kubernetes version
nameOverridestring""String to partially override common.names.fullname
fullnameOverridestring""String to fully override common.names.fullname
namespaceOverridestring""String to fully override common.names.namespace
clusterDomainstring"cluster.local"Kubernetes cluster domain
extraDeployarray[]Array of extra objects to deploy with the release
commonLabelsobject{}Add labels to all deployed resources
commonAnnotationsobject{}Add annotations to all deployed resources
secretAnnotationsobject{}Add annotations to secrets
diagnosticMode.enabledbooleanfalseEnable diagnostic mode (all probes disabled)
diagnosticMode.commandarray["sleep"]Command to override containers in diagnostic mode
diagnosticMode.argsarray["infinity"]Args to override containers in diagnostic mode

Image Parameters

ParameterTypeDefaultDescription
image.registrystring"ghcr.io"PostgreSQL image registry
image.repositorystring"sammyeby/postgresql"PostgreSQL image repository
image.tagstring"17.10-alpine"PostgreSQL image tag (immutable tags recommended)
image.digeststring""PostgreSQL image digest (overrides tag if set)
image.pullPolicystring"IfNotPresent"PostgreSQL image pull policy
image.pullSecretsarray[]PostgreSQL image pull secrets
image.debugbooleanfalseEnable debug mode

Authentication Parameters

ParameterTypeDefaultDescription
auth.enablePostgresUserbooleantrueAssign password to "postgres" admin user
auth.postgresPasswordstring""Password for postgres admin user (auto-generated if empty)
auth.usernamestring""Name for an additional user to create (does not replace the "postgres" superuser)
auth.passwordstring""Password for the additional user (auto-generated if empty)
auth.databasestring""Name for a custom database to create (owned by the additional user if auth.username is set)
auth.replicationUsernamestring"repl_user"Name of the replication user
auth.replicationPasswordstring""Password for replication user
auth.existingSecretstring""Existing secret for PostgreSQL credentials
auth.secretKeys.adminPasswordKeystring"postgres-password"Key in existing secret for admin password
auth.secretKeys.userPasswordKeystring"password"Key in existing secret for user password
auth.secretKeys.replicationPasswordKeystring"replication-password"Key in existing secret for replication password
auth.usePasswordFilesbooleantrueMount credentials as files instead of env vars

PostgreSQL Configuration Parameters

ParameterTypeDefaultDescription
architecturestring"standalone"PostgreSQL architecture (standalone or replication)
replication.synchronousCommitstring"off"Synchronous commit mode (on, remote_apply, remote_write, local, off)
replication.numSynchronousReplicasnumber0Number of replicas with synchronous replication
replication.applicationNamestring"my_application"Cluster application name
containerPorts.postgresqlnumber5432PostgreSQL container port
postgresqlDataDirstring"/var/lib/postgresql/pgdata"PostgreSQL data directory
postgresqlSharedPreloadLibrariesstring"pgaudit"Shared preload libraries

Audit Parameters

ParameterTypeDefaultDescription
audit.logHostnamebooleanfalseLog client hostnames
audit.logConnectionsbooleanfalseAdd client log-in operations to log
audit.logDisconnectionsbooleanfalseAdd client log-out operations to log
audit.pgAuditLogstring""Operations to log using pgAudit extension
audit.pgAuditLogCatalogstring"off"Log catalog using pgAudit
audit.clientMinMessagesstring"error"Message log level to share with user
audit.logLinePrefixstring""Template for log line prefix
audit.logTimezonestring""Timezone for log timestamps

LDAP Parameters

ParameterTypeDefaultDescription
ldap.enabledbooleanfalseEnable LDAP support
ldap.serverstring""IP address or name of LDAP server
ldap.portstring""Port number on LDAP server
ldap.prefixstring""String to prepend to user name for DN
ldap.suffixstring""String to append to user name for DN
ldap.basednstring""Root DN to begin user search
ldap.binddnstring""DN of user to bind to LDAP
ldap.bindpwstring""Password for user to bind to LDAP
ldap.searchAttributestring""Attribute to match against user name
ldap.searchFilterstring""Search filter for search+bind authentication
ldap.schemestring""Set to ldaps to use LDAPS
ldap.tls.enabledbooleanfalseEnable TLS encryption
ldap.uristring""Complete LDAP URL (overrides other LDAP params)

SHM Volume Parameters

ParameterTypeDefaultDescription
shmVolume.enabledbooleantrueEnable emptyDir volume for /dev/shm
shmVolume.sizeLimitstring""Size limit for shm tmpfs

TLS Parameters

ParameterTypeDefaultDescription
tls.enabledbooleanfalseEnable TLS traffic support
tls.autoGeneratedbooleanfalseGenerate automatically self-signed TLS certificates
tls.preferServerCiphersbooleantrueUse server's TLS cipher preferences
tls.certificatesSecretstring""Name of existing secret with certificates
tls.certFilenamestring""Certificate filename
tls.certKeyFilenamestring""Certificate key filename
tls.certCAFilenamestring""CA Certificate filename
tls.crlFilenamestring""Certificate Revocation List filename

PostgreSQL Primary Parameters

ParameterTypeDefaultDescription
primary.namestring"primary"Name of the primary database
primary.configurationstring""PostgreSQL main configuration to inject as ConfigMap
primary.pgHbaConfigurationstring""PostgreSQL client authentication configuration
primary.existingConfigmapstring""Existing ConfigMap with PostgreSQL configuration
primary.extendedConfigurationstring""Extended PostgreSQL configuration
primary.existingExtendedConfigmapstring""Existing ConfigMap with extended configuration
primary.initdb.argsstring""PostgreSQL initdb extra arguments
primary.initdb.postgresqlWalDirstring""Custom location for transaction log
primary.initdb.scriptsobject{}Dictionary of initdb scripts
primary.initdb.scriptsConfigMapstring""ConfigMap with initdb scripts
primary.initdb.scriptsSecretstring""Secret with initdb scripts
primary.initdb.userstring""PostgreSQL username to execute initdb scripts
primary.initdb.passwordstring""PostgreSQL password to execute initdb scripts
primary.preInitDb.scriptsobject{}Dictionary of pre-init scripts
primary.preInitDb.scriptsConfigMapstring""ConfigMap with pre-init scripts
primary.preInitDb.scriptsSecretstring""Secret with pre-init scripts
primary.standby.enabledbooleanfalseEnable primary as standby of another cluster
primary.standby.primaryHoststring""Host of replication primary in other cluster
primary.standby.primaryPortstring""Port of replication primary in other cluster
primary.extraEnvVarsarray[]Extra environment variables
primary.extraEnvVarsCMstring""ConfigMap with extra env vars
primary.extraEnvVarsSecretstring""Secret with extra env vars
primary.commandarray[]Override default container command
primary.argsarray[]Override default container args

Primary Health Check Parameters

ParameterTypeDefaultDescription
primary.livenessProbe.enabledbooleantrueEnable livenessProbe
primary.livenessProbe.initialDelaySecondsnumber30Initial delay for livenessProbe
primary.livenessProbe.periodSecondsnumber10Period seconds for livenessProbe
primary.livenessProbe.timeoutSecondsnumber5Timeout seconds for livenessProbe
primary.livenessProbe.failureThresholdnumber6Failure threshold for livenessProbe
primary.livenessProbe.successThresholdnumber1Success threshold for livenessProbe
primary.readinessProbe.enabledbooleantrueEnable readinessProbe
primary.readinessProbe.initialDelaySecondsnumber5Initial delay for readinessProbe
primary.readinessProbe.periodSecondsnumber10Period seconds for readinessProbe
primary.readinessProbe.timeoutSecondsnumber5Timeout seconds for readinessProbe
primary.readinessProbe.failureThresholdnumber6Failure threshold for readinessProbe
primary.readinessProbe.successThresholdnumber1Success threshold for readinessProbe
primary.startupProbe.enabledbooleanfalseEnable startupProbe
primary.startupProbe.initialDelaySecondsnumber30Initial delay for startupProbe
primary.startupProbe.periodSecondsnumber10Period seconds for startupProbe
primary.startupProbe.timeoutSecondsnumber`

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.3.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