postgres

by groundhog2k

Helm chartv1.6.10App 19.0

A Helm chart for PostgreSQL on Kubernetes

About this chart

PostgreSQL

Changelog

see RELEASENOTES.md

A Helm chart for PostgreSQL on Kubernetes

⚠️ Warning

There is no automatic database upgrade from PostgreSQL 13.x (Chart version 0.2.x) to PostgreSQL 14.x (Chart version 0.3.x) or Postgres 14.x to Postgres 15.x (Chart version 0.4.x) etc. Upgrade deployment will fail in case of a major version change.

TL;DR

helm repo add groundhog2k https://groundhog2k.github.io/helm-charts/
helm install my-release groundhog2k/postgres

Introduction

This chart uses the original PostgreSQL image from Docker Hub to deploy a stateful PostgreSQL instance in a Kubernetes cluster.

It fully supports deployment of the multi-architecture docker image.

Prerequisites

  • Kubernetes 1.12+
  • Helm 3.x
  • PV provisioner support in the underlying infrastructure

Installing the Chart

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

helm install my-release groundhog2k/postgres

Uninstalling the Chart

To uninstall/delete the my-release deployment:

helm uninstall my-release

Common parameters

KeyTypeDefaultDescription
fullnameOverridestring""Fully override the deployment name
nameOverridestring""Partially override the deployment name

Deployment parameters

KeyTypeDefaultDescription
image.pullPolicystring"IfNotPresent"Image pull policy
image.registrystring"docker.io"Image registry
image.repositorystring"postgres"Image name
image.tagstring""Image tag
imagePullSecretslist[]Image pull secrets
extraInitContainerslist[]Extra init containers
extaContainerslist[]Extra containers for usage as sidecars
startupProbeobjectsee values.yamlStartup probe configuration
livenessProbeobjectsee values.yamlLiveness probe configuration
readinessProbeobjectsee values.yamlReadiness probe configuration
customStartupProbeobject{}Custom startup probe (overwrites default startup probe configuration)
customLivenessProbeobject{}Custom liveness probe (overwrites default liveness probe configuration)
customReadinessProbeobject{}Custom readiness probe (overwrites default readiness probe configuration)
initResourcesobject{}Resource limits and requests for the default init container
resourcesobject{}Resource limits and requests
priorityClassNamestring""Deployment priority class name
nodeSelectorobject{}Deployment node selector
customLabelsobject{}Additional labels for Deployment or StatefulSet
customAnnotationsobject{}Additional annotations for Deployment or StatefulSet
podAnnotationsobject{}Additional pod annotations
podLabelsobject{}Additional pod labels
podSecurityContextobjectsee values.yamlPod security context
securityContextobjectsee values.yamlContainer security context
envlist[]Additional container environmment variables
argslist[]Arguments for the container entrypoint process
serviceAccount.annotationsobject{}Additional service account annotations
serviceAccount.createboolfalseEnable service account creation
serviceAccount.namestring""Name of the service account
affinityobject{}Affinity for pod assignment
tolerationslist[]Tolerations for pod assignment
topologySpreadConstraintsobject{}Topology spread constraints for pods
podManagementPolicystring"OrderedReady"Pod management policy
updateStrategyTypestring"RollingUpdate"Pod update strategy
revisionHistoryLimitintnilMaximum number of revisions maintained in revision history

Service paramters

KeyTypeDefaultDescription
service.typestring"ClusterIP"Service type
service.portint5432PostreSQL service port
service.nodePortintnilThe node port (only relevant for type LoadBalancer or NodePort)
service.clusterIPstringnilThe cluster ip address (only relevant for type LoadBalancer or NodePort)
service.loadBalancerIPstringnilThe load balancer ip address (only relevant for type LoadBalancer)
service.loadBalancerSourceRangeslist[]The list of IP CIDR ranges that are allowed to access the load balancer (only relevent for type LoadBalancer)
service.annotationsobject{}Additional service annotations
service.labelsobject{}Additional service labels

Network policies

Allows to define optional network policies for ingress and egress The policyTypes will be automatically set

KeyTypeDefaultDescription
networkPolicy.ingressobject{}Ingress network policies
networkPolicy.egressobject{}Egress network policies

Storage parameters

KeyTypeDefaultDescription
storage.accessModes[0]string"ReadWriteOnce"Storage access mode
storage.persistentVolumeClaimNamestringnilPVC name when existing storage volume should be used
storage.volumeNamestring"postgres-data"Internal volume name and prefix of a created PVC
storage.requestedSizestringnilSize for new PVC, when no existing PVC is used
storage.classNamestringnilStorage class name
storage.keepPvcboolfalseKeep a created Persistent volume claim when uninstalling the helm chart (only for option useDeployment: true)
storage.persistentVolumeClaimRetentionPolicy.whenDeletedstringnilPersistent volume claim retention policy when StatefulSet is deleted - Valid values: Retain or Delete (only applies when useDeployment: false)
storage.persistentVolumeClaimRetentionPolicy.whenScaledstringnilPersistent volume claim retention policy when StatefulSet is scaled down - Valid values: Retain or Delete (only applies when useDeployment: false)
storage.annotationsobject{}Additional storage annotations
storage.labelsobject{}Additional storage labels
extraStoragelist[]A list of additional existing PVC that will be mounted into the container
extraStorage[].namestringnilInternal name of the volume
extraStorage[].pvcNamestringnilName of the existing PVC
extraStorage[].mountPathstringnilMount path where the PVC should be mounted into the container

PostgreSQL parameters

KeyTypeDefaultDescription
useDeploymentboolfalseUse Kubernetes Deployment instead of StatefulSet
settings.authMethodstringnilPostgres database authentication method
settings.initDbArgsstringnilOptional init database arguments
settings.dataDirstring"/var/lib/postgresql/data"Default data directory mountpoint
settings.pgDirstring"pg"Name of the postgres directory inside data directory
settings.superuser.secretKeystringnilKey of existingSecret for the Superuser name
settings.superuser.valuestringnilSuperuser name (if no existingSecret was specified) - defaults to "postgres"
settings.superuserPassword.secretKeystringnilKey of existingSecret for the Superuser password
settings.superuserPassword.valuestringnilPassword of Superuser (if no existingSecret was specified)
userDatabase.existingSecretstringnilOptional existing secret with database name, user and password
userDatabase.name.secretKeystring""Key of the existingSecret with database name
userDatabase.name.valuestring""Name of the user database (if no existingSecret was specified)
userDatabase.user.secretKeystring""Key of the existingSecret with database user
userDatabase.user.valuestring""User name with full access to user database (if no existingSecret was specified)
userDatabase.password.secretKeystring""Key of the existingSecret with password of created user
userDatabase.password.valuestring""Password of created user (if no existingSecret was specified)
customConfigstringnilOptional custom configuration block that will be mounted as file in /etc/postgresql/postgresql.conf
extraEnvSecretslist[]A list of existing secrets that will be mounted into the container as environment variables
extraSecretConfigsstringnilAn existing secret with files that will be added to the postgres configuration in addition to /etc/postgresql/postgresql.conf
customScriptsobjectnilOptional custom scripts that can be defined inline and will be mounted as files in /docker-entrypoint-initdb.d
extraScriptsstringnilAn existing configMap with files that will be mounted into the container as script files (*.sql, *.sh) in /docker-entrypoint-initdb.d
extraSecretslist[]A list of additional existing secrets that will be mounted into the container
extraSecrets[].namestringnilName of the existing K8s secret
extraSecrets[].defaultModeint0440Mount default access mode
extraSecrets[].mountPathstringnilMount path where the secret should be mounted into the container (f.e. /mysecretfolder)
extraConfigslist[]A list of additional existing configMaps that will be mounted into the container
extraConfigs[].namestringnilName of the existing K8s configMap
extraConfigs[].defaultModeint0440Mount default access mode
extraConfigs[].mountPathstringnilMount path where the configMap should be mounted into the container (f.e. /myconfigfolder)

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