Skip to content

Upgrades and scaling

You installed with Upgrade with
lowtide sets it up Upgrade on the cluster page. The provisioner applies the module again with the new version. It needs its access, so grant it again first if you removed it. You can also upgrade with Terraform from the module and the state in your bucket.
Terraform Change the module’s ref to the new version and run terraform apply.
Helm helm upgrade with the new chart and image tag.

The console shows when a new version is available. During an upgrade the gateways roll one zone at a time, one pod at a time, and keep serving. The agent keeps its registration.

With Helm, pass --timeout 20m (or more for many pods per zone): Helm waits until the last zone has rolled.

  1. The pod first waits preStopSleepSeconds (10 seconds). It leaves the Service while still serving, so reconnecting clients go elsewhere.
  2. On SIGTERM it reports not ready, refuses new consumers, records the acknowledgement position of every shard it serves, ends its streaming pulls with UNAVAILABLE and releases its leases. Clients reconnect, and other pods take over each shard from the recorded position. Unacknowledged messages are delivered again.
  3. Open requests drain. Streaming pulls proxied through this pod to another one may hold the drain until terminationGracePeriodSeconds (60 seconds). That is safe for data but makes the shutdown slow. Raise the grace period if pods serve many subscriptions.
  4. The WAL writer stops. Files not yet uploaded stay on the disk, and the new pod recovers and uploads them. Messages in that last window reach other pods’ subscribers only after the restart: delayed, not lost.

The chart creates one StatefulSet per zone and rolls them one after another:

  1. Helm applies the new version. Only the first zone’s pods restart. The other zone’s StatefulSet gets the new spec but is held (its update partition equals its pod count).
  2. A hook Job, <release>-rollout, waits until every pod of the first zone runs the new version and has been ready for minReadySeconds (10 seconds).
  3. It releases the next zone and waits for it the same way. helm upgrade and terraform apply end when it is done.

While a zone’s pods restart, its clients reconnect to the other zone, and the other zone serves that zone’s subscriptions until the pods are back (Cross-zone delivery). On GKE with one pod per zone and traffic in both zones, an upgrade lost no message, consumers waited at most about 3 seconds between messages, and the slowest message arrived 11 seconds after it was published. With both zones restarting at once, consumers waited up to 13 seconds and messages up to 60 seconds, because clients had no pod to reconnect to and backed off.

If the first zone doesn’t get ready, for example because the new image fails, the other zone stays on the previous version and keeps serving. Fix the cause and upgrade again, or roll back.

helm rollback rolls zones the same way. rollout.zoneByZone.enabled: false rolls all zones at once.

The hook Job runs kubectl (rollout.zoneByZone.image) with a Role that can only read and patch this release’s StatefulSets. With the Terraform module it uses the kubectl_image variable. If the hook fails, its pod stays for kubectl logs job/<release>-rollout, and the next upgrade replaces it.

To check a new version in one zone before the other zone gets it, hold the other zone with rollout.pausedZones:

Terminal window
helm upgrade lowtide CHART -n lowtide -f values.yaml --timeout 20m \
--set 'rollout.pausedZones={us-central1-b}' # only us-central1-a rolls
# check: pods ready, "recovered WAL file" then uploads, a publish and consume test
helm upgrade lowtide CHART -n lowtide -f values.yaml --timeout 20m # now us-central1-b rolls

A paused zone’s StatefulSet gets the new spec, but no pod restarts until you remove the pause. Remove it in an upgrade of its own: removing it together with a new version rolls both zones at once. With the Terraform module, set rollout = { pausedZones = ["us-central1-b"] } through helm_values for the first apply, then remove it.

  • Don’t upgrade during a database outage. New pods can’t start without the database.
  • Never change the release name, fullnameOverride, a zone, or the module’s cluster_name, zones or namespace on a running cluster. Pod names are stream names. New names mean new streams, and data on the old disks that was not uploaded yet is stranded.
  • Volume settings (persistence.*) need the StatefulSets deleted with --cascade=orphan first (WAL disk full).
  • Database schema. Each pod adds tables and columns it needs at startup, so the first upgraded pod updates the schema and older pods keep running. Read the release notes before you roll back to an older version.
  • Rolling back past zone-aware delivery. Versions before it can’t tell which messages newer pods serve. For about a second after each older pod starts, some messages can be delivered twice, and messages with an ordering key out of order. Nothing is lost. Roll back when traffic is low (Cross-zone delivery).

Raise the pod count: gateways_per_zone in the module, or replicasPerZone (or zoneReplicas.<zone>) in the chart. Each new pod registers a new writer stream and takes a share of the subscription shards and ordering lanes.

Don’t use a HorizontalPodAutoscaler. Pods are not interchangeable, and scaling down automatically runs into the problem below.

Scaling down is not drain-aware. The removed pod’s last WAL window, which can hold acknowledged messages not yet in Cloud Storage, stays on its disk. The disk is kept, and those messages become visible again only when that pod comes back. Its stream also stays registered, so peers in its zone keep trying to read from it and fall back to Cloud Storage.

Before you scale down, make sure the pods you remove have received no publishes for a few seconds and have uploaded everything: their WAL directory should hold a single empty file.

Terminal window
kubectl -n lowtide exec lowtide-us-central1-a-2 -- ls -l /var/lib/lowtide/wal

Ordering keys owned by removed pods move to other pods. Messages for a moved key published just before and just after the move can arrive out of order.