narwhal fleet¶
narwhal fleet reads and changes a deployed fleet at the router that holds the lease. status compares the fleet with the fleet file that its routers loaded. watch redraws each engine's role, load and latency. drain takes engines out of placement and readmit returns them. reset returns the fleet to the fleet file:
narwhal fleet status
narwhal fleet watch
narwhal fleet drain n2 --wait
narwhal fleet readmit n2
narwhal fleet reset
drain and readmit take engine IDs as the routers know them, and status lists them: n1, n2 and so on. They correspond to the fleet file's roles engine-1, engine-2, which also name the engine pods on Kubernetes. A router refuses a name the fleet does not hold, and the refusal lists the IDs it does hold.
Each subcommand reads state from either router of a pair, finds the lease holder, and sends an action to that router only. status and watch send no action. A standby answers fleet reads with 503. So does a router that lost the lease between the read and the action. narwhal fleet never retries an action at the other router. Run the command again.
On SSH hosts¶
The workstation calls the routers itself. --fleet is the same NarwhalFleet file that narwhal deploy reads. It names the routers in spec.ssh.router.url and spec.ssh.standby.url, and its secrets file holds routerToken, the control token that every action carries. status needs no token.
The command reaches each of those routers through an SSH forward to the router's own host. The forward goes the way narwhal deploy reaches the hosts, with spec.ssh.knownHosts, spec.ssh.jump and each host's login. The workstation needs no route to a router's address and no tunnel. The SSH log is in live/fleet/ in the run directory, or in runs/access-<id>/ without one. When SSH cannot open a forward, the command exits 4 and names the cause and that log, such as cannot reach the router on host-a over SSH: ssh: connect to host 192.0.2.10 port 22: Connection refused; ssh exited 255; inspect .narwhal/runs/first-fleet/live/fleet/host-a.log.
--run is the run directory of narwhal deploy run. status compares the routers' membership with the engines of the fleet file that the fleet-limits stage wrote and the routers loaded. reset returns the fleet to that file, so reset needs --run. An action takes the run's lock, so it never interleaves with a narwhal deploy run of the same run.
--router URL calls a router directly at that URL, in place of the routers that the fleet file names over SSH. Give it once for each router of a pair. Use it for a router you started yourself, or the local end of a tunnel you already hold. Without a fleet file, actions read the token from NARWHAL_ROUTER_TOKEN:
narwhal fleet status --router http://127.0.0.1:18000 --router http://127.0.0.1:18001
NARWHAL_ROUTER_TOKEN=... narwhal fleet drain n2 --router http://127.0.0.1:18000
Watching the fleet¶
watch shows the view of narwhal dev watch for a fleet on SSH hosts: each engine's role and requests in flight, the time to first token and time per output token at the median and the 95th percentile, the throughput, each engine's role history, the role switches and the role controller's last decision. It finds the routers as status does, through the fleet file and an SSH forward to each router's host, or at the --router URLs:
narwhal fleet watch --fleet narwhal-fleet.yaml
narwhal fleet watch --router http://127.0.0.1:18000 --router http://127.0.0.1:18001
Each redraw reads /narwhal/state from the router that holds the lease, then /metrics from that same router. It sends no action and no control token. A standby counts only what it served, so after a takeover the figures start again at the new lease holder, and the heading names it. While no router holds the lease, the view says so and keeps reading. When a reading fails because the SSH forward to a router's host ended, watch stops and exits 4, naming the cause and the SSH log.
watch runs until you press Ctrl+C. With --once or --format json, it takes two readings one --interval apart and prints that frame. On Kubernetes the workstation reaches no router, so watch refuses --target kubernetes. Watch a cluster's fleet in Grafana.
On a Kubernetes cluster¶
With --target kubernetes, the workstation never reaches a router. It sets the fleet's narwhal-inference.com/fleet-request annotation to a nonce, the verb, the engines and the drain deadline. It then waits for the controller's answer under that nonce in status.fleetRequests. The controller runs the request in a router-check Job with the control token from spec.controlTokenSecret, and compares status and reset with the fleet file that its own fleet-limits stage wrote.
The workstation writes only the annotation, so a fleet that Helm, Argo CD or Flux owns takes requests too, with the same fleet-editor Role that narwhal deploy uses.
narwhal fleet status --target kubernetes --namespace <namespace>
narwhal fleet drain n2 --target kubernetes
Name the fleet with --fleet (its metadata.namespace gives the namespace), with --namespace, or with a --run directory that narwhal deploy run --target kubernetes made. The controller takes one request per fleet every 5 seconds and runs one at a time. A request that arrives while another runs gets the answer a fleet request is running; retry. The workstation then asks again under a new nonce until --timeout. It also asks again 30 seconds after another request replaces the annotation before the controller takes this one. A controller that restarts while a request runs answers it with an error once it is back, since the router may or may not have acted on it. Check with narwhal fleet status before you repeat a drain, readmit or reset. status.fleetRequests keeps the last four answers. An error that points at the action log replaces a result larger than 32 KiB.
--wait follows a drain on SSH hosts only. On a cluster, run narwhal fleet status --target kubernetes until the engine reads drained.
What each subcommand does¶
| Subcommand | Operation |
|---|---|
status |
Prints each router's readiness and the router that holds the lease, with its epoch. Prints each member with its role, its lifecycle state and whether it accepts new requests. It also prints each engine that differs from the fleet file. An engine differs when it is not a member, is not active, is ejected or is quarantined. It also differs when it is a member that the file does not name. A blocked engine carries relaunch: true when its peers' KV transfers to its process fail, as after a long freeze. The text report then names the relaunch. Stop the engine's container and run narwhal deploy run --run <run>, or on Kubernetes delete its engine pod. status reports the fleet as degraded in three cases. An engine differs. The lease holder is not ready. No other router of the pair stands by to take over. A router stands by when its /ready answers 503 with the reason shadowing. A router does not stand by when it lost its lease, is blocked (such as with no fresh handoff), or does not answer. |
drain |
Sends one lifecycle drain per engine, in order. It stops at the first drain that the router refuses and reports the engines after it as not_sent. Each drain sends restart: false, so the engine keeps running out of placement and readmit takes the same process back. --deadline sets the router's drain deadline. The router refuses a drain when the fleet's engine_contract is incomplete, because readmission needs it. A dev fleet on llama.cpp engines has none. With --wait, drain follows each engine until it is drained, and reports the fleet as degraded once an engine is past its deadline. |
readmit |
Sends one readmission per engine, in order, and stops at the first that the router refuses. The router readmits only a drained or blocked engine, once its readmission checks pass. The checks test the attestation of the process that runs now. An engine restarted during the drain comes back the same way as one that kept running. |
watch |
Redraws the live view from the lease holder's /narwhal/state and /metrics until Ctrl+C, as Watching the fleet describes. With --once, it prints one frame and exits. On SSH hosts only. |
reset |
Readmits each drained or blocked engine. It joins each engine that the fleet file names and that is not a member, with its endpoint as the file gives it. On SSH hosts, a ${VAR} endpoint resolves as the run resolved it. The sources, in order, are the variables that the run's discover stage derived (such as NARWHAL_NODE_<n>_URL), the --fleet file's variables, and the shell's variables. reset refuses an endpoint that does not resolve and never sends it. It leaves a member that the file does not name. It reports an engine that is draining, past its deadline, validating or ejected as degraded, because the router owns those states. |
Every action reports each change with its engine, action, outcome, the router that answered, the router's error and the engine's state after it.
The action log¶
Each drain, readmit and reset with --run appends its result document as one JSON line to <run>/fleet/actions.jsonl. narwhal fleet creates fleet/ at mode 0700 and the file at mode 0600. It refuses a file that is not a regular file you own, or that other users can read. status writes nothing. On Kubernetes, the controller also appends each action to the same file in the fleet's run directory on the state volume.
Output and exit codes¶
In text mode, stdout carries the report, and a failure writes one stderr line, narwhal: fleet <subcommand>: <cause>. With --format json, every subcommand prints a versioned command result whose data is the result document. For watch, that document is the frame, with router, the lease holder that answered.
| Outcome | Status | Exit code | Error code |
|---|---|---|---|
Every change took effect, or status found nothing to report |
success |
0 |
|
| A router refused an action. Examples: a drain of an engine it does not hold, a readmission whose checks failed, or a router that lost the lease before the action. | failed_gate |
1 |
router_refused |
Invalid arguments, a fleet file that narwhal deploy would refuse, a run directory of another target, or a missing control token. |
invalid_input |
2 |
invalid_input |
| An engine differs from the fleet file, such as one drained, blocked, ejected or quarantined. Also: a drain passed its deadline, the lease holder is not ready, or no other router stands by. | degraded |
3 |
fleet_differs |
No router controls the fleet, or a router did not answer. Also: SSH could not open the forward to a router's host, another runner holds the run, or the controller did not answer within --timeout. |
error |
4 |
no_controller, operation_failed or follow_timeout |
Options¶
Every subcommand takes --format, --target, --fleet, --run and --router. Every subcommand but watch also takes --namespace and --timeout. drain adds --deadline and --wait. watch adds --interval and --once. When none of --fleet, --router, --namespace and --run is given, a subcommand reads narwhal-fleet.yaml where it exists. It also reads the run directory that narwhal deploy keeps for that fleet under .narwhal/runs/, where that exists.
| Option | Default | Description | Valid values |
|---|---|---|---|
--format |
text |
Output format, either text or json for versioned command results. |
|
--target |
ssh |
Where the fleet runs: on SSH hosts, whose routers the command calls over SSH, or on a Kubernetes cluster, whose controller runs the request. | ssh or kubernetes |
--fleet |
None | The NarwhalFleet file. On SSH hosts it names the routers, and its secrets file holds the control token. On Kubernetes its metadata.namespace names the fleet. On SSH hosts, required unless you give --router. |
A file narwhal deploy accepts |
--run |
None | The run directory of narwhal deploy run. It holds the fleet file that the routers loaded, which status compares and reset returns to. The action log goes there. On SSH hosts it needs --fleet, and reset needs it. |
A run directory you own, mode 0700 |
--router |
The fleet file's routers, each through an SSH forward to its host | On SSH hosts, a router URL to call directly, in place of the routers that the fleet file names. Use it for a router you started yourself, or a tunnel's local end. Repeatable, once for each router of a pair. | http://HOST:PORT or https://HOST:PORT |
--namespace |
The one the run directory follows | On Kubernetes without --fleet, the namespace whose fleet to act on. |
A DNS label |
--deadline |
The router's 300 |
Seconds the router lets each engine drain before it reads deadline_exceeded. |
A positive number up to 86400 |
--wait |
Off | On SSH hosts, follow each drained engine until it reads drained or passes its deadline. |
|
--interval |
1.0 |
Seconds between redraws of watch, and between the two readings of --once. |
A positive number |
--once |
Off | Makes watch print one frame and exit. |
A flag with no value |
--timeout |
600 |
Seconds each router request, the --wait follow, or the controller's answer may take. |
A positive number |