Skip to content
Opod

Install

High availability

Run several control-plane replicas over one database with leader election and a shared event bus, your own or provided by the chart.

In short

One control-plane replica is a complete install, and endpoints keep serving while it restarts. Run three replicas when the API and the console must not blink during a node loss or an upgrade. Every replica serves the API; one at a time runs the control loops, chosen by a Kubernetes Lease. They need a shared Postgres and a shared event bus (NATS), your own or provided by the chart.

When you need it

  • The console or the API is part of an on-call workflow and must stay up through a node drain.
  • Automation (CI, GitOps, a gateway that reads plans) calls the API and cannot wait a few minutes for a reschedule.
  • A replica's doctor row reads blocked, and you must decide between granting the Lease and turning election off.

Do it

These steps use your own Postgres and NATS. To let the chart run them instead, see Or let the chart provide them. For an on-premises datacenter, the on-prem profile does it in one file.

  1. Point the state store at your Postgres

    Several replicas need a database every replica reaches. Put its whole DSN in a Secret:

    kubectl -n opodcp create secret generic opod-state-dsn \
      --from-literal=dsn='postgres://opod:PASSWORD@db.example.com:5432/opodcp?sslmode=require'

    To move an existing store there first, use opodcp store move (Backup and restore).

  2. Scale out

    helm upgrade opodcp oci://ghcr.io/opod-io/charts/opodcp -n opodcp --reset-then-reuse-values \
      --set replicas=3 --set ports.state.dsnSecret.name=opod-state-dsn
  3. Connect the event bus

    On the Connectors page, save OPODCP_EVENTS_URL=nats://nats.example.com:4222 (an optional path is the subject prefix, for example /opod). A user and password in it are stored sealed. The save restarts the control plane once. Every event is then mirrored to <prefix>.<type>, and events from other replicas fan out locally. The bus is core NATS (no JetStream stream), and its user needs publish and subscribe on <prefix>.> and, after 0.3.6, on <prefix>_observe.>: see Connector setup → NATS. With SSO, give the control plane's host sticky sessions at your ingress: in 0.3.6 a login's state lives on the replica that started it (why).

  4. Check

    On the lease holder, opodcp doctor shows the controllers row in mode leader with its loop count; on each other replica it reads standby — <holder> holds the lease <namespace>/opodcp-controllers and runs the loops. The events row is green on every replica.

Check it worked

kubectl -n opodcp get pods -l app.kubernetes.io/name=opodcp -o wide
kubectl -n opodcp get lease opodcp-controllers -o jsonpath='{.spec.holderIdentity}{"\n"}'
for p in $(kubectl -n opodcp get pods -l app.kubernetes.io/name=opodcp -o name); do
  kubectl -n opodcp exec "$p" -- /opodcp doctor | grep -E '^. (controllers|events) '
done

A good answer: three Running pods on three different nodes; the Lease names one pod as <pod name>-<pid> on 0.2.1, and as <pod name>-<8 hex digits> (a new value at each start) in 0.3.0. On that pod the controllers row reads ✔ controllers N loops leader …. On each other pod it reads ✔ controllers standby elected standby — … holds the lease opod/opodcp-controllers and runs the loops, and the events row is ✔ on all three. The console's Settings → Controller loops shows the loops and their last run.

To prove the hand-over, delete the holder and watch a standby take the Lease. A deleted pod stops cleanly, so on 0.2.1 this takes up to about 19 s and in 0.3.0 about 4 s:

kubectl -n opodcp delete pod "$(kubectl -n opodcp get lease opodcp-controllers -o jsonpath='{.spec.holderIdentity}' | sed 's/-[^-]*$//')"
kubectl -n opodcp get lease opodcp-controllers -w

If it fails

SymptomCauseFix
replicas > 1 cannot run under nodeSelector kubernetes.io/hostnamethe release is pinned to one noderemove the hostname from nodeSelector
A replica stays Pending with didn't match pod anti-affinity rulesfewer schedulable nodes than replicasopodcp preflight --replicas 3 (row ha.nodes); add or uncordon nodes
events red on a standby, naming the replica it does not hearno shared event bussave OPODCP_EVENTS_URL on Connectors, or --set ha.nats.provide=true
Every API call answers 503 E-DB-UNREACHABLE, and /readyz still answers 200the database is down or unreachable from the replicas. By design the replicas stay Ready, so that each caller hears "database unreachable" and not a connection refused; each replica reconnects by itselfbring the database back; opodcp doctor row state names its host
controllers reads blockedthe ServiceAccount cannot get, create or update the Leasegrant coordination.k8s.io/leases in the namespace
controllers red: NO replica is running the loops: the lease … has not been renewed for …the holder crashed, or the role may read the Lease but not update itgrant update on leases; the next replica then takes it
ha.postgres.provide and ports.state.dsn (or its Secret) are both seta provided and an own database at oncekeep one
A pod refuses to start under a provided Postgres after a rollbackan image older than the HA profile does not know postgresql://roll forward again

How replicas work in detail

One replica is a complete install. The pod keeps nothing on disk, so losing its node costs only the minutes Kubernetes takes to reschedule it, and endpoints keep serving meanwhile. Run more replicas when the API and the console must not blink.

Who does what

  • Every replica serves the API and the console. Reads and writes go to the shared database, so they are safe from any replica.
  • One replica runs the controller loops: the reconciler, the autoscaler, the run resumer, the usage shipper (and the usage puller, for a leader too old to push), retention and alerts. It holds the Lease <namespace>/opodcp-controllers; the identity in it is <pod hostname>-<pid> on 0.2.1, and <pod hostname>-<random> with a new random part at each start in 0.3.0. The others are warm standbys: the doctor's controllers row reads standby and names the holder.
  • Only the lease holder runs a create, rollout or rollback. Any replica accepts one and answers at once. In 0.3.0 a standby writes the run to the database and the holder starts it within 2 s, and one replica runs each run once. On 0.2.1 the replica that accepted the run ran it. A create accepted by a replica just before it took the Lease could then run twice: the two runs deleted each other's prefetch Job (jobs.batch "…-prefetch-…" not found) and the create rolled back. Start it again once kubectl -n opodcp get lease opodcp-controllers shows a holder.
  • Replicas share one database and judge capacity against it as one unit, so two replicas never double-book a card. Replicas survive a node only if the database does: the chart's Postgres (ha.postgres.provide) runs three instances with failover. A single-instance database of your own must not share a node with a replica, or that node's death stops the database and a replica together.
  • Replicas need a shared event bus. Without one, the console's live stream on one replica misses what another publishes, and a standby's events doctor row turns red naming the replica it does not hear.

How callers reach a replica

Nothing outside the control plane knows there are several replicas. Every caller uses one address, the release's Service http://<release>.<namespace>.svc:8080, and Kubernetes sends each new connection to a replica whose /readyz passes:

CallerWhat it sendsWhen a replica dies
A leaderits usage records (OTLP), each freed only on the control plane's 2xxthe leader keeps them in its queue and sends again; the retry reaches a live replica, and a record stored twice is one row (key: endpoint, leader boot, sequence)
The GPU telemetry podseach node's card readingsthe next reading reaches a live replica
The console, the CLI, your automationAPI calls and the live event streamthey reconnect; through an Ingress or a Gateway (ingress.*) the route points at the same Service

The control plane sends plans, keys and policy to a leader as mounted files, and never calls it on the request path. The leader therefore serves whichever replica is up, or none.

Any replica takes a leader's usage push. In 0.2.1 a replica that did not hold the Lease stored those rows without the card's GPU class for two minutes after it started. From 0.3.0 it reads the endpoint's pods itself and names the card.

In 0.2.1 each replica kept its own record of how each leader's usage arrives, so GET /api/v1/usage/streams and the console answered differently depending on the replica they reached (one read lastBatch 0). From 0.3.0 the record is kept in the database and every replica gives the same answer.

An endpoint's status (GET /api/v1/endpoints/<id>/status, and the console's model and leader badges) carries what the lease holder's watch loop last saw: the leader's serving proof (proof) and each worker's loaded models. Up to 0.3.6 only the holder had them. A standby answered from the pods alone, with no proof and every loaded empty, so a console polling through the Service saw the badges change between two answers. In the release after 0.3.6, the holder sends each endpoint's observation to the other replicas over the shared NATS bus, on the subject <prefix>_observe.<endpoint>, after each watch tick (every 5 s), and every replica gives the same answer. The observation is not journaled and does not appear on the event stream. A standby uses it for 30 s. If the holder dies, the standby answers from the pods until it takes the Lease and observes for itself. The doctor's events row counts the observations each replica sent and received. With one replica, or no bus, nothing is sent and nothing changes.

What the chart does when replicas is above 1

ObjectSetting
Deployment strategyRollingUpdate, one replica at a time (maxSurge: 0, maxUnavailable: 1); one replica uses Recreate. In 0.2.1 the roll used the default surge, which never finishes when there are as many nodes as replicas: the new pod stays Pending. On 0.2.1, delete the oldest replica's pod and the roll goes on
Pod anti-affinityrequired, on kubernetes.io/hostname: each replica runs on a node of its own
Topology spreadmaxSkew: 1 on topology.kubernetes.io/zone, ScheduleAnyway
PodDisruptionBudgetminAvailable: replicas - 1, so a node drain takes at most one replica at a time
Preflight hookits pod is labelled app.kubernetes.io/name: opodcp-preflight, so the replicas' anti-affinity does not apply to it. In 0.2.1 it carried the replicas' labels: with as many labelled nodes as replicas, helm upgrade hung at the pre-upgrade hook with the pod Pending. On 0.2.1, label one more node for the control plane (nodeSelector) before the upgrade

The chart refuses replicas above 1 together with nodeSelector: {kubernetes.io/hostname: …}: one hostname is one node. Remove the pin; the database keeps the state. Each replica needs a Ready, schedulable node: run opodcp preflight --replicas 3 first and read row ha.nodes.

The lease

TimingValue
lease duration15 s. After a holder crashes (no clean stop), a standby takes the lease once it has not seen a renewal for 15 s, at its next retry: up to about 17 s. Measured on a two-replica install: about 17 s after a SIGKILL of the holder's process, 15 s after every pod on the holder's node was killed
holder crash, restarted in placeon 0.2.1, if the kubelet restarts the crashed container before a standby takes the lease, the same pod takes it back as its own: the Lease names <pod name>-1 again (the control plane is process 1 in its container) and shows no transition. The loops stop for as long as the restart takes, which grows with each restart (16.8 s measured on a second restart). In 0.3.0 each start has a new identity, so a restarted holder waits out the lease like any standby: up to about 17 s (17.3 s measured), and the Lease records the transition
renew deadline10 s: a holder that cannot renew in time stands down before the lease can go to anyone else
retry period2 s
clean stop (a roll, a drain, helm upgrade)on 0.2.1 the holder exits before it releases the lease, so a standby waits out the lease (18 to 19 s measured). In 0.3.0 the holder releases it first, and a standby took it in 3 to 4 s on a two-replica install

A replica that loses the lease exits and Kubernetes restarts it as a standby. A loop caught mid-decision cannot be unwound, so a restart is the one handover with no overlap.

The doctor's controllers row also reads the Lease itself. A lease nobody has renewed for more than 45 s (three lease durations) turns the row red, even on a standby that believes it knows the holder. That catches a dead holder, and a grant that allows get but not update.

Two replicas, one lease

Who runs the controller loops when the holder goes away

The holder dies without releasing. Nobody renews, so B takes the Lease once it expires: at most the 15 s lease duration. No loop runs in between; every replica keeps serving the API.
holds the Lease, runs the loopsstandby (serves the API)stands down and exits

Or let the chart provide them

Both are off by default, because the default release installs no service pods.

ValueWhat it installs
ha.postgres.provide=trueCloudNativePG's operator in namespace opod-cnpg, and a Postgres Cluster of ha.postgres.instances (default 3) in the release namespace. Its <fullname>-pg-app Secret (opodcp-pg-app for release opodcp) becomes the state store. A post-install hook creates the Cluster once the operator's webhook answers.
ha.nats.provide=truea three-node NATS JetStream cluster in namespace opod-nats, which becomes OPODCP_EVENTS_URL. A URL saved on the Connectors page wins.
helm install opodcp oci://ghcr.io/opod-io/charts/opodcp -n opodcp --create-namespace \
  --set replicas=3 --set ha.postgres.provide=true --set ha.nats.provide=true

Each comes with a PodDisruptionBudget. ha.postgres.storage (default 10Gi) and ha.postgres.storageClass (default: the cluster's default class) size each instance. Images are pinned by digest under ha and the cloudnative-pg and nats subchart values.

A provided Postgres is a convenient start, not a managed database: you own its backups. opodcp backup works the same against it.

The on-prem profile

The chart carries values-onprem.yaml from 0.3.0: three replicas over a Postgres and a NATS the chart provides, with cloud.provider: onprem. It needs three schedulable nodes.

  1. Check the nodes

    opodcp preflight --kubeconfig ~/.kube/config --replicas 3

    Row ha.nodes passes with three Ready, schedulable nodes.

  2. Install with the profile

    helm pull oci://ghcr.io/opod-io/charts/opodcp --untar
    helm install opodcp ./opod -n opodcp --create-namespace -f ./opod/values-onprem.yaml
  3. Check

    Run Check it worked. You can also run kubectl -n opodcp get cluster opodcp-pg to see the provided Postgres Cluster.

To use your own database, add --set ha.postgres.provide=false --set ports.state.dsnSecret.name=opod-state-dsn. To use your own bus, add --set ha.nats.provide=false and save OPODCP_EVENTS_URL on Connectors.

On bare metal nothing hands out a load-balancer address unless you run kube-vip or MetalLB, and the chart installs neither. A NodePort address belongs to one node, so it goes when that node goes. Put the console behind your Ingress or Gateway, or behind a virtual IP of your own. A cluster that opodcp infra builds with three servers has one already (0.3.0, not yet proven on hardware): the Kubernetes API's VIP, where a NodePort also answers. See Bare metal → Three servers.

Upgrades with several replicas

Pods roll one at a time under the PodDisruptionBudget. The first new pod runs any schema step under a Postgres advisory lock; a second new pod waits and then finds nothing left to run. Replicas still on the old binary keep serving the API from the same database until they are replaced. Every schema step only adds; a drill that runs a step while an old replica still serves has not been run yet.

An image older than the HA profile does not know the postgresql:// scheme that CloudNativePG writes and refuses to start under a provided Postgres. Roll forward again to clear it.

A single replica without leader election

Leader election is on by default (OPODCP_LEADER_ELECTION unset means on). At start the replica reads the Lease once. On a cluster that will not grant it, the replica serves the API and runs no loops. The doctor's controllers row reads blocked with the reason, and the replica tries the check again every 30 s. It never runs the loops without the lease, because a second replica would then decide everything twice.

The fix is one of two:

  • Grant coordination.k8s.io/leases get, create and update in the namespace. The chart's Role does.
  • For a single replica only, set OPODCP_LEADER_ELECTION=0 through extraEnv:
extraEnv:
  - { name: OPODCP_LEADER_ELECTION, value: "0" }

A control plane that runs outside any cluster (for example opodcp serve on a laptop against a kubeconfig) also elects, against the Lease in that cluster.

Fleet mode

A fleet control plane has no leader election and runs exactly one replica. See Several cells.

Last updated · Source: content/docs/control-plane-install/high-availability.mdx · View as Markdown