postgresql

by sanghyuk-lee-lvgs

Helm chartv0.1.2App 16

A Helm chart for PostgreSQL database with support for local and cloud deployments

About this chart

PostgreSQL Helm Chart

This Helm chart deploys PostgreSQL database on Kubernetes with support for both local and cloud deployments.

Features

  • Uses official PostgreSQL Docker image from Docker Hub
  • Supports two deployment modes:
    • Local: StatefulSet + Service + Secret for local deployment
    • Cloud: Deployment + PV + PVC + Service (LoadBalancer) + Secret for cloud deployment
  • Configurable resources, persistence, and security settings
  • Health checks and probes for reliability

Prerequisites

  • Kubernetes 1.19+
  • Helm 3.0+

Installing the Chart

Local Deployment

helm install my-postgresql ./charts/postgresql \
  --set deploymentType=local \
  --set postgresql.auth.password=mypassword

Cloud Deployment

helm install my-postgresql ./charts/postgresql \
  --set deploymentType=cloud \
  --set postgresql.auth.password=mypassword \
  --set cloud.service.type=LoadBalancer

Configuration

The following table lists the configurable parameters and their default values.

Global Configuration

ParameterDescriptionDefault
deploymentTypeDeployment type: "local" or "cloud""local"

PostgreSQL Configuration

ParameterDescriptionDefault
postgresql.image.repositoryPostgreSQL image repositorypostgres
postgresql.image.tagPostgreSQL image tag"16"
postgresql.image.pullPolicyImage pull policyIfNotPresent
postgresql.auth.usernamePostgreSQL usernamepostgres
postgresql.auth.passwordPostgreSQL passwordchangeme
postgresql.auth.databasePostgreSQL database namepostgres
postgresql.auth.existingSecretUse existing secret for credentials""

Local Deployment Configuration

ParameterDescriptionDefault
local.replicaCountNumber of replicas1
local.service.typeService typeClusterIP
local.service.portService port5432
local.persistence.enabledEnable persistencetrue
local.persistence.sizeStorage size8Gi
local.persistence.storageClassStorage class""
local.resources.limits.cpuCPU limit500m
local.resources.limits.memoryMemory limit512Mi

Cloud Deployment Configuration

ParameterDescriptionDefault
cloud.replicaCountNumber of replicas1
cloud.service.typeService typeLoadBalancer
cloud.service.portService port5432
cloud.persistence.enabledEnable persistencetrue
cloud.persistence.sizeStorage size20Gi
cloud.persistence.storageClassStorage class""
cloud.persistence.persistentVolume.enabledCreate PVtrue
cloud.persistence.persistentVolume.capacityPV capacity20Gi
cloud.resources.limits.cpuCPU limit1000m
cloud.resources.limits.memoryMemory limit1Gi

Examples

Using with existing secret

kubectl create secret generic my-postgres-secret \
  --from-literal=POSTGRES_USER=myuser \
  --from-literal=POSTGRES_PASSWORD=mypassword \
  --from-literal=POSTGRES_DB=mydatabase

helm install my-postgresql ./charts/postgresql \
  --set postgresql.auth.existingSecret=my-postgres-secret

Cloud deployment with specific storage class

helm install my-postgresql ./charts/postgresql \
  --set deploymentType=cloud \
  --set cloud.persistence.storageClass=fast-ssd \
  --set postgresql.auth.password=securepassword

Connecting to PostgreSQL

After installation, you can connect to PostgreSQL using:

# Get the service name
kubectl get svc -l "app.kubernetes.io/name=postgresql"

# Forward port for local access
kubectl port-forward svc/my-postgresql 5432:5432

# Connect using psql
psql -h localhost -U postgres -d postgres

Uninstalling the Chart

helm uninstall my-postgresql

License

This chart is licensed under the Apache License 2.0.

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