postgresql-single
Helm chartv1.16.0App 16.16Verified publisher
Postgres with backup/restore and replication
About this chart
postgresql-single
Postgres with backup/restore and replication
Homepage: https://github.com/sergelogvinov/helm-charts
Maintainers
| Name | Url | |
|---|---|---|
| sergelogvinov | https://github.com/sergelogvinov |
Source Code
A single-node PostgreSQL database is straightforward and relatively easy to maintain. You don't need to worry about configuring a distributed database or managing multiple nodes.
- Support backup/restore to the extrernal storage, using wal-g
- Automatically tuning PostgreSQL parameters base on
postgresqlServerMemoryvalue.
# create backup-s3 secret
kubectl create secret generic backup-s3 --from-file=credentials
# Helm values
installationType: standalone # or cnpg
pgHbaConfiguration:
# host database user address auth-method
- hostssl app app 10.0.0.0/8 md5
postgresqlServerMemory: 2048
resources:
limits:
memory: 4Gi
cpu: 4
requests:
memory: 2Gi
cpu: 2
extraVolumes:
- name: s3-certs
secret:
defaultMode: 256
secretName: backup-s3
extraVolumeMounts:
- name: s3-certs
mountPath: /var/lib/postgresql/.aws
readOnly: true
backup:
enabled: true
recovery: true # If PVC empty - it will use latest backup.
walpush: true # Send wal to the s3.
walg:
WALG_TAR_DISABLE_FSYNC: true
WALG_UPLOAD_WAL_METADATA: INDIVIDUAL
WALG_PREVENT_WAL_OVERWRITE: true
WALG_COMPRESSION_METHOD: brotli
WALG_LIBSODIUM_KEY_TRANSFORM: hex
WALG_LIBSODIUM_KEY: "" # generate it: openssl rand -hex 32
WALG_S3_PREFIX: s3://backup/postgrtes-backup
backupCheck:
enabled: true
metrics:
enabled: true
Values
| Key | Type | Default | Description |
|---|---|---|---|
| replicaCount | int | 1 | |
| image.repository | string | "ghcr.io/sergelogvinov/postgresql" | |
| image.pullPolicy | string | "IfNotPresent" | |
| image.tag | string | "" | |
| imagePullSecrets | list | [] | |
| nameOverride | string | "" | |
| fullnameOverride | string | "" | |
| installationType | string | "standalone" | Installation type can be "cnpg" or "standalone" |
| command | list | [] | command Override default container command |
| env | list | [] | Environment variables |
| postgresqlUsername | string | "postgres" | PostgreSQL admin user ref: https://hub.docker.com/_/postgres |
| postgresqlMaxConnections | int | 150 | Create a database ref: https://hub.docker.com/_/postgres postgresqlDatabase: |
| pgHbaConfiguration | list | [] | Postgres auth ref: https://www.postgresql.org/docs/current/auth-pg-hba-conf.html |
| initdb.args | string | "--data-checksums --auth-host=scram-sha-256" | PostgreSQL initdb parameters ref: https://www.postgresql.org/docs/current/app-initdb.html |
| initdb.database | string | "app" | Create owner and database |
| initdb.username | string | "app" | |
| initdb.password | string | nil | |
| initdb.script | list | [] | PostgreSQL initdb scripts ref: https://hub.docker.com/_/postgres |
| tlsCerts.create | bool | false | |
| tlsCerts.mode | string | "require" | |
| pooler.enabled | bool | false | |
| pooler.replicaCount | int | 1 | |
| pooler.types[0] | string | "rw" | |
| pooler.types[1] | string | "ro" | |
| pooler.mode | string | "session" | |
| pooler.parameters | object | {} | |
| pooler.service.type | string | "ClusterIP" | Service type ref: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types |
| pooler.service.labels | object | {} | Extra labels for load balancer service. ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ |
| pooler.service.annotations | object | {} | Extra annotations for load balancer service. ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ |
| pooler.service.externalTrafficPolicy | string | "Cluster" | Traffic policies. ref: https://kubernetes.io/docs/reference/networking/virtual-ips/#traffic-policies |
| pooler.service.internalTrafficPolicy | string | "Cluster" | |
| pooler.service.ipFamilies | list | ["IPv4"] | IP families for service possible values: IPv4, IPv6 ref: https://kubernetes.io/docs/concepts/services-networking/dual-stack/ |
| pooler.autoscaling | object | {"controlledResources":["cpu","memory"],"controlledValues":"RequestsOnly","enabled":false,"maxAllowed":{},"minAllowed":{},"updatePolicy":{"updateMode":"InPlaceOrRecreate"}} | Vertical pod autoscaler |
| pooler.autoscaling.controlledResources | list | ["cpu","memory"] | Resource to control Possible values are "cpu" and "memory" |
| pooler.autoscaling.controlledValues | string | "RequestsOnly" | Controls which resource value should be autoscaled Possible values are "RequestsAndLimits" and "RequestsOnly" |
| pooler.autoscaling.maxAllowed | object | {} | Max allowed resources for the pod default is resources.limits |
| pooler.autoscaling.minAllowed | object | {} | Min allowed resources for the pod default is resources.requests |
| pooler.autoscaling.updatePolicy | object | {"updateMode":"InPlaceOrRecreate"} | Update policy Possible values are "Off", "Initial", "Recreate", "InPlaceOrRecreate" and "Auto" |
| pooler.resources.limits.cpu | string | "500m" | |
| pooler.resources.limits.memory | string | "64Mi" | |
| pooler.resources.requests.cpu | string | "100m" | |
| pooler.resources.requests.memory | string | "32Mi" | |
| pooler.priorityClassName | string | nil | Priority Class Name ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass |
| pooler.podAntiAffinityPreset | string | "soft" | Pod Anti Affinity soft/hard |
| pooler.podAntiAffinityPresetKey | string | "kubernetes.io/hostname" | |
| pooler.nodeSelector | object | {} | Node labels for pod assignment. ref: https://kubernetes.io/docs/user-guide/node-selection/ |
| pooler.tolerations | list | [] | Tolerations for pod assignment. ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ |
| pooler.affinity | object | {} | Affinity for pod assignment. ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity |
| initContainers | list | [] | |
| serviceAccount | object | {"annotations":{},"create":true,"name":""} | Pods Service Account. ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ |
| podlabels | object | {} | Extra labels for pod. ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ |
| podAnnotations | object | {} | Annotations for pod. ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ |
| podSecurityContext | object | {"fsGroup":999,"fsGroupChangePolicy":"OnRootMismatch","runAsGroup":999,"runAsNonRoot":true,"runAsUser":999} | Pod Security Context. ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod |
| securityContext | object | {"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"seccompProfile":{"type":"RuntimeDefault"}} | Container Security Context. ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod |
| service | object | {"ipFamilies":["IPv4"],"port":5432,"type":"ClusterIP"} | Service parameters ref: https://kubernetes.io/docs/user-guide/services/ |
| service.ipFamilies | list | ["IPv4"] | IP families for service possible values: IPv4, IPv6 ref: https://kubernetes.io/docs/concepts/services-networking/dual-stack/ |
| postgresqlServerMemory | string | "128" | Specifies the expected memory usage |
| postgresqlServerWalWriterDelay | string | "200ms" | Specifies how often the WAL writer flushes WAL (wal_writer_delay) ref: https://www.postgresql.org/docs/current/runtime-config-wal.html |
| autoscaling | object | {"controlledResources":["cpu","memory"],"controlledValues":"RequestsOnly","enabled":false,"maxAllowed":{},"minAllowed":{},"updatePolicy":{"updateMode":"InPlaceOrRecreate"}} | Vertical pod autoscaler |
| autoscaling.controlledResources | list | ["cpu","memory"] | Resource to control Possible values are "cpu" and "memory" |
| autoscaling.controlledValues | string | "RequestsOnly" | Controls which resource value should be autoscaled Possible values are "RequestsAndLimits" and "RequestsOnly" |
| autoscaling.maxAllowed | object | {} | Max allowed resources for the pod default is resources.limits |
| autoscaling.minAllowed | object | {} | Min allowed resources for the pod default is resources.requests |
| autoscaling.updatePolicy | object | {"updateMode":"InPlaceOrRecreate"} | Update policy Possible values are "Off", "Initial", "Recreate", "InPlaceOrRecreate" and "Auto" |
| resources | object | {"requests":{"cpu":"100m","memory":"128Mi"}} | Resource requests and limits. ref: https://kubernetes.io/docs/user-guide/compute-resources/ |
| persistence | object | {"accessModes":["ReadWriteOnce"],"annotations":{},"enabled":false,"mountPath":"/database","size":"8Gi"} | Persistence parameters ref: https://kubernetes.io/docs/user-guide/persistent-volumes/ |
| priorityClassName | string | nil | Priority Class Name ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass |
| terminationGracePeriodSeconds | int | 120 | The time in seconds that is allowed for a PostgreSQL instance to gracefully shutdown ref: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks |
| updateStrategy.type | string | "RollingUpdate" | |
| backup.enabled | bool | false | |
| backup.recovery | bool | false | |
| backup.recoveryMethod | string | "backup" | |
| backup.walpush | bool | false | |
| backup.walgSecrets | string | "" | |
| backup.walg | object | {} | |
| backup.walgSourceConfig | string | nil | |
| backup.cleanPolicy | string | "retain FULL 3" | |
| backup.schedule | string | "15 4 * * *" | Backup schedule. set value "" to disable cron backup refs: https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ |
| backup.resources | object | {"limits":{"cpu":2,"memory":"4Gi"},"requests":{"cpu":"1500m","memory":"768Mi"}} | Resource requests and limits. ref: https://kubernetes.io/docs/user-guide/compute-resources/ |
| backup.priorityClassName | string | nil | Priority Class Name ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass |
| backup.podAffinityPreset | string | "hard" | |
| backupCheck.enabled | bool | false | |
| backupCheck.schedule | string | "15 8 * * *" | |
| backupCheck.resources | object | {"limits":{"cpu":2,"memory":"1Gi"},"requests":{"cpu":"100m","memory":"512Mi"}} | Resource requests and limits. ref: https://kubernetes.io/docs/user-guide/compute-resources/ |
| backupCheck.persistence | object | {"accessModes":["ReadWriteOnce"],"annotations":{},"size":"8Gi"} | Persistence parameters ref: https://kubernetes.io/docs/user-guide/persistent-volumes/ |
| backupCheck.nodeSelector | object | {} | Node labels for pod assignment. ref: https://kubernetes.io/docs/user-guide/node-selection/ |
| backupCheck.tolerations | list | [] | Tolerations for pod assignment. ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ |
| backupCheck.affinity | object | {} | Affinity for pod assignment. ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity |
| metrics.enabled | bool | false | |
| metrics.image.repository | string | "quay.io/prometheuscommunity/postgres-exporter" | |
| metrics.image.pullPolicy | string | "IfNotPresent" | |
| metrics.image.tag | string | "v0.11.1" | |
| metrics.database | string | "postgres" | |
| metrics.username | string | "postgres" | |
| metrics.slowQueries | bool | true | |
| metrics.queries | string | `"{{- if eq .Values.installationType "standalone" }}\npg_replication:\n query: SELECT CASE WHEN NOT pg_is_in_recovery() THEN 0 ELSE GREATEST (0, EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))) END AS lag\n metrics:\n - lag:\n usage: "GAUGE"\n description: "Replication lag behind master in seconds"\npg_postmaster:\n query: SELECT pg_postmaster_start_time as start_time_seconds from pg_postmaster_start_time()\n metrics:\n - start_time_seconds:\n usage: "GAUGE"\n description: "Time at which postmaster started"\n{{- end }}\n{{- if and .Values.metrics.slowQueries (regexMatch "^[0-9]+\\.[0-9]+$" .Values.image.tag) (semverCompare ">=14.0" (default .Chart.AppVersion .Values.image.tag)) }}\npg_stat_slow_queries:\n query: SELECT pg_get_userbyid(userid) as rolname,t3.datname,queryid,calls,max_exec_time / 1000 as max_time_seconds,REGEXP_REPLACE(substring(query,1,200),'["\n\s\t]+',' ','g') as sql FROM pg_stat_statements t1 JOIN pg_database t3 ON (t1.dbid=t3.oid) WHERE datname != 'postgres' AND rows != 0 AND max_exec_time > 1000 ORDER BY max_exec_time DESC LIMIT 10\n metrics:\n - rolname:\n usage: "LABEL"\n description: "Name of user"\n - datname:\n usage: "LABEL"\n description: "Name of database"\n - queryid:\n usage: "LABEL"\n description: "Query ID"\n - sql:\n usage: "LABEL"\n description: "SQL"\n - calls:\n usage: "COUNTER"\n description: "Number of times executed"\n - max_time |
Deploy postgresql-single with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has postgresql-single 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-single is pinned at v1.16.0 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