15 KiB
Moving an all-local swarm onto k8s: swarmctl migrate
A running all-local swarm (services.hyperhive.deploy.singleHostSwarm) moves
onto the k3s cluster on the same host one service at a time. The operator sets
deploy.<svc>.runtime = "k8s" and rebuilds; swarmctl migrate status reports
where each service stands. Nothing copies a service's state: each one's pod
re-derives what it keeps, keeps it in the service's own store, or uses the host
unit's directory in place.
Scope and guarantees
The swarm's own daemons and the queue move into the cluster:
swarm-notify-router, swarm-review-classifier, swarm-claude-login,
swarm-stt, swarm-ci-metrics, NATS with swarm-nats-auth, and
swarm-controller. bao, the forge, authelia, the gateway, swarm-builder,
swarm-matrix-ctl and every hive keep running on the host.
- The hive contract stays the same. Hives and agents keep the NATS URL, its port, its certificate name and its auth callout. No hive needs a rebuild for any move.
- One nix option decides where a service runs.
deploy.<svc>.runtimeis"host"(the default) or"k8s". The cut-over is an operator rebuild, never a runtime toggle thatswarmctlflips on its own. - A move leaves the host's data alone. The host unit's directories stay
where they're, so going back is
runtime = "host"and a rebuild.
Names
| name | what it names |
|---|---|
services.hyperhive.deploy.k8s.enable |
brings up single-node k3s on the swarm host |
services.hyperhive.deploy.<svc>.runtime |
"host" or "k8s", per service |
/etc/hyperhive/migrate.json |
the module's render of each service's runtime and host units |
SWARMCTL_KUBECTL, SWARMCTL_KUBECONFIG |
the swarmctl wrapper's kubectl and the k3s admin kubeconfig |
swarmctl migrate status |
the one verb: a read-only report |
swarmctl migrate status
It reads /etc/hyperhive/migrate.json, asks systemd whether each service's
host units run, and lists the pods of the swarm's namespace with one
kubectl get. It creates and changes nothing. For each service it reports:
- runtime: whether the host units have stopped when the configuration says
k8s, and whether the cluster still holds a pod of a service the configuration puts on the host; - order: whether the service moved before one that comes earlier in the order of moves;
- ready: whether the newest pod's readiness probe passes (a
CronJob's pod finishes when its Job completed).
It names the next step that isn't done, exits 0 when every check ran, and
exits 1 when a check failed to run. --json prints the services as the module
renders them, every step with its status, and the next step.
Services
"Ready" means the pod's readiness probe passes. The probes read the /readyz
endpoints the services page lists; the
readiness page has their mechanics.
| service | state | what the pod starts with | readiness signal | cut-over and rollback |
|---|---|---|---|---|
swarm-notify-router |
in the queue: a state bucket and a durable consumer on the forge events stream | the queue's | /readyz: queue connected |
runtime = "k8s", rebuild; back with runtime = "host" |
swarm-review-classifier |
none on disk; its runs and settings live in buckets the controller owns | the queue's | /readyz: queue connected |
same |
swarm-claude-login |
none; credentials it writes go to the store | nothing; a login in progress ends | /readyz: queue connected |
same |
swarm-stt |
the transcript cache, entries live 24 h; the pod keeps it in an emptyDir |
an empty cache | /readyz: queue connected |
same |
swarm-ci-metrics |
cursor.json in the state directory; losing it re-pushes every run |
an empty claim: the first pass re-pushes every run as the same points | the CronJob's next Job completes | runtime = "k8s", rebuild; the timer goes, the CronJob runs; back with runtime = "host" |
NATS + swarm-nats-auth |
JetStream's store_dir: the swarm's desired state, operator profiles, schedules and run records. swarm-nats-auth keeps nothing |
the host unit's own store_dir, in place |
nats-server's /healthz?js-enabled-only=true and swarm-nats-auth's /readyz; Ready when both pass |
runtime = "k8s", rebuild; the pod takes the same host port, so hives keep their URL. Rollback is runtime = "host" and a rebuild: the same files |
swarm-controller |
its state directory holds the legacy webhook-secret (the store has it too), the forge avatar markers and, once, a legacy operator-admin file; the grant record is in the queue's key-value store |
an emptyDir |
/readyz on the controller's plain health listener |
runtime = "k8s", rebuild; the same rebuild points the gateway's /api/ and /webhook/forge/ upstreams at the controller's TCP listener. Back with runtime = "host" and a rebuild |
Two facts the table rests on:
- The queue's store is state that must survive. Losing it empties the hive-status view, and it also loses the buckets that hold desired state. It never leaves its directory on the host: the pod and the container use the same files, so a switch in either direction copies nothing, and the streams, consumers and acknowledgements are the ones the other side left. See the queue's store.
- The controller keeps no state of its own that a move could lose. The record of the Matrix admin grants is in the queue's key-value store, the webhook secret is in the secret store, and the controller sets the avatar markers again at start. The first start of the controller on the host after an upgrade imports a legacy grant file into the store, so run the host controller once before the switch.
The queue's store
The queue's pod uses the directory its container's nats unit already uses:
/var/lib/nixos-containers/swarm-nats/var/lib/nats on the host, /var/lib/nats
in both. The module renders a static local PersistentVolume on that path,
pinned to the node, with a storage class of its own and the Retain policy.
The claim swarm-nats-store binds it by name, so nothing else binds either.
- One server at a time. The prune unit stops a pod before the container starts, and the Deployment replaces its pod rather than running two. Nothing reads the directory while the other side writes.
- Pod to host. nats-server creates its files with mode
0600, owned by the uid it runs as. The pod runs as uid 65532, so the container'snatsunit runschown -R nats:natson the directory before the server starts, as root and at every start. - Host to pod. The pod's
fsGroupmakes the kubelet set the directory's group to the pod's and add group read and write on every file at each pod start, so the pod's uid can use files the host'snatsuser wrote. - No lock or identity file. nats-server keeps none in the store, so nothing there ties the directory to the side that wrote it.
- A host that never ran the container. The module makes the directory, because the volume needs it before the pod starts.
- An older claim. A
swarm-nats-stateclaim from an earlier shape isn't the queue's any more: the pod mountsswarm-nats-store, so the old claim stays unused and needs no step.
Order of moves
swarmctl migrate status reports the services in this order, and flags a
service that moved ahead of an earlier one:
swarm-notify-routeralone. The first cut-over proves the runtime switch, the image, the store identity and reaching the host-run NATS by name.swarm-review-classifier,swarm-claude-login,swarm-stt,swarm-ci-metrics, in one rebuild or one at a time, the same pattern as step 1.- NATS with
swarm-nats-auth. The riskiest move: every hive and agent disconnects, and the data is the swarm's desired state. Nothing copies it.swarm-nats-authmoves in the same pod, because it answers the auth callout on every connect and dials the server by name, which the pod's host aliases map to its loopback. swarm-controllerlast.- It's the operator's view of the swarm. Kept on the host through step 3,
it reports from an unchanged place whether the hives reconnected after
the NATS move, and
swarmctlkeeps its local socket for the checks. - Its cut-over also changes the gateway's upstream and ends the local
socket for
swarmctl, the widest change to the operator's tools.
- It's the operator's view of the swarm. Kept on the host through step 3,
it reports from an unchanged place whether the hives reconnected after
the NATS move, and
Each step needs the previous one Ready. swarmctl migrate status says which
service comes next.
Downtime and what hives see
The budget is the time from the cut-over rebuild stopping the host unit to the pod being Ready.
| service | budget | what hives, agents and the operator see |
|---|---|---|
swarm-notify-router |
2 min | Forge events wait in the stream behind the durable consumer and arrive late |
swarm-review-classifier |
2 min | A try-out request in the gap gets no answer, and its caller reports a failure |
swarm-claude-login |
2 min | A login in progress fails; the operator starts it again |
swarm-stt |
2 min | Transcription requests fail during the gap; the cache starts empty |
swarm-ci-metrics |
one 5-minute period | One pass runs late; the first pass on the pod's empty cursor pushes every run again |
NATS + swarm-nats-auth |
10 min | below |
swarm-controller |
5 min | The swarm UI and API answer with gateway errors. Forge webhook deliveries in the gap fail at the forge. After the cut-over, swarmctl on the host needs --swarm |
During the NATS gap:
- Every hive, agent and swarm daemon loses its connection. The queue client retries at once, then backs off from 500 ms up to one minute. Clients therefore return within a minute of the pod passing readiness.
- The desired-state buckets aren't readable. Hives apply no change, and running agents keep running as they are.
- Operator input to agents and agent status in the UI stall, and the UI shows status as stale.
- Core NATS messages published in the gap get lost. JetStream publishes fail at the publisher.