Skip to content

Kubernetes

Mohammad Rasoul Kazemi edited this page Dec 3, 2026 · 1 revision

Kubernetes

Not released. Planned for release 0.3.0. KingresDB on Kubernetes (phase 21) is built on the main branch (kingres-18) and is not in any 0.2.x release. The chart and the images are not published yet. There is no console or operator upgrade of a cluster of pods in 0.3.0: the upgrade is a manual procedure (below). Nothing here is a promise until the release.

Phase 21 gives KingresDB a Helm chart (kingres-cluster) and an operator (kingres-operator, with the resource KingresCluster). It changes no REST contract (the contract stays as it is on the main branch). The full guide is kubernetes.md in the repository; the files are in kingres/deploy/helm/kingres-cluster/ and kingres/operator/. For the phase and its place in the plan see Status and Roadmap.

The model

One pod is one KingresDB server. Inside the pod, kingresd runs the server's primary and the standbys of other groups, as it does on a machine. Kubernetes starts, stops and schedules pods; kingresd stays the only authority over the cluster: leases, fencing, failover, standbys, adding and removing servers and the settings of PostgreSQL. The chart and the operator make Kubernetes objects and ask kingresd through REST for everything else. They never promote a standby, never restart an instance and never delete a pod or a volume claim on their own (the operator deletes a pod only after a drain, for a scale-down). See High Availability.

The server id is the stable DNS name of the pod, <release>-<n>.kingres-hl.<namespace>.svc, at most 63 characters. So a cluster is named once and cannot be renamed, and a namespace holds one cluster. Use a short release name and a namespace of its own.

The chart and the operator

  • The chart kingres-cluster makes a StatefulSet with one pod per server, the headless, client and console Services, a volume claim per pod, the pod security of the compose file (the pod meets the Pod Security Standard "restricted"), probes, a 180 s stop, a PodDisruptionBudget, a NetworkPolicy, the setup token seeded by an init container, a formation Job and an optional Ingress for the console. It refuses to render, and says what to set, when a required value is missing or wrong (the PostgreSQL major, 18 or 19, is never defaulted and cannot change; the memory; a name that is too long).
  • The operator kingres-operator does what the chart alone cannot (next section). Its resource KingresCluster (db.kingresdb.com/v1alpha1, with validation rules) describes the cluster; the operator forms it, adopts an existing one, scales up, scales down by a drain, keeps the disruption budget, runs a finalizer, manages TLS of its own or through cert-manager, rotates its own password and can make the console Ingress. An optional admission policy narrows its rights.
  • kingresd settings added for this: orchestrator, peer-address-refresh (a pod that gets a new address is found again), trusted-proxies, the reload of the REST certificate without a restart, and the memory of a server under a container limit (the limit replaces the memory of the node in the figures).

What you need

  • Kubernetes 1.35 or newer, amd64 nodes (the server image is amd64 only), a storage class with ReadWriteOnce volumes that honour fsGroup, and a network plugin that enforces NetworkPolicy (otherwise the policy does nothing).
  • A TLS certificate for the REST port (the chart never serves plain HTTP), from cert-manager or from a Secret of yours.
  • Memory: the container limit, 8 GiB or more for production. Size a pod for the worst case after a failover, when it holds more primaries than usual.
  • Storage: one volume per server, at least (1 + standbys) x data per group x 1.3.

The install is: make the Secrets first (the bootstrap administrator, the operator password, the formation key), write a values file (postgresMajor, servers, resources, storage, auth, tls, scheduling) and run helm install on the chart. The pods start empty; the formation Job then initialises server 0 and joins the others. Sign in to the console as the bootstrap user, change the password and delete that Secret. The exact commands are in the guide.

What the chart alone cannot do

These are procedures for you with the chart; the operator does them.

  • Scale down. Drain and remove the server first (kingres-cli server drain <id> --remove-when-done --wait, see Command Line Client), then lower servers by exactly one with helm upgrade. A StatefulSet otherwise removes its highest pod without a drain. The claim stays.
  • A lost node. A pod on an unreachable node stays Terminating; the chart never force-deletes it. Once you know the node is gone, taint it node.kubernetes.io/out-of-service or delete the node object. Failover is kingresd's and is off by default, so fail the groups over by hand or switch it on in the console.
  • A change of the memory limit is restarted by you.
  • Upgrade (below).
  • Backup. A snapshot of the volumes is not a backup of a cluster of several groups, and a namespace is not a backup either: deleting it deletes the claims. See Backup Restore and PITR.

helm uninstall leaves the volume claims and the Secrets; installing again with the same name in the same namespace adopts the cluster. With the operator, delete the KingresCluster first and the namespace after it, or the resource stays in Terminating until you remove its finalizer by hand.

The CA key

The first server holds the key of the certificate authority of the cluster. With the escrow on (the default), a sealed copy goes to the servers that can become the manager leader, once a standby of the map group is ready. With the escrow off, copy the key off the cluster. Without it a cluster cannot add a server or renew a certificate.

Upgrade: manual in 0.3.0

There is no console or operator upgrade on Kubernetes in 0.3.0. The upgrade of phase 19 (see Upgrades) does not offer a cluster of pods, and the operator reports UpgradeUnsupported and changes nothing. The update run for pods and the operator's update controller come later (0.3.1 or 0.4.0). A new chart version changes the template and restarts nothing.

The manual procedure, one KingresDB version to the next of the same PostgreSQL major, after a backup and after pulling the new image on the nodes:

  1. Change the image of the StatefulSet. Nothing restarts.
  2. Delete the pods one at a time, the server of the manager leader last. After each one wait until the pod is Ready on the new image, every server is live and every standby streams with a small lag.
  3. When every pod runs the new image, update the extensions in every database, on every primary instance of every server (see Upgrades).
  4. Check that the alert versionMismatch is gone and every server is live.

While the pods differ, the cluster is mixed: distributed scans fail until the extensions are updated, no server is added or removed, and there is no switchover. There is no rollback; the backup is the way back. The script kingres/deploy/test/upgrade/test-upgrade.sh runs exactly these steps on a cluster of pods.

What was tested

Offline: helm lint, render and golden tests, and kubeconform against Kubernetes 1.35 to 1.37; for the operator, unit tests with a fake client and a fake kingresd.

On clusters (kind, with images built from the branch): Kubernetes 1.37.0 (one control plane, three workers) with PostgreSQL 18 and 19, and Kubernetes 1.35.8 with PostgreSQL 18; k3d with Traefik earlier. The scenarios:

Scenario Result
Formation, with the operator killed during it pass
Scale-up (a join) and scale-down (a drain and removal), also with the operator killed pass
A node lost (a stopped node): the failover of kingresd ran with nothing paused and no decision asked pass
A vanished server (a paused node whose connections hang): the failover ran, then a scale-up pass, except the run below
The disruption budget follows a dead server pass
The finalizer on delete, and adoption by a new resource pass
One cluster per namespace pass
Pod Security "restricted", the network policy, ingress-nginx and Traefik, the reload of the certificate, a pod with a new address, a cold start of all pods pass
The manual upgrade procedure, on PostgreSQL 18 and 19 pass

The operator logs no promote, fence or failover call in these runs: failover stayed kingresd's. In 0.2.1 the failover of a vanished server began about 14 minutes late; on these runs it begins after about 30 to 120 seconds.

Not proved: storage classes other than the local provisioner; managed Kubernetes services (expected to work, not tested by the project); the packaging of PostgreSQL 19 for the earliest runs (the PostgreSQL 19 image was the released 0.2.0 image with the branch kingresd copied over it; the later runs built the images from the branch tree); any automatic upgrade.

Known issue under follow-up: a paused failover under a DNS outage

On one PostgreSQL 19 run on Kubernetes 1.37.0 (the first of two), the failover of a vanished server started after 40 s and then paused in its step "Make the catalog follow", with a refused connection to a peer (could not connect to node ...). The PostgreSQL log shows name resolution failing for about four minutes during the pause, probably because a cluster DNS (CoreDNS) replica was on the paused node. The failover stayed paused after the node came back, and the scale-up and the disruption-budget check after it failed. A second run, with the CoreDNS pods moved off the victim node first, passed, and so did the same scenario on PostgreSQL 18 (both Kubernetes versions). This is the failover of kingresd, not of the operator, and it is being followed up apart; until it is closed, do not count on a paused failover finishing by itself when the cluster DNS is lost together with a server, and keep the cluster DNS replicas away from a single node. See Runbooks and Limitations and Known Issues.

Limits of the first version

Not supported: OpenShift's restricted user numbers (the image runs as 10001), an ARM server image, an IPv6-only cluster, more than one cluster per namespace, one REST certificate per pod (the certificate is shared), volume expansion by the operator, a second volume for the WAL, and a Gateway API route for the console. Drift is found by a hash, not by comparing the live object, so do not edit the objects of the operator by hand; change the resource. The operator pod has no NetworkPolicy of its own and its metrics and health ports are plain HTTP: restrict them yourself where the network is shared. Replacing the operator's own CA has no overlap (years away).

KingresDB

1. Product

Features in detail

Administration

2. Architecture (arc42)

3. Data architecture

4. Development

5. Operations

Clone this wiki locally