spqr-router

by Das Meta

Helm chartv0.1.1App 2.8.0

Stateless Postgres Query Router (SPQR) Helm chart using dasmeta/base.

About this chart

SPQR Router Helm Chart

This chart deploys the Stateless Postgres Query Router (SPQR) router component using the shared dasmeta/base chart as a dependency.
It is intended to be published together with the other charts in this repository and to be used as an easy way to run pgsharding/spqr-router in Kubernetes.

The Docker image used by default is pgsharding/spqr-router.

Requirements

  • Kubernetes 1.18+
  • Helm 3.7.1+

Installation

Add the dasmeta repository and install the chart:

helm repo add dasmeta https://dasmeta.github.io/helm
helm repo update

helm upgrade --install spqr-router dasmeta/spqr-router \
  --namespace default \
  -f values.yaml

Public values: values.yaml. Examples: examples/spqr-router/. From repo root: helm template test charts/spqr-router -f examples/spqr-router/minimal.yaml.

Configuration

This chart is a thin wrapper around the base chart:

  • SPQR router–specific configuration lives at the root in routerConfig and is rendered into a ConfigMap (router.yaml) consumed by the router.
  • Pod / service / lifecycle settings for the router are configured under the spqr key and passed to the base dependency via its alias.
  • For all non–SPQR-specific options (ingress, HPA, topology spread, external secrets, rolloutStrategy, etc.) refer to the base chart documentation in charts/base/README.md.

Important spqr values (pod & service)

KeyDescriptionDefault
spqr.image.repositoryContainer image repositorypgsharding/spqr-router
spqr.image.tagContainer image tag (SPQR Router version)2.8.0
spqr.replicaCountNumber of router replicas1
spqr.containerPortContainer port where router listens7432
spqr.service.portService port7432
spqr.resourcesResource requests/limits for the SPQR router containersee values.yaml
spqr.livenessProbeLiveness probe configurationTCP check on port 7432
spqr.readinessProbeReadiness probe configurationTCP check on port 7432
spqr.volumesVolume mount wiring the generated router.yamlmounts at /config/router.yaml
spqr.extraEnvExtra environment variables for the routerpoints to config file path

You can also set any other base-supported fields (e.g. ingress, autoscaling, topologySpreadConstraints) under spqr if you need them.

routerConfig – SPQR router configuration

The routerConfig map is rendered directly to router.yaml via the chart’s ConfigMap template and is the primary place to define SPQR behaviour.

KeyDescriptionDefault / Example
routerConfig.listen_addrAddress where router listens for Postgres connections"0.0.0.0:7432"
routerConfig.admin_addr(Optional) admin / management endpointcommented out by default
routerConfig.shardsList of shards and backend Postgres connection infoexample in values.yaml
routerConfig.coordinator(Optional) coordinator connection settingsexample in values.full.yaml

See the upstream SPQR documentation at https://github.com/pg-sharding/spqr for all supported configuration fields.

Example: basic router deployment

Minimal values file (see also examples/base/spqr-basic.values.yaml in this repo):

spqr:
  image:
    repository: pgsharding/spqr-router
    tag: "2.8.0"

  service:
    type: ClusterIP
    port: 7432

Install with:

helm upgrade --install spqr-router dasmeta/spqr-router -f spqr-basic.values.yaml

Example: router with configuration defined in values.yaml

SPQR is typically configured via a YAML file passed to the router. With this chart the configuration is delivered via routerConfig and rendered into router.yaml which is mounted into the router container:

spqr:
  replicaCount: 2
  image:
    repository: pgsharding/spqr-router
    tag: "2.8.0"
  service:
    port: 7432

routerConfig:
  listen_addr: "0.0.0.0:7432"
  admin_addr: "0.0.0.0:7433"
  # shards:
  #   - name: shard1
  #     db:
  #       host: "postgres-1"
  #       port: 5432
  #       user: "spqr"
  #       password: "spqr"

Install:

helm upgrade --install spqr-router dasmeta/spqr-router -f spqr-with-config.values.yaml

Notes

  • This chart only provides the router component. You are expected to provision PostgreSQL instances / shards and SPQR coordinator/balancer components separately according to the official SPQR documentation at https://github.com/pg-sharding/spqr.

Deploy spqr-router with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has spqr-router 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 chartspqr-router is pinned at v0.1.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