docs: the start gate describes what the pod runs
This commit is contained in:
parent
360454958a
commit
65f7a55967
2 changed files with 66 additions and 36 deletions
|
|
@ -33,7 +33,7 @@ The command moves the swarm's own daemons and the queue into the cluster:
|
||||||
| `services.hyperhive.deploy.<svc>.runtime` | `"host"` or `"k8s"`, per service |
|
| `services.hyperhive.deploy.<svc>.runtime` | `"host"` or `"k8s"`, per service |
|
||||||
| `/etc/hyperhive/migrate.json` | the module's render of each service's runtime, state paths, PVC |
|
| `/etc/hyperhive/migrate.json` | the module's render of each service's runtime, state paths, PVC |
|
||||||
| `/var/lib/hyperhive-migrate/` | host record: pre-move snapshots and copy digests, root `0700` |
|
| `/var/lib/hyperhive-migrate/` | host record: pre-move snapshots and copy digests, root `0700` |
|
||||||
| `.hyperhive-migrated` in a PVC | the copy marker the pod's start gate waits for |
|
| `.hyperhive-migrated` in a PVC | the copy marker the pod's start gate checks for |
|
||||||
| `swarmctl migrate` `status` / `rollback` / `finish` | the verbs |
|
| `swarmctl migrate` `status` / `rollback` / `finish` | the verbs |
|
||||||
|
|
||||||
## The move of one stateful service
|
## The move of one stateful service
|
||||||
|
|
@ -50,8 +50,12 @@ A service with state moves in four steps. A service without state skips steps
|
||||||
2. **Cut-over rebuild** (the operator). The operator sets
|
2. **Cut-over rebuild** (the operator). The operator sets
|
||||||
`deploy.<svc>.runtime = "k8s"` and rebuilds. The rebuild stops the host
|
`deploy.<svc>.runtime = "k8s"` and rebuilds. The rebuild stops the host
|
||||||
unit and renders it no more, and applies the workload and its PVC. The
|
unit and renders it no more, and applies the workload and its PVC. The
|
||||||
pod starts in a **start gate**: an init container that waits until the
|
pod's first init container is the **start gate**. It exits 0 only when the
|
||||||
PVC holds `.hyperhive-migrated`. A pod therefore never starts on an empty
|
PVC holds `.hyperhive-migrated`, or when the PVC is empty and the
|
||||||
|
service's `deploy.<svc>.k8s.freshState` is on. Any other volume fails the
|
||||||
|
gate: the pod stays in `Init:Error` with one line saying to run
|
||||||
|
`swarmctl migrate <svc>` or set the option, and the kubelet runs the gate
|
||||||
|
again with a growing delay. A pod therefore never starts on an empty
|
||||||
volume, whatever re-applies the manifest.
|
volume, whatever re-applies the manifest.
|
||||||
3. **Copy** (`swarmctl migrate`). Refuses while the host unit runs. Streams
|
3. **Copy** (`swarmctl migrate`). Refuses while the host unit runs. Streams
|
||||||
the host state directory as a tar archive into a copy pod that mounts the
|
the host state directory as a tar archive into a copy pod that mounts the
|
||||||
|
|
@ -62,9 +66,10 @@ A service with state moves in four steps. A service without state skips steps
|
||||||
4. **Verify** (`swarmctl migrate`). Waits for the pod's readiness, then
|
4. **Verify** (`swarmctl migrate`). Waits for the pod's readiness, then
|
||||||
compares what the service serves against the snapshot from step 1.
|
compares what the service serves against the snapshot from step 1.
|
||||||
|
|
||||||
The copy pod and the start gate run a small `swarmctl` image with the hidden
|
The copy pod runs a small `swarmctl` image with the hidden subcommand
|
||||||
subcommands `migrate receive` and `migrate gate`. The service images carry no
|
`migrate receive`. The start gate is a script in an image of its own that holds
|
||||||
shell and no `tar`, and this keeps them that way. The copy streams through the
|
coreutils and nothing else. The service images carry no shell and no `tar`, and
|
||||||
|
this keeps them that way. The copy streams through the
|
||||||
k8s API instead of writing into the volume's directory on the host, so it works
|
k8s API instead of writing into the volume's directory on the host, so it works
|
||||||
for every storage class.
|
for every storage class.
|
||||||
|
|
||||||
|
|
@ -79,7 +84,7 @@ endpoints the [services page](../../2-handbook/swarm/services.md) lists; the
|
||||||
| `swarm-notify-router` | in the queue: a state bucket and a durable consumer on the forge events stream | nothing | `/readyz`: queue connected | `runtime = "k8s"`, rebuild; back with `runtime = "host"` |
|
| `swarm-notify-router` | in the queue: a state bucket and a durable consumer on the forge events stream | nothing | `/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 | nothing | `/readyz`: queue connected | same |
|
| `swarm-review-classifier` | none on disk; its runs and settings live in buckets the controller owns | nothing | `/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-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 | nothing; the pod starts with an empty cache | `/readyz`: queue connected | same |
|
| `swarm-stt` | the transcript cache, entries live 24 h | nothing; the pod starts with an empty cache, once the gate has its marker | `/readyz`: queue connected | same |
|
||||||
| `swarm-ci-metrics` | `cursor.json` in the state directory; losing it re-pushes every run | the state directory, to a PVC | the CronJob's next Job completes | `runtime = "k8s"`, rebuild; the timer goes, the CronJob runs. Rollback copies the PVC back |
|
| `swarm-ci-metrics` | `cursor.json` in the state directory; losing it re-pushes every run | the state directory, to a PVC | the CronJob's next Job completes | `runtime = "k8s"`, rebuild; the timer goes, the CronJob runs. Rollback copies the PVC back |
|
||||||
| 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 whole `store_dir`, to a PVC; the cut-over rebuild stops NATS, so the copy reads a quiescent tree | 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 copies the PVC back |
|
| 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 whole `store_dir`, to a PVC; the cut-over rebuild stops NATS, so the copy reads a quiescent tree | 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 copies the PVC back |
|
||||||
| `swarm-controller` | its state directory: the operator-admin set, the legacy `webhook-secret` fallback and the forge avatar markers. The rest sits in the queue or the store | the state directory, to a PVC | `/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. Rollback copies the PVC back and returns the upstreams to the socket |
|
| `swarm-controller` | its state directory: the operator-admin set, the legacy `webhook-secret` fallback and the forge avatar markers. The rest sits in the queue or the store | the state directory, to a PVC | `/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. Rollback copies the PVC back and returns the upstreams to the socket |
|
||||||
|
|
@ -201,8 +206,11 @@ directories and the PVC of any service back on the host. It runs only when
|
||||||
every service passed verification where the config wants it. A rebuild that
|
every service passed verification where the config wants it. A rebuild that
|
||||||
stops a workload leaves its PVC in place, so the data survives until `finish`.
|
stops a workload leaves its PVC in place, so the data survives until `finish`.
|
||||||
|
|
||||||
A fresh install straight onto k8s has no host state to copy: `swarmctl migrate`
|
A fresh install straight onto k8s has no host state to copy: with
|
||||||
writes a marker that names no source, and the gate opens.
|
`deploy.<svc>.k8s.freshState` on, the gate marks the empty volume itself
|
||||||
|
(`{"fresh": true, "at": <time>}`), and `swarmctl migrate` isn't needed. A
|
||||||
|
service with state that moves nothing, `swarm-stt`, still needs the marker:
|
||||||
|
`swarmctl migrate` writes one that names no source.
|
||||||
|
|
||||||
## Downtime and what hives see
|
## Downtime and what hives see
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,12 @@ cluster follow the same pattern.
|
||||||
own section.
|
own section.
|
||||||
- `services.hyperhive.deploy.nats.runtime` (default `"host"`), with the same
|
- `services.hyperhive.deploy.nats.runtime` (default `"host"`), with the same
|
||||||
rule. One switch covers the queue's server and its auth callout. It needs
|
rule. One switch covers the queue's server and its auth callout. It needs
|
||||||
the iptables firewall (`networking.nftables.enable` off), and
|
the iptables firewall (`networking.nftables.enable` off).
|
||||||
`deploy.nats.k8s.freshStore` says whether a fresh store may start the
|
[The queue](#the-queue) has its own section.
|
||||||
server. [The queue](#the-queue) has its own section.
|
- `services.hyperhive.deploy.<service>.k8s.freshState` (default `false`) for
|
||||||
|
each service whose pod keeps state in a volume: `swarm-controller`, `stt`,
|
||||||
|
`ci-metrics` and `nats`. It says whether the pod may start on an empty volume
|
||||||
|
([State](#state)).
|
||||||
|
|
||||||
With `"host"`, a host without [the cluster node](node.md) renders the same
|
With `"host"`, a host without [the cluster node](node.md) renders the same
|
||||||
configuration as before the option existed. With the node on and every service
|
configuration as before the option existed. With the node on and every service
|
||||||
|
|
@ -105,6 +108,22 @@ claims stay; `swarmctl migrate finish` deletes them.
|
||||||
|
|
||||||
## State
|
## State
|
||||||
|
|
||||||
|
A pod with a state volume starts only on migrated state. Its first init
|
||||||
|
container, `state-gate`, mounts the volume and exits 0 when the volume holds
|
||||||
|
`.hyperhive-migrated`. A volume with no entries besides `lost+found` gets the
|
||||||
|
marker (`{"fresh": true, "at": <time>}`) and passes where the service's
|
||||||
|
`k8s.freshState` is on. Every other volume fails the gate, including one that
|
||||||
|
holds files and no marker, since a copy may have stopped half way. The pod stays
|
||||||
|
in `Init:Error`, and the container's termination message and log carry one
|
||||||
|
line that names the service, the `swarmctl migrate` command and the option to
|
||||||
|
set for a fresh install. Nothing of the service runs on the empty volume. The
|
||||||
|
gate doesn't decide which copy runs: the host unit stops before the pod
|
||||||
|
exists. Switching a stateful service to `"k8s"` on a live host therefore needs
|
||||||
|
`swarmctl migrate`, which copies the state and writes the marker, or the
|
||||||
|
fresh flag, which is for a swarm with no state to lose.
|
||||||
|
`swarm-notify-router`, `swarm-review-classifier` and `swarm-claude-login` have
|
||||||
|
no volume and no gate.
|
||||||
|
|
||||||
`swarm-notify-router` keeps nothing on the host. Its durable consumer on the
|
`swarm-notify-router` keeps nothing on the host. Its durable consumer on the
|
||||||
forge events stream and its `notify-router-state` bucket live in the queue, so a
|
forge events stream and its `notify-router-state` bucket live in the queue, so a
|
||||||
switch in either direction copies nothing, and the router continues from the
|
switch in either direction copies nothing, and the router continues from the
|
||||||
|
|
@ -114,19 +133,21 @@ consumer's position.
|
||||||
cache sits in the container's `/var/lib/swarm-stt`. In the cluster it sits in
|
cache sits in the container's `/var/lib/swarm-stt`. In the cluster it sits in
|
||||||
the PersistentVolumeClaim `swarm-stt-state`, mounted at the same path. A switch
|
the PersistentVolumeClaim `swarm-stt-state`, mounted at the same path. A switch
|
||||||
copies neither: each side starts with the cache it last had, empty the first
|
copies neither: each side starts with the cache it last had, empty the first
|
||||||
time, and transcribes a memo that only the other side cached. The claim stays
|
time (the pod's gate wants the marker or `deploy.stt.k8s.freshState` for
|
||||||
|
that), and transcribes a memo that only the other side cached. The claim stays
|
||||||
after a switch back, as every claim does, and the container's directory stays
|
after a switch back, as every claim does, and the container's directory stays
|
||||||
too. The whisper model isn't state: the pod's image holds it, from the same
|
too. The whisper model isn't state: the pod's image holds it, from the same
|
||||||
store path the container reads, and the volume doesn't.
|
store path the container reads, and the volume doesn't.
|
||||||
|
|
||||||
`swarm-ci-metrics` keeps a cursor, `cursor.json`, which holds the run numbers
|
`swarm-ci-metrics` keeps a cursor, `cursor.json`, which holds the run numbers
|
||||||
already pushed. On the host it sits in the service's state directory. In the
|
already pushed. On the host it sits in the service's state directory. In
|
||||||
cluster it sits in the PersistentVolumeClaim `swarm-ci-metrics-state`, mounted
|
the cluster it sits in the PersistentVolumeClaim `swarm-ci-metrics-state`,
|
||||||
at the same path, and the claim binds with the first Job. A switch copies
|
mounted at the same path, and the claim binds with the first Job. A
|
||||||
neither, so each side keeps the cursor it last had, and the first pass on a side
|
switch copies neither, so each side keeps the cursor it last had, and
|
||||||
with none pushes every run again, as the same points. A second Job on the same
|
the first pass on a side with none (the pod's gate wants the marker or
|
||||||
side finds the cursor and pushes nothing. The claim stays after a switch back,
|
`deploy.ci-metrics.k8s.freshState` for that) pushes every run again, as
|
||||||
and so does the host's directory.
|
the same points. A second Job on the same side finds the cursor and pushes
|
||||||
|
nothing. The claim stays after a switch back, and so does the host's directory.
|
||||||
|
|
||||||
## The controller
|
## The controller
|
||||||
|
|
||||||
|
|
@ -197,7 +218,7 @@ holds the container back until the pod has gone.
|
||||||
- **Containers.** The responder is the pod's main container, `swarm-nats`,
|
- **Containers.** The responder is the pod's main container, `swarm-nats`,
|
||||||
rendered from the unit the container runs, as the other daemons are. Beside
|
rendered from the unit the container runs, as the other daemons are. Beside
|
||||||
it run `nats`, the server, `tls-renew` and `exporter`, the Prometheus
|
it run `nats`, the server, `tls-renew` and `exporter`, the Prometheus
|
||||||
exporter. Three init containers run in order before them. `store-guard`
|
exporter. Three init containers run in order before them. `state-gate`
|
||||||
checks the JetStream volume. `tls-issue` issues the server's leaf.
|
checks the JetStream volume. `tls-issue` issues the server's leaf.
|
||||||
`callout-config` creates the callout's keys if the store holds none, fetches
|
`callout-config` creates the callout's keys if the store holds none, fetches
|
||||||
their public halves and writes the server's configuration. The server's
|
their public halves and writes the server's configuration. The server's
|
||||||
|
|
@ -241,10 +262,10 @@ holds the container back until the pod has gone.
|
||||||
- **State.** The server's store directory, `/var/lib/nats`, is the
|
- **State.** The server's store directory, `/var/lib/nats`, is the
|
||||||
PersistentVolumeClaim `swarm-nats-state`. The claim starts empty, and a switch
|
PersistentVolumeClaim `swarm-nats-state`. The claim starts empty, and a switch
|
||||||
copies nothing from the container's store: it holds the swarm's declared
|
copies nothing from the container's store: it holds the swarm's declared
|
||||||
desired state, which nothing regenerates. `store-guard` therefore stops the
|
desired state, which nothing regenerates. `state-gate` therefore stops the
|
||||||
pod, with a message naming `swarmctl migrate`, when the volume holds no
|
pod, with a message naming `swarmctl migrate`, until the volume holds the
|
||||||
JetStream data, unless `deploy.nats.k8s.freshStore` is on. Turn it on for a
|
migration marker, unless `deploy.nats.k8s.freshState` is on. Turn it on for
|
||||||
fresh install only. The claim stays after a switch back, as every claim
|
a fresh install only. The claim stays after a switch back, as every claim
|
||||||
does, and the container's store stays too.
|
does, and the container's store stays too.
|
||||||
- **Readiness.** The pod is Ready when the responder's `/readyz`, on the pod's
|
- **Readiness.** The pod is Ready when the responder's `/readyz`, on the pod's
|
||||||
port 8080, passes and the server's exec probe does. The probe runs
|
port 8080, passes and the server's exec probe does. The probe runs
|
||||||
|
|
@ -345,17 +366,18 @@ minter's real login step does, while `claude` with `HOME` on the root leaves
|
||||||
nothing there.
|
nothing there.
|
||||||
|
|
||||||
The VM test `k8s-nats-switch` moves the queue against the real secret store. A
|
The VM test `k8s-nats-switch` moves the queue against the real secret store. A
|
||||||
sampler counts servers and responders every 200 ms and sees at most one of each,
|
sampler counts servers and responders every 200 ms and sees at most one of
|
||||||
and the container and the pod never together. The pod is Ready by its exec probe
|
each, and the container and the pod never together. The pod is Ready by its
|
||||||
and has the init containers, the `hostPort`s and the volumes the module renders,
|
exec probe and has the init containers, the `hostPort`s and the volumes the
|
||||||
and its leaf's volume is a tmpfs. A client on the bridge reaches the queue by
|
module renders, and its leaf's volume is a tmpfs. A client on the bridge
|
||||||
name, and a second node outside the node reaches the control port and not the
|
reaches the queue by name, and a second node outside the node reaches the
|
||||||
queue's, as with the container; with `openFirewall` it dials the pod by name and
|
control port and not the queue's, as with the container; with `openFirewall`
|
||||||
verifies the name, and the responder in the pod admits it. A stream written
|
it dials the pod by name and verifies the name, and the responder in the pod
|
||||||
before a pod delete survives it: the replacement pod reads it from the same
|
admits it. A stream written before a pod delete survives it: the replacement
|
||||||
volume. The store guard's image refuses an empty volume, passes a fresh one and
|
pod reads it from the same volume. The state gate's image refuses an empty
|
||||||
a volume with data. The exporter answers the host's own processes through the
|
volume, passes a fresh one and a volume with the marker. The exporter answers
|
||||||
published port, and the switch back removes the pod before the container starts.
|
the host's own processes through the published port, and the switch back
|
||||||
|
removes the pod before the container starts.
|
||||||
|
|
||||||
The VM test `k8s-controller-switch` moves the controller. It asserts one copy at
|
The VM test `k8s-controller-switch` moves the controller. It asserts one copy at
|
||||||
each step by the switch's own timestamps and by a sampler, that the pod is Ready
|
each step by the switch's own timestamps and by a sampler, that the pod is Ready
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue