postgresql

by joaquinito2051

Helm chartv0.7.1

Object-relational database management system (ORDBMS) with an emphasis on extensibility and on standards-compliance. Patched version for pvc

About this chart

PostgreSQL

PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness.

TL;DR;

$ helm install stable/postgresql

Introduction

This chart bootstraps a PostgreSQL deployment on a Kubernetes cluster using the Helm package manager.

Prerequisites

  • Kubernetes 1.4+ with Beta APIs enabled
  • PV provisioner support in the underlying infrastructure (Only when persisting data)

Installing the Chart

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

$ helm install --name my-release stable/postgresql

The command deploys PostgreSQL on the Kubernetes cluster in the default configuration. The configuration section lists the parameters that can be configured during installation.

Tip: List all releases using helm list

Uninstalling the Chart

To uninstall/delete the my-release deployment:

$ helm delete my-release

The command removes all the Kubernetes components associated with the chart and deletes the release.

Configuration

The following tables lists the configurable parameters of the PostgresSQL chart and their default values.

ParameterDescriptionDefault
imagepostgres image repositorypostgres
imageTagpostgres image tag9.6.2
imagePullPolicyImage pull policyAlways if imageTag is latest, else IfNotPresent
postgresUserUsername of new user to create.postgres
postgresPasswordPassword for the new user.random 10 characters
postgresDatabaseName for new database to create.postgres
postgresInitdbArgsInitdb Argumentsnil
persistence.enabledUse a PVC to persist datatrue
persistence.existingClaimProvide an existing PersistentVolumeClaimnil
persistence.storageClassStorage class of backing PVCnil (uses alpha storage class annotation)
persistence.accessModeUse volume as ReadOnly or ReadWriteReadWriteOnce
persistence.sizeSize of data volume8Gi
persistence.subPathSubdirectory of the volume to mount atpostgresql-db
resourcesCPU/Memory resource requests/limitsMemory: 256Mi, CPU: 100m
metrics.enabledStart a side-car prometheus exporterfalse
metrics.imageExporter imagewrouesnel/postgres_exporter
metrics.imageTagExporter imagev0.1.1
metrics.imagePullPolicyExporter image pull policyIfNotPresent
metrics.resourcesExporter resource requests/limitMemory: 256Mi, CPU: 100m
metrics.customMetricsAdditional custom metricsnil
service.externalIPsExternal IPs to listen on[]
service.portTCP port5432
service.typek8s service type exposing ports, e.g. NodePortClusterIP

The above parameters map to the env variables defined in postgres. For more information please refer to the postgres image documentation.

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \
  --set postgresUser=my-user,postgresPassword=secretpassword,postgresDatabase=my-database \
    stable/postgresql

The above command creates a PostgresSQL user named root with password secretpassword. Additionally it creates a database named my-database.

Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,

$ helm install --name my-release -f values.yaml stable/postgresql

Tip: You can use the default values.yaml

Persistence

The postgres image stores the PostgreSQL data and configurations at the /var/lib/postgresql/data/pgdata path of the container.

The chart mounts a Persistent Volume volume at this location. The volume is created using dynamic volume provisioning. If the PersistentVolumeClaim should not be managed by the chart, define persistence.existingClaim.

Existing PersistentVolumeClaims

  1. Create the PersistentVolume
  2. Create the PersistentVolumeClaim
  3. Install the chart
$ helm install --set persistence.existingClaim=PVC_NAME postgresql

The volume defaults to mount at a subdirectory of the volume instead of the volume root to avoid the volume's hidden directories from interfering with initdb. If you are upgrading this chart from before version 0.4.0, set persistence.subPath to "".

Metrics

The chart optionally can start a metrics exporter for prometheus. The metrics endpoint (port 9187) is not exposed and it is expected that the metrics are collected from inside the k8s cluster using something similar as the described in the example Prometheus scrape configuration.

The exporter allows to create custom metrics from additional SQL queries. See the Chart's values.yaml for an example and consult the exporters documentation for more details.

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 v0.7.1 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