Kubernetes: wardn-scale
Run the api, worker, controller and gateway as separate Deployments, each with its own replicas, autoscaling and budget.
wardn-scale is wardn-standard with the roles pulled apart. Each of the four roles of the server (api, worker, controller and gateway) is a Deployment of its own, so you size and scale each one for the load it carries: more api pods for a busy web app and CLI, more workers for a deep queue, more gateways for hundreds of connected clusters. The pods coordinate through the database exactly as in wardn-standard, so there is still no queue, cache or broker to run beside it. Read Self-hosting first for what each part does.
Choose it over wardn-standard
Stay on wardn-standard until one of these is true:
- One role is the bottleneck. In
wardn-standard, every replica runs every role, so a deep queue of renders can only be met by adding whole replicas, with their api and gateway too. - You want autoscaling. The api and the workers scale on CPU. A pod that runs every role does not scale well on it: its gateway streams and its controller standby make its CPU a poor measure of anything.
- Roles need different resources or nodes. Workers render manifests and need memory the api does not; gateways hold long-lived streams and want stable nodes.
- A restart of one role must not touch another. Rolling the workers leaves every api and gateway pod where it is.
wardn-scale uses the same images, the same settings and the same Postgres as the other charts, and the shared templates keep the shape of every pod the same. The cost is more objects to watch: four Deployments and, with autoscaling, up to three HorizontalPodAutoscalers.
wardn-standard | wardn-scale | |
|---|---|---|
| Server Deployments | 1, every role | 4: api, worker, controller, gateway |
| Replicas, by default | 3 | api 3, worker 2, controller 2, gateway 2 |
| Autoscaling | none | api, worker and gateway, off by default |
| PodDisruptionBudget | one | one per role |
| Database connections, at most | 60 for the server (3 pods) | 180 for the server (9 pods; see Database connections) |
| Web replicas | 2 | 2 |
| Postgres | external | external |
What each role does
| Role | What it does | Replicas | Autoscaling | PodDisruptionBudget | Stops by |
|---|---|---|---|---|---|
api | REST, event streams, MCP and webhooks. The only role the wardn-server Service reaches. | 3 | CPU, optionally memory. Off. | One pod at a time | Keeps serving 5 seconds after the signal, then stops accepting and lets requests finish (10 seconds). |
worker | Takes jobs from the queue in Postgres: renders, promotions, notifications, integrations, agent jobs. | 2 | CPU. Off. Scales down slowly. | One pod at a time | Stops claiming, gives running jobs 30 seconds to finish, then lets go of the rest. |
controller | Runs the periodic tasks. One replica leads through a lease in the database. | 2 | Not available. | One pod at a time | Gives up the lease; a standby takes over within a few seconds. |
gateway | Holds the operators' streams and each cluster's lease. The only role the gateway Service reaches. | 2 | Off, and best left off. | One pod at a time | Tells operators to reconnect elsewhere, drains its listener for 10 seconds, drops its registration. |
The gateway pods run the gateway role alone (gateway.roles: "gateway"), so they scale and roll apart from the api. A terminal or log stream that reaches an api pod is passed to the gateway pod that holds the cluster's operator. That pod answers on its HTTP port (8080) the four requests that are passed to it, a terminal's stream, a pod's logs and YAML, and a pod restart, checks the caller again, and refuses every other request, so the wardn-server Service never needs to reach it. To run the whole api in the gateway pods, set gateway.roles: "gateway,api".
Why the controller has no autoscaler. The controller runs the work that must happen once, such as partitions, freeze windows, expiries and the sync of tracked branches. One replica leads; the rest wait and try to lead every few seconds. Three replicas do the same work as two and only add standbys, so controller.autoscaling is refused at render time. Two is enough for a standby.
Why the gateway should not autoscale. A stream lasts as long as the operator stays connected. A scale-out moves none of the operators already connected, so the new pod sits idle until something else makes operators reconnect; a scale-in cuts every stream on the pod it removes, and those operators reconnect together. Size the gateway by the number of clusters you connect and change gateway.replicas by hand. If you turn autoscaling on anyway, the chart scales it down by one pod every five minutes.
Before you start
You need the same three things as wardn-standard: a Postgres 14 or newer, the keys, and a name for the gateway. wardn-standard describes each, and the commands there work unchanged. The install below assumes the Secrets wardn-db and wardn-keys.
The job-token key is a third key, job-token-key in the same Secret, for the signatures on agent job tokens. If you set secrets.generate=true the chart makes all of them.
Install
publicUrl: https://wardn.example.com
ingress:
enabled: true
className: nginx
host: wardn.example.com
tlsSecret: wardn-web-tls
secrets:
betterAuth: {name: wardn-keys}
masterKey: {name: wardn-keys}
jobTokenKey: {name: wardn-keys}
postgres:
external:
host: db.example.com
passwordSecretRef: {name: wardn-db}
gateway:
hosts: [gateway.example.com]
advertise: gateway.example.com:8443
api:
replicas: 4
worker:
autoscaling: {enabled: true, minReplicas: 2, maxReplicas: 10}helm install wardn oci://ghcr.io/future-pirate-king/charts/wardn-scale \
--namespace wardn --values values.yaml --wait --timeout 10mThen point the gateway name at the gateway Service and connect a cluster as in wardn-standard. The Service is wardn-wardn-scale-gateway, and you can check readiness on any api pod:
kubectl -n wardn get deployments
kubectl -n wardn exec deploy/wardn-wardn-scale-api -- wget -qO- http://localhost:8080/api/v1/readyThe api pods are ready when /api/v1/ready answers. The other roles are ready when /readyz on their ops listener answers. Each pod is asked only for what its own role needs: the database for all of them, the listener operators dial for a gateway, and a first answer from the queue for a worker. The first pod to start runs the migrations and the others wait for them.
Scale a role
Scale one role without the others:
kubectl -n wardn scale deployment/wardn-wardn-scale-worker --replicas=4Only that role's pods change. To keep it in the values file, set worker.replicas and run helm upgrade. With autoscaling on, the Deployment leaves replicas out, so an upgrade does not fight the autoscaler and worker.replicas is not used. Set minReplicas to the count you want when idle.
api:
autoscaling:
enabled: true
minReplicas: 3
maxReplicas: 12
cpu: 70 # percent of the CPU request
memory: null # leave unset to scale on CPU alone
worker:
autoscaling:
enabled: true
maxReplicas: 10
behavior:
scaleDown:
stabilizationWindowSeconds: 300An autoscaler measures against the container's requests, so a role with autoscaling needs resources.requests.cpu. It also needs a metrics source, such as metrics-server, in the cluster.
Scale workers on queue depth
CPU is a poor signal for a worker whose jobs mostly wait on the network or the database: the queue can be long while every worker is idle. Every Wardn process exposes the queue it reads from the database: wardn_work_queue_depth{state="ready"} (jobs due now) and wardn_work_queue_oldest_ready_seconds (how long the longest-waiting due job has waited); see Monitoring. The worker's autoscaler can scale on either one. It is off by default, because it needs an adapter in your cluster that serves those series as Kubernetes external metrics. The chart does not install one.
Serve the metrics
With the Prometheus Adapter, scraping Wardn's /metrics as in Monitoring, add two external rules to its values. Every pod reports the same queue, so the rule takes the max and the number does not grow with the pod count:
rules:
external:
- seriesQuery: 'wardn_work_queue_depth{namespace="wardn"}'
resources: {namespaced: false}
metricsQuery: 'max(<<.Series>>{<<.LabelMatchers>>,namespace="wardn"})'
- seriesQuery: 'wardn_work_queue_oldest_ready_seconds{namespace="wardn"}'
resources: {namespaced: false}
metricsQuery: 'max(<<.Series>>{<<.LabelMatchers>>,namespace="wardn"})'Use the namespace Wardn runs in, and check the result with kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/wardn/wardn_work_queue_depth?labelSelector=state%3Dready".
Turn it on
worker:
autoscaling:
enabled: true
minReplicas: 2
maxReplicas: 12
queue:
enabled: true
readyPerWorker: 20 # add workers while more than 20 due jobs wait per worker
oldestReadySeconds: 120 # and in proportion while the longest wait is over 2 minutesThe autoscaler follows whichever of CPU, readyPerWorker and oldestReadySeconds asks for the most workers, and the slow scale-down in worker.autoscaling.behavior keeps a burst's workers until the queue is quiet. Leave either queue value empty to leave that metric out, and set cpu: null to scale on the queue alone. If the adapter does not serve a metric, the autoscaler cannot compute it and holds the replica count: it never scales on a number it cannot read, so a broken adapter shows as a FailedGetExternalMetric event on the HorizontalPodAutoscaler. queue is for the worker only; worker.autoscaling.queue.enabled without worker.autoscaling.enabled fails the render.
Database connections
Every pod opens up to 20 connections by default (postgres.maxConns), and every role opens its own pool. The server's share of the database is about 20 × (api + worker + controller + gateway pods), plus the web app's. With the default counts and a role at its maximum from autoscaling, that is several hundred connections, so check max_connections before raising a maximum, lower postgres.maxConns, or put a pooler in front (Postgres). Autoscaling is bounded by the database, not by the cluster.
Roll out a change
Rollouts replace one pod at a time and wait for the new pod to be ready before stopping an old one (maxUnavailable: 0, maxSurge: 1), so a role never runs below its replica count. Each role gives its pods time to leave cleanly:
| Role | Grace period | What happens in it |
|---|---|---|
api | 45 s | 5 s after the signal the pod is already out of the Service, then it stops accepting and finishes what it has. |
worker | 60 s | 30 s for running jobs; a job still running after that is released and another worker runs it again, so every job is written to be safe to run twice. |
controller | 30 s | The lease is released at once. |
gateway | 30 s | The operators are told to reconnect elsewhere, and reconnect through the gateway Service. A cluster whose pod was killed instead moves within WARDN_GATEWAY_LEASE_TTL (15 seconds). |
The pod waits preStopSleepSeconds (5, for the api) before it stops accepting, because nodes learn that a pod left the Service a moment after it begins to stop. The sleep needs Kubernetes 1.30 or newer. Without it, a request can reach a pod that has already stopped listening.
Restart a role without a new release the same way a release would:
kubectl -n wardn rollout restart deployment/wardn-wardn-scale-gateway
kubectl -n wardn rollout status deployment/wardn-wardn-scale-gatewayUpgrade the whole install as in Upgrading. While a role rolls, old and new pods run side by side on one schema: the first new pod to start migrates it, so a release's migrations must work for the old pods too, as they do for wardn-standard.
The test that checks this is task deploy:scale: it installs the chart on a kind cluster, scales each role up and down, and rolls each role under a steady stream of API requests while a push is rendered and applied, and fails if one request, one job or one apply is lost.
Move from wardn-standard
The database and the keys are shared between the charts, so moving is an uninstall and an install on the same Postgres. Expect a few minutes without an API; operators keep what they applied and reconnect by themselves.
Back up
Take a database backup and a copy of the keys (Backup and restore).
Carry the values over
Translate the values file:
wardn-standard | wardn-scale |
|---|---|
server.replicas | api.replicas, and worker, controller and gateway as you want them |
server.resources | api.resources and the other roles' |
server.extraEnv | extraEnv for every role, or a role's own extraEnv |
server.podAnnotations | each role's podAnnotations |
podDisruptionBudget | each role's podDisruptionBudget |
server.roles | gone: the roles are fixed per Deployment |
Everything else, such as publicUrl, ingress, postgres, gateway.hosts, gateway.tls and web, keeps its name and meaning. If the keys were made by the chart (secrets.generate=true), name the Secret it made, wardn-wardn-standard-secrets, in secrets.betterAuth.name, secrets.masterKey.name and secrets.jobTokenKey.name, or the new install makes new keys and cannot open your secrets.
Swap the charts
helm uninstall wardn -n wardn
helm install wardn oci://ghcr.io/future-pirate-king/charts/wardn-scale \
-n wardn --values values.yaml --wait --timeout 10mThe Services are named after the chart (wardn-wardn-standard-gateway becomes wardn-wardn-scale-gateway), so the gateway's load balancer is a new one: point the gateway's DNS name at its new address. To move back, do the same in the other direction.
Values
wardn-scale has every value of wardn-standard except server.* and podDisruptionBudget.*, which are per role. The same keys appear under each of api, worker, controller and gateway:
| Value | Default (api / worker / controller / gateway) | What it does |
|---|---|---|
<role>.replicas | 3 / 2 / 2 / 2 | Pods. Not used when the role's autoscaling is on. |
<role>.resources | api: 250m CPU and 512Mi requested, 1Gi limit. worker: 500m and 1Gi, 4Gi limit. controller: 100m and 256Mi, 1Gi limit. gateway: 250m and 512Mi, 1Gi limit. | Starting points, not measurements: watch each role's CPU and memory (/metrics on its ops port) for a week and set them from that. |
<role>.podAnnotations | {} | Annotations on the role's pods. |
<role>.seccompProfile | {type: RuntimeDefault} | The role's seccomp profile. Renders of chart sources run in the worker, so worker.seccompProfile is the one that matters: when /api/v1/ready lists render_sandbox as not ok (Monitoring), set it to {type: Unconfined}, or to {type: Localhost, localhostProfile: <file>} with a profile that allows unshare(CLONE_NEWUSER). |
<role>.extraEnv | [] | More environment entries, after the top-level extraEnv. |
<role>.terminationGracePeriodSeconds | 45 / 60 / 30 / 30 | How long a pod has to leave. See Roll out a change. |
<role>.podDisruptionBudget | {enabled: true, maxUnavailable: 1} | The role's budget. |
<role>.autoscaling.enabled | false | Create a HorizontalPodAutoscaler (autoscaling/v2) for the api, worker or gateway. Setting controller.autoscaling fails the render. |
<role>.autoscaling.minReplicas, maxReplicas | api 3 and 12, worker 2 and 10, gateway 2 and 6 | Bounds. |
<role>.autoscaling.cpu | 70 | Target average CPU, as a percent of the request. |
<role>.autoscaling.memory | null | Target average memory, as a percent of the request. Unset leaves memory out. |
<role>.autoscaling.behavior | worker and gateway slow the scale-down | Passed through to the autoscaler's behavior. |
worker.autoscaling.queue | {enabled: false, readyPerWorker: 20, oldestReadySeconds: null} | Also scale the worker on the queue. Needs an adapter serving the queue metrics; see Scale workers on queue depth. |
api.preStopSleepSeconds | 5 | Seconds a stopping api pod keeps serving. |
api.serviceName | wardn-server | The name of the api Service. Leave it: the web image forwards /api/v1 to this name. |
gateway.roles | gateway | The roles the gateway pods run. See above. |
extraEnv | [] | Environment for every role. |
Each role also has a Service named <release>-<chart>-<role>-ops on port 9090 for metrics (the api's is the wardn-server Service, port ops). Scrape /metrics on each pod, as in Monitoring.
Read replica
wardn-scale supports a read replica. Set postgres.readReplica to a hot standby of your external Postgres and the lists are read from it; a person's own writes stay on the primary until the standby has replayed them, and a standby more than maxLag behind (5 seconds by default) serves nothing until it catches up. It is off by default, and enabling it does not fail the install.
postgres:
readReplica:
enabled: true
host: db-replica.example.com
maxLag: 5sThe standby uses the primary's user, password and database, or give postgres.readReplica.urlSecretRef a whole URL. With a primary given as postgres.external.urlSecretRef, the replica's urlSecretRef is required, and the bundled Postgres has no replica; the render fails with a message in those two cases, and when host is missing. Each pod opens up to postgres.readReplica.maxConns connections to the standby (10 by default) beside its pool on the primary, so count them when you size it. The values are in Helm chart values, and Postgres says how to set up the standby.