Deploying on Kubernetes¶
A NarwhalFleet resource holds the fleet's deployment inputs. The fleet controller, which the narwhal chart installs in the same namespace, runs the stage graph for it. Each check runs as a gate Job. These are the checks narwhal deploy runs on SSH hosts, with the same rerun rules and evidence. The controller builds the engine StatefulSet, the router pair and HAProxy. It owns each object it makes through an owner reference to the fleet, and it writes what it observed to the fleet's status.
The fleet is the only thing you write. Apply it with kubectl apply or a GitOps tool, or let narwhal deploy --target kubernetes --fleet apply it from a workstation. The file format is the one narwhal deploy reads on SSH hosts. The controller ignores the spec.ssh section that SSH hosts need. NarwhalFleet reference lists every field and the target that reads it.
Cluster requirements¶
The cluster admin provides:
- Kubernetes 1.35 or later. The chart requires it.
- A GPU device plugin on every engine node. Engines that send KV over
ucx_rdmaalso need an RDMA device plugin. Engines on several nodes send KV overucx_rdmaunlessNARWHAL_TRANSFER_TRANSPORTisucx_tcp. Each engine pod requests its GPUs, and forucx_rdmaone HCA, under the extended resource names inspec.engines.resources.accessfails on an engine node that offers no GPU, or no HCA whenspec.engines.resources.rdmanames one. Engines on one node send KV overucx_tcpunless the fleet setsucx_rdma. Engines that useucx_tcprequest no HCA. - An RDMA resource,
spec.engines.resources.rdma, with these properties. On each engine node it holds only one HCA, the one thatNARWHAL_TRANSFER_NET_DEVICESor the node'sNARWHAL_NODE_<n>_TRANSFER_NET_DEVICESnames. Several pods may hold it at once. The engine pod and the fabric Jobs offabric-edgeboth request it, so the fabric stages measure the HCA the engine sends KV through. The resource needs room for the node's engine pods, one fabric server Job and one fabric client Job. An RDMA resource from the generic device plugin shows how. A pool that hands each pod any one of several HCAs does not work. The engine pod's runtime check and each fabric Job compare the HCA they hold with the one the fleet names. Engines that share a node also share its HCA, because the one engine StatefulSet requests one set of resources. - For
ucx_rdmaengines that share a node, HCA port counters on that node.cat /sys/class/infiniband/<hca>/ports/<port>/counters/port_xmit_datamust print a number there. Thehcagate of preflight reads the counter to check that KV between those engines crossed the HCA.discoverrefuses the fleet before any engine starts when a node cannot read the counter. A node that runs in a network namespace other than its kernel's initial one shows its RDMA devices without counters, as a node that runs as a container does. Therediscoverand preflight skip the same-host HCA check and name the engine and its node, so KV between those engines passes without proof that it crossed the HCA. To leave no path unchecked, send KV overucx_tcpthere or place one engine on each node. Engines on different nodes need no counters. - Engine nodes that carry no
NoScheduleorNoExecutetaint, or only taints thatspec.engines.tolerationsmatches. A taint whose key is the GPU or RDMA resource name the engine pods request, such asnvidia.com/gpu, is allowed. The engine pods carry the fleet's tolerations, and so does each gate Job that runs on an engine node. - A default StorageClass that offers ReadWriteMany for the state volume, or one that
state.storageClassNamenames. The controller and its gate Jobs mount the volume on every node. On NFS, mount itsoft, as Storage on a lost node explains. The storage must keep the numeric user and group that each client gives a file. No engine, router or HAProxy pod mounts the volume. - A volume that serves the checkpoint, a PersistentVolumeClaim in the namespace by default. When
spec.engines.model.fetchnames a source, the controller's user,controller.runAsUser, must be able to write the volume. A volume shared by several engine nodes must be ReadWriteMany. Engine pods mount it for as long as they run, so on NFS mount itsofttoo. - A network plugin that enforces NetworkPolicy. The chart's policy is what keeps the routers' control routes away from everything but HAProxy, the gate Jobs, the other router and monitoring.
- Images in a registry the nodes pull from, each pinned by digest: the engine image, and the images the release names. The released narwhal chart sets every other image by digest from its release manifest. These are the Narwhal image and the narwhal-host image on
ghcr.io, HAProxy 3.4 (haproxy:3.4-alpine), Prometheus v3.16.0 and Grafana 13.3.2, the versionsmake observepins. A fleet'sspec.images.hostandspec.images.haproxyreplace the chart's. A cluster that cannot pull fromghcr.ioruns images built from the repository'sDockerfile. - A namespace for each fleet, labelled
pod-security.kubernetes.io/enforce=privilegedwhen the cluster enforces the Pod Securitybaselinelevel by default. The engine pods need the host network andIPC_LOCK, whichbaselinerefuses. The chart's admission policy applies the baseline's other rules instead.
The workstation needs helm and kubectl, and cosign v3 to check the release's signatures. It installs the chart from ghcr.io and needs no checkout of the repository.
An RDMA resource from the generic device plugin¶
The generic device plugin can serve the RDMA resource. Each --device is one resource, named <--domain>/<name>. A group lists the paths a pod gets and count, how many pods may hold it at once. For engines that send KV through the HCA whose verbs device is uverbs0 on every engine node, give the plugin's container these arguments:
args:
- --domain=rdma
- --device
- |
name: hca
groups:
- count: 4
paths:
- path: /dev/infiniband/uverbs0
- path: /dev/infiniband/rdma_cm
The fleet then names the resource rdma/hca, in spec.engines.resources.rdma, which is engines.resources.rdma in a fleet file that narwhal deploy --target kubernetes applies. Put one verbs device in each group: a pod that holds two fails its runtime check. Fabric qualification inputs shows how to find the verbs device of an HCA port.
Engine nodes may send KV through HCAs with different verbs devices, such as uverbs0 on one node and uverbs1 on another. Then add a group for each device. That works only while each node has just its own group's device. A node that has both devices advertises both groups, which makes a pool of two HCAs. In that case, run one plugin DaemonSet for each set of nodes. Give each DaemonSet a nodeSelector and the group of its nodes' device under the same resource name. Each engine on a node with another device also needs its own NARWHAL_NODE_<n>_TRANSFER_NET_DEVICES and NARWHAL_NODE_<n>_TRANSFER_DEVICES in spec.engines.launch.
Before you apply the fleet, check that every engine node offers the resource:
Installing the chart¶
Each release publishes the narwhal chart as an OCI artifact at oci://ghcr.io/athrael-soju/charts/narwhal, at the release's version. It also publishes the Narwhal and narwhal-host images at ghcr.io/athrael-soju/narwhal and ghcr.io/athrael-soju/narwhal-host, and the release manifest, which names every image and the chart by digest. The release workflow signs both images, the chart and the manifest keylessly. Verifying a release checks them. Install the chart in the fleet's namespace, with no values file:
helm install narwhal oci://ghcr.io/athrael-soju/charts/narwhal --version <version> \
--namespace <namespace> --create-namespace
Helm installs the NarwhalFleet CRD from the chart's crds/ directory first. It then installs the controller and its RBAC, the namespace's admission policy, the engines' and routers' ServiceAccounts, the router Lease and its Role, the routers' NetworkPolicy, the state claim and the monitoring. With gateway.mode set, it also installs the Gateway API objects of Serving through a Gateway. It renders no fleet, engine, Job, router or HAProxy object.
With the chart's defaults:
- The state claim takes 200Gi from the cluster's default StorageClass, which must offer ReadWriteMany.
state.storageClassNameandstate.sizechange these. - Prometheus and Grafana run from the images the release pins. Grafana serves the dashboard the chart holds, rendered when the chart was packaged.
- The controller creates Grafana's admin login in the Secret
grafana-admin, unlessmonitoring.grafana.adminnames a Secret you made. Read the password withkubectl get secret grafana-admin --namespace <namespace> -o jsonpath='{.data.password}' | base64 -d. If the Secret goes, as when someone deletes it or the Deploymentgrafanathat owns it, the controller creates a new login within a minute, also while a pass runs. Grafana reads the login when its container starts, so a running Grafana pod takes the new one only when it restarts. Withmonitoring.grafana.storage, Grafana keeps its database on the claim, and an init container sets the admin password from the Secret before each start. A password changed in Grafana itself lasts until the pod restarts.
The cluster admin's allow-lists stay off until you set them. They cover the RuntimeClasses a pod may name and the model volume sources other than a PersistentVolumeClaim. For engine nodes whose default runtime exposes no GPUs and a checkpoint in a directory on each node, pass a values file such as:
runtimeClassNames: ["<GPU RuntimeClass>"]
modelVolumeSources: [persistentVolumeClaim, hostPath]
modelHostPathPrefixes: ["<directory that holds the checkpoint>"]
The narwhal chart's README lists every value.
Upgrading the chart and its CRD¶
Helm never upgrades or deletes a CRD from crds/, so apply the new release's CRD server-side, then upgrade the release:
helm show crds oci://ghcr.io/athrael-soju/charts/narwhal --version <version> \
| kubectl apply --server-side --force-conflicts -f -
helm upgrade narwhal oci://ghcr.io/athrael-soju/charts/narwhal --version <version> \
--namespace <namespace> --reset-then-reuse-values
--reset-then-reuse-values keeps the settings you gave at install, such as runtimeClassNames, and takes the new chart's image digests. --reuse-values would keep the old release's images, since the chart holds them as values. An upgrade with neither flag drops your settings.
Helm applies the CRD at install under its own field manager. A changed field therefore conflicts unless --force-conflicts takes it over. A controller whose schema differs from the installed CRD's stalls the fleet with reason SchemaStale and starts nothing, so apply the CRD first. The CRD is cluster-wide. Upgrade every namespace's release to the version whose CRD you applied. helm uninstall leaves the CRD and the fleets in place.
Verifying a release¶
Check that Narwhal's release workflow signed the images and the chart before you install them. Read the images' digests from the chart:
helm show values oci://ghcr.io/athrael-soju/charts/narwhal --version <version> | grep -A9 '^images:'
Then verify the signatures with cosign v3:
cosign verify ghcr.io/athrael-soju/narwhal@sha256:<digest> ghcr.io/athrael-soju/narwhal-host@sha256:<host digest> \
ghcr.io/athrael-soju/charts/narwhal:<version> \
--certificate-identity-regexp '^https://github\.com/athrael-soju/Narwhal/\.github/workflows/release\.yml@refs/heads/main$' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
cosign fails unless each signature's certificate names the release workflow running on main and the signature is in Sigstore's transparency log. The same flags with cosign verify-attestation --type spdxjson check each image's SBOM. gh attestation verify oci://ghcr.io/athrael-soju/narwhal@sha256:<digest> --repo athrael-soju/Narwhal checks the SLSA build provenance of the Narwhal image.
The release manifest¶
Each GitHub release carries narwhal-release-manifest.json, a narwhal.release-manifest document that names every image and the chart of the release by digest, and its keyless cosign bundle. Download both from the release and verify the bundle with the same identity:
gh release download v<version> --repo athrael-soju/Narwhal \
--pattern 'narwhal-release-manifest.json*'
cosign verify-blob narwhal-release-manifest.json \
--bundle narwhal-release-manifest.json.sigstore.json \
--certificate-identity-regexp '^https://github\.com/athrael-soju/Narwhal/\.github/workflows/release\.yml@refs/heads/main$' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
sha256sum narwhal-release-manifest.json
The manifest holds the version, and under images the entries narwhal, narwhal-host, haproxy, prometheus, grafana and grafana-image-renderer. Each entry has the reference that nodes and hosts pull, <repository>@sha256:<digest>, and the digest itself. For each platform, it has the platform manifest digest and the image_id, the image's config digest. charts holds the narwhal chart's oci:// reference and manifest digest. engines holds, in the same shape, the engine image each backend's release qualification ran: vLLM, SGLang and TensorRT-LLM. narwhal deploy init writes the backend's into spec.engines.image, and the released chart's images.engines names the same images for a fleet that names none.
A pulled image is the manifest's when its ID is the digest, as Docker's containerd image store and RepoDigests show it. It is also the manifest's when its ID is the host platform's image_id, as the classic image store and the kubelet's imageID show it. Any other ID is another image.
A fleet pins the manifest it deploys in spec.release, with the version and the sha256sum above:
narwhal deploy plan and run then read the manifest from the release over HTTPS. For an air-gapped or pre-release deploy, they read a copy with --release-manifest FILE. They refuse it unless its SHA-256 and version equal the pin. Give the narwhal chart the same file. Until the chart carries a manifest whose SHA-256 and version equal the pin, the controller refuses a fleet with spec.release with reason InputRefused:
helm upgrade narwhal oci://ghcr.io/athrael-soju/charts/narwhal --version <version> \
--namespace <namespace> --reset-then-reuse-values \
--set-file releaseManifest=narwhal-release-manifest.json
The controller then runs the manifest's HAProxy and narwhal-host images wherever the fleet names none. It also runs the manifest's engine image for the engines' backend wherever the fleet names none. spec.images.haproxy, spec.images.host and spec.engines.image override each. A manifest that names no engine image for the backend leaves spec.engines.image required. The chart's own pods run images the controller cannot choose. The controller therefore also refuses the fleet unless these chart values have the manifest's digests. They are images.narwhal, which every router, gate Job and sidecar runs, and, with the chart's own monitoring, monitoring.prometheus.image and monitoring.grafana.image. A copy in your own registry at the same digest passes.
Building the image yourself¶
A cluster that cannot reach ghcr.io runs the Narwhal and narwhal-host images from your own registry. Build both from a checkout at the release tag, push them, and note the digests the pushes print:
git clone --branch v<version> https://github.com/athrael-soju/Narwhal
cd Narwhal
docker build -t <registry>/narwhal:<version> .
docker build --target host -t <registry>/narwhal-host:<version> .
docker push <registry>/narwhal:<version>
docker push <registry>/narwhal-host:<version>
Package the chart from the checkout as the release does. tools/maintenance/release_artifacts.py writes a manifest of your images and the upstream images the release pins, reading each from its registry with docker buildx imagetools inspect. It then packages the chart with every image default set to the manifest's image, and with the CRD and the rendered dashboard in it:
python3 tools/maintenance/release_artifacts.py manifest --version <version> \
--image narwhal=<registry>/narwhal@sha256:<digest> \
--image narwhal-host=<registry>/narwhal-host@sha256:<host digest> --out images.json
python3 tools/maintenance/release_artifacts.py package --manifest images.json --out charts
helm install narwhal charts/narwhal-<version>.tgz --namespace <namespace> --create-namespace
The chart in the checkout has no default Narwhal or narwhal-host image, so helm install of deploy/helm/narwhal itself fails without images.narwhal. The package names the HAProxy, Prometheus and Grafana images the release pins. If the nodes cannot pull from Docker Hub, set images.haproxy, monitoring.prometheus.image and monitoring.grafana.image to copies in your registry. Alternatively, once the published images and chart verify as above, copy them into your registry with a tool such as crane copy and helm pull.
Applying the fleet¶
A fleet needs no Secret of its own. If the fleet names no controlTokenSecret or engines.apiKeySecret, the controller generates the routers' control token and the engine API key. Credentials describes them.
Give the controller the fleet in one of these ways.
- With
kubectl apply. Apply aNarwhalFleetnamedfleet, such as a reference layout with its values set to the cluster's. The API server checks it against the CRD's schema and CEL rules:
apiVersion: narwhal-inference.com/v1alpha1
kind: NarwhalFleet
metadata:
name: fleet
namespace: <namespace>
spec:
engines:
image: <registry>/engine@sha256:<digest>
model:
name: <served model name>
modelVolume:
persistentVolumeClaim:
claimName: models
resources:
gpu: <GPU resource name>
rdma: <RDMA resource name>
runtimeClassName: <GPU RuntimeClass>
slo:
ttftS: "<seconds>"
tpotS: "<seconds>"
kubectl apply --server-side --namespace <namespace> -f narwhal-fleet.yaml
kubectl wait --namespace <namespace> --for=condition=Ready narwhalfleet/fleet --timeout=4h
- Through GitOps. Keep the fleet file in the repository that a tool such as Argo CD or Flux syncs, beside the chart's release. Helm installs the CRD before the chart's templates. Give the fleet its own sync step after the chart, or an Argo CD
argocd.argoproj.io/sync-wavelater than the chart's. The controller changes nothing the chart rendered and writes only the fleet's status. A workstation adds only therequested-at,export-requestandfleet-requestannotations. - From a workstation.
narwhal deploy run --target kubernetes --fleet FLEET --run DIRapplies the fleet fileFLEETserver-side as the field managernarwhal-cli. It follows the fleet's status and copies the evidence intoDIR. For a fleet whose spec another field manager owns, such as Helm, Argo CD or Flux, it follows the fleet and never writes that spec. It writes only thenarwhal-inference.com/export-requestannotation that asks for the evidence.narwhal deploydescribes the subcommands.
A namespace holds one fleet, and the API server refuses a fleet with another name. The controller refuses it too, with reason NameRefused.
Choosing the engine nodes¶
Without spec.engines.nodes, access takes every Ready, schedulable node that offers the GPU resource, and discover lays the engines out on them. A node is schedulable when it is not cordoned and carries no NoSchedule or NoExecute taint. A taint whose key is the GPU or RDMA resource name it offers does not count, and neither does a taint that spec.engines.tolerations matches. A toleration there takes the shape of a pod's, such as {key: dedicated, operator: Equal, value: inference, effect: NoSchedule}. access prints a line for each node it skips. One such line is access: skipped node gpu-b carries the taint dedicated=training:NoSchedule, which the engine pods do not tolerate. The GPU resource is spec.engines.resources.gpu. Without that field, it is the one <domain>/gpu resource the nodes offer, such as nvidia.com/gpu or amd.com/gpu. access fails and names the resources when the nodes offer more than one. spec.engines.nodeSelector keeps only the nodes that carry each of its labels. spec.engines.nodeCount takes that many of the remaining nodes, the first by name. access fails and names the matching nodes when fewer nodes match than nodeCount asks for. spec.engines.nodes places every engine itself, so the API server refuses it together with either field. spec.engines.gpusPerEngine sets the GPUs each engine pod requests. Without spec.engines.nodes, each node then runs as many engines as its GPUs hold, so the value must divide each node's GPUs. Engine pods run on the node's host network, so engines that share a node need their own ports. Without spec.engines.nodes, leave spec.engines.ports out and each engine takes its own. discover refuses engines on one node whose ports overlap, and names the field to change. A node that joins the cluster later runs no engine until one of those changes reruns access.
Credentials¶
The controller generates each Secret the fleet does not name, before the first stage of a pass. These are narwhal-router-token for controlTokenSecret and narwhal-engine-key for engines.apiKeySecret. Each is Opaque and immutable, holds 32 random bytes in hex, and names the fleet as its controlling owner, so deleting the fleet deletes both. A Secret of either name that the fleet does not own stalls the fleet with reason SecretNotOwned, and the controller uses none of it. If an earlier fleet of the name owns the Secret, the pass waits until the garbage collector deletes it. The chart's Secret admission policy, <namespace>-narwhal-secrets, lets the controller create only two kinds of Secret. One is the two fleet Secrets, Opaque, immutable and owned by a NarwhalFleet. The other is Grafana's admin login, owned by the Deployment grafana. The controller generates nothing while that policy or its binding is missing. It stalls the fleet with reason AdmissionPolicyMissing.
To choose the credentials yourself, create Secrets and name them in spec.engines.apiKeySecret and spec.controlTokenSecret. Keep each Secret immutable and give its name a version, such as engine-key-v2. To rotate the engine key or the control token, create the next Secret and point spec.engines.apiKeySecret or spec.controlTokenSecret at it. A generated Secret is never rotated in place. A key-check Job holds both credentials. It reports only their HMACs, under a salt kept in the run directory. A credential edited in place therefore also counts as a change. A new engine key restarts the engines and the routers. A new control token restarts only the routers. The controller runs the key check after each edit or new requested-at value, and otherwise every controller.keyCheckPeriodSeconds, 900 by default.
Only the containers that call engines and the key-check Job read the engine key. Only the routers, the router-check Jobs of router-start and the key-check Job read the control token. The controller copies the references and never reads a Secret the fleet names. The CRD and InputRefused both refuse a controlTokenSecret with the name and key of engines.apiKeySecret. The controller cannot see two Secrets that hold the same value. The routers therefore compare the token with the engine key when they start, and refuse to start when they match.
The key check also refuses an engine key under 32 random bytes, by the rule plan applies to engineKey on SSH hosts: 64 hex digits or 43 base64url characters. It runs before the first stage of a fleet's first pass, and of each pass after an edit or a new requested-at value, so a weak key stops the fleet before any engine starts with it. The fleet then stalls with reason InputRefused, and the message names the Secret and its key, never the value.
Reading the status¶
kubectl get narwhalfleet shows whether the fleet serves and whether it is ready. It also shows the stage its latest pass runs or stopped at, and how many engines passed engine-check on nodes that are currently Ready. After discover stops the engines for a rerun, SERVING is false and ENGINES counts only the engines that passed engine-check since then. This lasts until router-start passes again:
kubectl wait --for=condition=Ready returns once Ready is True and the condition's observedGeneration has reached the fleet's metadata.generation. It never returns for a spec that the controller has not yet run a pass for. It exits nonzero at the timeout. kubectl describe narwhalfleet fleet prints every condition with its reason and message. For a fleet that sets no spec.engines.model.treeSha256, status.model.treeSha256 holds the checkpoint tree that the first discover to pass pinned.
status.observedGeneration is the generation the latest pass started from. If the fleet's metadata.generation is ahead of it, the fleet has an edit that the controller has not acted on. Ready, Reconciling and Stalled follow the kstatus conventions, so exactly one of them is True unless the fleet is stopped:
| Condition | True when |
Reasons |
|---|---|---|
Ready |
A pass for the current generation has passed every stage up to spec.until. Its live checks hold, every engine node is Ready, and the routers hold no engine out of placement |
Passed when true. Its message names the last stage up to spec.until. It says when spec.until stops the run before router-start. Otherwise the reason of the condition that is true. It is Running, Retrying, Stopping, Stalled or Stopped. It is EnginesStopped when a failed discover stopped the engines. It is EngineNodeNotReady when every stage passed but an engine node is not Ready. It is EnginesHeld when every stage passed and every engine node is Ready. The router that holds the Lease then keeps engines out of placement, as Held engines describes |
Reconciling |
A pass runs, or one will | Running while a stage runs. Retrying after an error the controller retries, such as an unreachable API server, an interrupted attempt or work pinned to a lost node. Stopping while spec.stopped takes effect. EngineNodeNotReady while an engine node is not Ready, with the EngineNodesReady message. Ready, Stalled or Stopped when false |
Stalled |
No pass runs until something changes | StageFailed, InputRefused, SchemaStale, AdmissionPolicyMissing, SecretNotOwned, RouterStorageImmutable, NameRefused, as below. Ready, Reconciling or Stopped when false |
Stopped |
spec.stopped is true and the fleet's workloads are gone |
Stopped, Stopping while they go, Running |
EngineNodesReady |
Every engine's node is Ready |
NodesReady, with a message that names each node whose loss would leave fewer than two engines. NodeNotReady names each node that is not Ready or is gone, since when, and the engines on it. It also gives how many engines are left on Ready nodes, by the roles the fleet file starts them in, as Node loss describes |
Stalled reason |
Cause | What clears it |
|---|---|---|
StageFailed |
A stage failed or exceeded its time limit. The message names the stage instance and its failure. A gate Job's shell may stop at a tool's error, such as cp: cannot stat .... The message is then the tool's last error line from the Job log, with credentials redacted and cut to at most 300 characters. It ends with (sh exited with status <n>). When discover failed after it stopped the engines, the message ends engines stopped for discovery; the fleet is not serving |
An edit of the spec, or a new requested-at value |
InputRefused |
An input is missing or malformed, or outside the cluster admin's allow-lists for model volumes and RuntimeClasses. The engine key in the Secret that spec.engines.apiKeySecret names holds fewer than 32 random bytes. The message names each problem |
An edit that fixes it. For a Secret fixed in place, a new requested-at value |
SchemaStale |
The installed CRD holds another schema than the one the controller was built with. | Applying the release's CRD server-side, as Upgrading the chart and its CRD shows |
AdmissionPolicyMissing |
The namespace's admission policy or its binding is missing, or the binding does not deny. For a fleet whose Secrets the controller generates, the same for the Secret admission policy | Installing or upgrading the narwhal chart |
SecretNotOwned |
A Secret the controller would generate exists. Either the fleet does not own it, or the fleet owns it and it is not Opaque or lacks its key. The Secrets are narwhal-router-token and narwhal-engine-key |
Deleting the Secret, so the controller generates it. Naming a Secret of your own in spec.controlTokenSecret or spec.engines.apiKeySecret |
RouterStorageImmutable |
spec.routers asks for a storage class or size that the router StatefulSet's volume claim template does not hold. Or it moves the routers between claims and emptyDir volumes. The message names the StatefulSet and claims |
Putting spec.routers back. Or deleting the StatefulSet router and the claims router-state-router-0 and router-state-router-1, which loses the routers' journals and handoff state |
NameRefused |
The fleet is not named fleet |
Applying it as fleet |
Each stage the run record holds also has a condition, typed stage.narwhal-inference.com/<stage>. Its reason is the run-record status of the stage's worst instance, in CamelCase. From worst to best, the order is Failed, Timeout, Interrupted, Cancelled, Running, Invalidated, Passed. The status is True for Passed, Unknown for Running and False for the rest. A stage whose evidence the pass copied from an earlier fleet has the reason Reused and status True. Its message starts evidence reused from run <id>. The message gives the reasons the stage last ran after ran because:, such as an input that changed. For a failed instance, the failure comes first. A stage after spec.until keeps the condition an earlier pass left, and its message ends from an earlier pass; spec.until stops at <stage>. The message of a failed gate is the gate's own failure line, such as the FAIL lines of the preflight report. A failure that names an input names the fleet field that sets it, such as spec.engines.nodes[0].rdma.gidIndex or the spec.engines.launch entry NARWHAL_TRANSFER_DEVICES. status.stages.<stage> counts the instances that passed, out of all the stage runs, with the time one last passed. The run record keeps per-instance detail.
Evidence and logs¶
The controller keeps each fleet's run directory on the state volume, at /narwhal-state/runs/<namespace>/<fleet uid>/. It holds the run record run.json and each stage attempt's evidence in stages/<stage>/<instance>/attempt-<n>/, with the log of each of its Jobs in logs/<job>.log. Each gate Job also keeps its own output, exit status and returned files on the volume, in /narwhal-state/deploy/<run-id>/stages/<stage>/<instance>/attempt-<n>/jobs/<job>/. A gate mounts only that directory, its attempt's work directory and the directories it reads, each by its own subPath. A fleet that is deleted and made again under its name gets a new uid and a new directory. status.previousRuns names the earlier directories the controller kept. Each pass keeps the newest spec.retainRuns directories of the namespace, 3 by default, and the one that spec.reuseFrom names. It deletes the rest, each with its work tree under /narwhal-state/deploy/<run-id>/. While a failed stage stalls the fleet, the run directory also holds controller-stall.json, which keeps the stall across a controller restart.
narwhal deploy status --target kubernetes --run DIR copies the run record and the evidence of every finished attempt into the workstation's run directory. DIR must be a run directory that narwhal deploy run --target kubernetes made. For a fleet that Helm, kubectl or a GitOps tool applied, run with the same fleet file makes the directory. It follows the fleet and does not write its spec. status and down need no fleet file, because the cluster holds the fleet. They follow the namespace that the run directory follows, or the one --namespace names. With a DIR that does not exist, status --namespace <namespace> only reads the fleet, prints its conditions and stages, and copies nothing.
The workstation sets the fleet's narwhal-inference.com/export-request annotation to a nonce and the attempts it already holds. The controller creates the Job from its own image, user and group, and names it under that nonce in status.exports. The Job mounts read-only only run.json and the attempt directories asked for. It never mounts the run directory's root, which holds the salt that keys the record's digests and the key check's salt and HMACs. Each nonce is used once. Once the Job's pod succeeds, the controller reads its log and adds the pod's name and the log's SHA-256 and size to the answer. The workstation reads that pod's log, imports nothing unless the digest matches, and checks every file against the log's manifest. An admin can also read the volume through the controller pod:
uid=$(kubectl get narwhalfleet fleet --namespace <namespace> -o jsonpath='{.metadata.uid}')
kubectl exec --namespace <namespace> deploy/<release>-controller -- \
cat /narwhal-state/runs/<namespace>/$uid/run.json
The logs stay where Kubernetes keeps them:
| Process | Log |
|---|---|
| Controller | kubectl logs deploy/<release>-controller. The log holds each pass that runs a stage, from its start to its outcome. It also holds each pass whose outcome differs from the last one logged. A pass that finds the fleet as the last line said logs nothing. Every 10 minutes, one line counts those passes |
| Gate Job | kubectl logs job/<job>, while the Job exists. The run record names each attempt's Jobs under jobs, and kubectl get jobs -l narwhal-inference.com/gate=<kind> lists them by kind |
| Engine pod | kubectl logs engine-<n> -c engine. The init containers checkpoint and runtime-check check the checkpoint and the runtime first |
| Attestation sidecar | kubectl logs engine-<n> -c attestation |
| Router | kubectl logs router-0 -c router. The request journal is /narwhal-router/journal.jsonl on the router's own volume. The volume lasts only as long as the pod unless spec.routers.storageClassName is set |
| HAProxy | kubectl logs deploy/haproxy |
The controller deletes an attempt's Jobs once the attempt passes. A failed attempt's Jobs stay, so kubectl logs job/<job> reads them, until the next attempt of the stage starts or the fleet stops. The attempt directory keeps every Job's log either way. Add --previous to read the log of a container the kubelet restarted.
Recovery¶
A failed or timed-out stage leaves the fleet Stalled with reason StageFailed. The stall lasts until the next edit of the fleet's spec or a new value of its narwhal-inference.com/requested-at annotation. A live change, such as a replaced engine pod, does not clear the stall. Fix the cause, then ask for the stage again:
kubectl annotate narwhalfleet fleet --namespace <namespace> --overwrite \
narwhal-inference.com/requested-at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
The next pass resumes at the failed stage, in a new attempt. A fleet that Helm or a GitOps tool owns can carry the annotation in its manifest. Any new value counts.
An edit takes effect at once when it changes an input whose rerun rule names the stage that runs. The controller cancels that stage, deletes its Jobs, records the attempt cancelled, and starts a new pass from the edited spec. Any other edit waits for the running stage instance to end. Rerunning after a change lists what each input reruns.
discover runs one Job on each engine node. Each Job takes every GPU of its node. After discover builds every Job, it deletes the engine StatefulSet. It waits for the engine pods to go, as engine-inspect stops the engines on SSH hosts. It first checks that every engine node is Ready, and stops nothing while one is not, as Node loss describes. The fleet serves nothing from the moment discover stops the engines until router-start passes again.
If discover fails after it stopped the engines, they stay stopped. The fleet is down until the next edit of its spec or a new requested-at value gets a pass past discover. Ready is then False with reason EnginesStopped, status.serving is false, and the Stalled message ends engines stopped for discovery; the fleet is not serving. A discovery Job may not finish in time, as when its image does not pull, or someone may delete it. The controller then starts the stage's Jobs again, up to three times within the stage's spec.timeouts limit. A check that rejects the node fails the stage at once.
spec.stopped: true stops the fleet. The controller cancels a running stage. It then deletes the routers, HAProxy, the engines and the Jobs, in that order, waits for their pods to go, and sets Stopped. STAGE then reads stopped, and the Stopped condition's message names the stage the last pass reached. The state volume, the router claims of a fleet that sets spec.routers.storageClassName, and the run directory stay. Setting spec.stopped back to false starts a pass from the run record. The pass applies the engines and the routers again and reruns the stages whose live checks fail.
The fleet has no finalizer. Deleting it leaves the removal of everything it owns to the garbage collector, which deletes in no order. Nothing waits on the controller, so no fleet is stuck terminating. These objects have no owner and stay:
- the state claim, which the chart keeps, with every run directory
- with
spec.routers.storageClassName, the router claimsrouter-state-router-0androuter-state-router-1, with the routers' journals and handoff state - the routers' Lease
narwhal-router, which the chart keeps, and the controller's Leasecontroller.narwhal-inference.com - the admission policy
<namespace>-narwhaland its binding, whichhelm uninstallkeeps - the CRD, which Helm never deletes
A fleet made again under the name starts a new run directory. It finds the routers' handoff state on any router claims, and finds the old router Lease, which expires because nobody renews it. To start the pair cold, delete the router claims and the Lease by hand. Then run helm upgrade on the release, which makes the Lease again. The routers may only get and update their Lease, not create it, so neither router can hold it until the upgrade makes it.
If the fleet is gone for good after helm uninstall, delete the state claim or the whole namespace. Once the namespace runs no fleet, delete the namespace. That deletes the claims, the Leases and the Secrets. Then delete the cluster-wide admission policy and its binding:
kubectl delete namespace <namespace>
kubectl delete validatingadmissionpolicybinding <namespace>-narwhal
kubectl delete validatingadmissionpolicy <namespace>-narwhal
A restarted controller adopts what its predecessor left running. The Deployment uses strategy: Recreate, and only the holder of the controller Lease acts. The next holder records the running attempt interrupted, finds its Jobs by those names, and waits for them instead of starting them again. An interrupted attempt therefore never stalls the fleet.
A Job that someone replaced with a copy of its name fails its stage with a message that names it and its uid, and its log is never read as evidence. The next attempt deletes it. A Job that finished with no pod left to read, as when someone deleted its pod, holds no outcome. Its attempt does not resume. The next pass deletes the Job and starts a new attempt in a new work directory. A resumed attempt that runs a Job again first deletes the outputs that an earlier pod of the same attempt left in its work directory. The controller Lease lasts 15 seconds. The holder renews it every 2 seconds and stops acting 10 seconds after its last renewal. A controller that loses the Lease, or receives SIGTERM, exits at once and touches no Job. The holder renews the Lease only while its pass shows progress. A pass that shows none for 10 minutes, such as one that hangs on a state volume that stopped answering, stops the renewals, and the controller exits 10 seconds after the last one. Its log says so first. The kubelet starts the container again, and the next holder adopts the Jobs. When the controller's node is lost, the replacement pod starts only once the old pod is force-deleted or the node is tainted node.kubernetes.io/out-of-service.
Engine restarts¶
The kubelet restarts a failed engine container in its pod. The pod's attestation sidecar stops once the engine process it serves ends. When the kubelet restarts the sidecar, it captures the new engine container's attestation before it serves, as Engine restart and process replacement describes. The router finds the new process and readmits the engine itself.
On every pass, the controller reads each engine pod's UID and its engine and sidecar containers' IDs, image IDs and starts. It reconciles every 60 seconds. A restarted engine container reruns engine-check, cache-capture or transfer-measure, attest-capture, sidecar-start and sidecar-verify for that engine. It then reruns finalize-fleet, preflight and router-start. router-start readmits the engine to a router pair that still runs, instead of restarting the pair. A restarted sidecar reruns sidecar-start, sidecar-verify and finalize-fleet.
The engine StatefulSet uses updateStrategy: OnDelete, so a changed pod template replaces no running pod. A deleted engine pod comes back held at the narwhal-inference.com/placement scheduling gate. The next pass's engine-start pins it to the node discovery measured. A stalled fleet runs no pass, so a pod replaced while the fleet is stalled waits at the gate until the stall clears.
Draining and readmitting engines¶
narwhal fleet --target kubernetes drains, readmits and resets engines at the router that holds the lease. It also reports the fleet against the fleet file that the fleet-limits stage wrote. The workstation sets the fleet's narwhal-inference.com/fleet-request annotation. The controller runs the request in a router-check Job and answers in status.fleetRequests. The workstation therefore needs no route to the routers and no Role beyond the fleet editor's:
narwhal fleet drain n2 --target kubernetes --namespace <namespace> --deadline 120
narwhal fleet status --target kubernetes --namespace <namespace>
narwhal fleet readmit n2 --target kubernetes --namespace <namespace>
The drain asks for no restart, so the engine pod keeps running. readmit returns it once the router's readmission checks pass.
The controller appends each drain, readmit and reset to fleet/actions.jsonl in the fleet's run directory. narwhal fleet gives the options and exit codes.
Node loss¶
When a node stops answering, Kubernetes marks it NotReady once the controller manager's --node-monitor-grace-period passes, and taints it so that its pods leave it. What happens next depends on the pod.
The router on the lost node stops renewing the router Lease. The other router takes the Lease within the takeover window, whether or not Kubernetes has noticed the node. The lost router's pod stays Terminating once Kubernetes evicts it, because a StatefulSet makes no new pod while the old one may still run. A node that returns before then finds its router fenced. Its /health answers HTTP 503, so the pod is not Ready. Once the router reads the Lease again, it exits with status 3, and the kubelet starts it as the standby, with one more container restart.
HAProxy runs one pod for each node the engines run on, up to two, unless spec.haproxy.replicas sets a count. Its pods spread over nodes as the routers do. Clients see a node loss for longer than the router takeover. Until Kubernetes marks the node NotReady, the Service sends new connections to the HAProxy pod there, and each of them times out at the client. Two settings set this window:
- The kubelet renews its node's Lease in
kube-node-leaseevery quarter of itsnodeLeaseDurationSeconds, 40 seconds by default, so every 10 seconds. - The controller manager's node lifecycle controller checks every
--node-monitor-period, 5 seconds by default. It marks a nodeNotReadyonce its Lease and status have not changed for--node-monitor-grace-period. That is 50 seconds by default in Kubernetes 1.32 and later, and 40 seconds in earlier versions.
A shorter --node-monitor-grace-period shortens the window. It also marks a node lost after a shorter pause, such as a slow kubelet. The pod leaves a lost node 30 seconds after the taint instead of the default 300, so its replacement starts on a live node sooner. The replacement stays there when the node returns, because the spread applies only when a pod is scheduled. To spread HAProxy again, delete one of the pods on the node that holds both, with kubectl delete pod --namespace <namespace> <pod>. The other pod keeps serving, and the scheduler places the replacement on the returned node. The admission policy refuses kubectl rollout restart of the controller's HAProxy Deployment. The chart's PodDisruptionBudget, haproxy.disruptionBudget, lets a drain take one HAProxy pod at a time.
An engine pod is pinned to its node, so nothing replaces it. It stays Terminating until the node returns, and its engine serves again then. The fleet's EngineNodesReady condition turns False with reason NodeNotReady at the next reconcile, at most a minute later. The message names the node, its engines and the engines left on Ready nodes:
node gpu-b is Ready Unknown since 2026-11-27T11:00:00Z, with engine-2 (decode). 1 of 2 engines are on Ready nodes (in the roles the fleet file starts them in: decode 0 of 1, prefill 1 of 1), and the routers serve while 2 remain, one prefill and one decode. ...
The controller also puts each engine node's readiness in the deployment status. Both routers export it as narwhal_deployment_engine_node_ready. NarwhalEngineNodeNotReady pages once a router reports the node for a minute.
While an engine node is not Ready, the fleet is not Ready either, even when every stage passed. Ready is False and Reconciling is True, both with reason EngineNodeNotReady and the EngineNodesReady message, and ENGINES counts only the engines on Ready nodes. status.serving stays true while the routers serve on the engines left. The controller keeps reconciling every 60 seconds and runs nothing on the lost node. It does not observe the fabric routes to the node. A gate Job or engine start pinned there ends at once as an interrupted attempt, instead of waiting out its time limit. The next pass retries it. Once the node is Ready again, the next pass observes its routes and the fleet turns Ready. The exception is when the routers hold its engines out of placement, as Held engines describes.
A rerun of discover, such as after helm upgrade or an edit of an engines field, waits for a lost node. discover would stop the engines on every node and could not inspect the lost one, so it stops none. The attempt ends interrupted. Reconciling has reason Retrying with a message that starts discover cannot run: node gpu-b is Ready Unknown. The engines on the other nodes keep serving on the release they run. The next pass after the node returns runs discover and every stage after it.
A node that will not return has to leave the fleet before discover can run. Once its Node object is deleted, the first discover, engine-start or gate Job that finds the node gone records that the node inventory is stale, and the next pass runs access again. A fleet that names no nodes then takes the Ready GPU nodes the cluster has, as Choosing the engine nodes describes. It lays its engines out on them. With spec.engines.nodeCount, access fails when fewer nodes are left than it asks for. A fleet that names its nodes in spec.engines.nodes stalls at access with the cluster has no node gpu-b for engine-2. Edit the fleet to take the node's engines out. Make that edit after the Node object is deleted. discover also waits while a node that is not Ready still holds one of the fleet's engine pods, because it could not delete the pod. In each case the engines that run keep serving until discover stops them.
The fleet keeps serving through the loss of one node only while the other nodes hold at least two engines. The routers need one prefill and one decode engine. The layout discover derives places enough engines on each node for that, where every node has a GPU for each of them.
Discovery spreads the roles the fleet file starts the engines in. With four engines or more on two nodes or more, it starts two prefill engines. These are the first engine of each of the two nodes that hold the most engines. It starts every other engine as decode. Each role then starts on two nodes, and one node's loss leaves an engine of each. A smaller fleet starts its first engine as prefill and the rest as decode, so some node holds every engine of one role. When that node is lost, engine monitoring refills the empty role. An engine backend with fixed roles cannot move an engine, so a role that starts on one node does not survive that node there. narwhal deploy plan --target kubernetes prints a note for each node whose loss would leave fewer than two engines. It also prints a note for each node whose loss would leave no engine that starts in some role. The EngineNodesReady message says the same while every node is Ready.
The controller never force-deletes a pod on a lost node. A node that stops answering may still run its pods, cut off from the API server. A second router or engine with the same identity would then run beside the first. Once you know the node is off, tell Kubernetes: taint it node.kubernetes.io/out-of-service=nodeshutdown:NoExecute, or delete its Node object. Kubernetes then deletes its pods and detaches their volumes, and the router StatefulSet starts the lost router on another node. Remove the taint once the node is back.
Held engines¶
The routers eject a lost node's engines, and readmit each once it answers again and its recovery checks pass. A check can fail while the node's network comes back, such as a fabric check whose decode leg gets no first token. The router then holds the engine blocked. It runs the engine's recovery again 5, 10, 20 and 40 seconds later, then every 60 seconds, as Readmission and drains describes.
The controller reads the engines the Lease holder keeps out of placement from the Lease's narwhal-inference.com/held-engines annotation at each pass. While the routers hold an engine out on a Ready node, ENGINES leaves it out. Ready is False with reason EnginesHeld, whose message names each held engine and why:
the routers hold n2, n4 out of placement: n2 blocked: fabric n2->n1: EngineError: decode leg against http://engine-1.engines.<namespace>.svc:8001 failed (504): no first token within 1.48911s: no frames at all; n4 blocked: ...
An engine drained with narwhal fleet drain counts as held too, until it is readmitted. narwhal fleet status exits 3 while an engine differs from the fleet file. It also exits 3 while the other router of the pair cannot take over, such as one fenced after its node returned.
Router volumes¶
Each router keeps its request journal and handoff state at /narwhal-router. By default that is an emptyDir on the router's node, limited to spec.routers.size, or 1Gi without it. The kubelet evicts a router whose volume outgrows the limit, and the other router takes over. The volume lasts as long as the pod. A container restart keeps it. A new pod starts with an empty one, and its router starts as the standby of the other. A standby takes over with the handoff the primary serves it over HTTP, so an emptyDir loses no takeover.
With spec.routers.storageClassName, each router gets a ReadWriteOnce claim of spec.routers.size, which keeps the journal across pods. Do not back it with an NFS share mounted hard, the default: a router whose node loses the server waits for it for ever, and only a reboot of the host clears it. Use node-local or block storage, or give the storage class soft mount options as Storage on a lost node describes. A write cut off this way is lost. The journal can miss lines or end in a torn one, and a handoff write can fail. The router logs the failure and retries on its next monitoring pass.
Storage on a lost node¶
A pod that mounts an NFS share can keep its node from shutting down once the node loses the server. As the pod's last process exits, the kernel unmounts the share and waits for the server's replies. With the default hard mount, that wait lasts minutes or longer.
No engine, router or HAProxy pod mounts a network volume. Each router reads the fleet file that fleet-limits wrote, with profiles.json and first-token-calibration.json beside it. The files are in an emptyDir mounted read-only at the path the files have on the state volume. The controller writes the files at router-start into immutable ConfigMaps router-fleet-<digest>-<n>, which one projected volume mounts. It gzip-compresses the files and splits them into parts of at most 1000 KiB. The router pod's unpack init container joins and decompresses each file. It checks the file against the SHA-256 that the pod template pins, and writes it to the emptyDir. Sixteen ConfigMaps hold about 45 engines' calibration at three prompt lengths. A fleet whose files need more fails router-start with the number they would take. A new fleet file gets new ConfigMaps, which roll the router pods, and each router-start deletes the earlier ones that no router pod mounts.
These long-running pods keep a ReadWriteMany claim:
- The engine pods mount the model volume read-only, and no other claim.
- The controller keeps every run directory on the state volume. Its export Jobs and gate Jobs read and write there. Mount the state class
soft. Keep the controller off the engine nodes, such as withcontroller.nodeSelector, so a lost NFS server can hang at most a node that runs no engine. - Direct engines share
narwhal-engine-sharedfor the slot files of their KV handoff.
On NFS, give the storage class of these claims mountOptions such as soft, timeo=100 and retrans=3. A call to a server that stopped answering then fails with an I/O error after its retransmissions. Each waits timeo tenths of a second longer than the last, as nfs(5) describes. The unmount then ends and the node shuts down. Node-local or block storage needs neither option. An inline nfs model volume takes no mount options, so serve the model from a claim of such a class instead.
The gate Jobs mount the state volume too, and model-fetch writes the model volume. A Job that was running on the node when it was lost still holds the mount. A hard mount can therefore hang that node's shutdown the same way. The chart's Prometheus and Grafana keep their data on ReadWriteOnce claims of monitoring.prometheus.storage and monitoring.grafana.storage, or an emptyDir without them, and mount nothing shared.
Monitoring¶
The chart's monitoring runs in one of two modes. Monitoring in the chart's README lists every value.
- The chart's own Prometheus and Grafana, the default. The chart runs both from the files
make observeuses. Prometheus scrapes both routers, the engines that/narwhal/targetslists through HAProxy and each engine pod's attestation sidecar, with the alert rules ofmake observe. The controller lists the sidecars oncediscoverhas derived the engines, in the ConfigMapsidecar-targetsthat Prometheus mounts. - The cluster's Prometheus Operator and Grafana, such as kube-prometheus-stack. With
monitoring.serviceMonitors.enabledandmonitoring.dashboardConfigMap.enabled, the chart runs neither. It rendersServiceMonitor,PodMonitorandScrapeConfigobjects that scrape the same targets with the same labels and interval. It renders the alert rules as aPrometheusRule, and the dashboard as a ConfigMap for the Grafana dashboard sidecar. Put the labels the cluster's Prometheus selects by inmonitoring.serviceMonitors.labels, and admit its namespace to the routers innetworkPolicy.monitoring. ThePodMonitorscrapes each sidecar at the port the controller sets in its engine pod'snarwhal-inference.com/attestation-portannotation as it pins the pod to its node.
Tested with kube-prometheus-stack 94.2.2 (Prometheus Operator v0.95.2, Prometheus v3.16.0, Grafana 13.3.2), installed with:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install kps prometheus-community/kube-prometheus-stack --version 94.2.2 \
--namespace monitoring --create-namespace
Its defaults select monitors labelled release: kps in every namespace, and its dashboard sidecar searches every namespace. Set monitoring.serviceMonitors.labels.release=kps, and admit its namespace to the routers with --set-json 'networkPolicy.monitoring=[{"namespaceSelector":{"matchLabels":{"kubernetes.io/metadata.name":"monitoring"}}}]'.
Expect kube-prometheus-stack's own PrometheusSDRefreshFailure warning for the <release>-engines ScrapeConfig while no router serves. That ScrapeConfig discovers the engines from /narwhal/targets through HAProxy, which router-start creates and spec.stopped deletes, so until then each refresh fails with no such host. It clears about 10 minutes after HAProxy answers.
Both modes serve the dashboard the chart holds, rendered for every engine backend when the chart was packaged.
Reach the chart's Grafana and Prometheus, and the fleet through HAProxy, with kubectl port-forward, each in its own terminal. The workstation identity of narwhal deploy cannot port-forward. narwhal deploy gives a Role that can.
kubectl port-forward --address 127.0.0.1 --namespace <namespace> svc/grafana 13000:3000
kubectl port-forward --address 127.0.0.1 --namespace <namespace> svc/prometheus 19090:9090
kubectl port-forward --address 127.0.0.1 --namespace <namespace> svc/haproxy 18000:8000
Without --address 127.0.0.1, kubectl port-forward on a local port another process holds may bind only [::1] and print only that line. http://127.0.0.1:<port> then reaches the other process. With it, the forward fails instead.
Then open http://127.0.0.1:13000/d/narwhal-router/narwhal-orchestrator and sign in with the login in the Secret grafana-admin, or the one monitoring.grafana.admin names, unless monitoring.grafana.anonymous is set. Prometheus is at http://127.0.0.1:19090, and clients reach the serving routes at http://127.0.0.1:18000. HAProxy forwards only POST /v1/completions, POST /v1/chat/completions, GET /v1/models, GET /health, GET /ready and GET /narwhal/targets. Every series carries the fleet label, the release name unless monitoring.fleet sets another.
The dashboard's Supervisor restarts panel shows the kubelet restart counts of each engine pod's containers, which the sidecars export. After each pass, passed or not, the controller writes the run's deployment status to the ConfigMap deployment-status. Both routers mount and export it, so the Deployment row shows each stage, the fabric margins and the attestation generations of the last pass. The row stays empty until router-start first passes, because no router exports the status before then. Read kubectl describe narwhalfleet fleet instead.
Cluster health stays with the cluster's own monitoring. Narwhal's Prometheus scrapes only the routers and the engines, so it holds no node GPU health, no PersistentVolumeClaim usage and no Job outcomes. Watch those through the cluster's GPU exporter, the kubelet's volume statistics and kube-state-metrics, and alert on them there. With the chart's own Prometheus, set monitoring.alertmanagerUrl to deliver the fleet's alerts to your Alertmanager. With the cluster's Prometheus, the cluster's Prometheus sends the PrometheusRule's alerts to the Alertmanager its own configuration names. The chart refuses monitoring.alertmanagerUrl in that mode.
The chart's Prometheus avoids the routers' nodes where another node can take it. monitoring.prometheus.nodeSelector, tolerations and affinity place it elsewhere. An affinity replaces that default. Without monitoring.prometheus.storage, its samples last as long as its pod. A new pod starts with none, whether it moves to another node or an upgrade changes its configuration, such as monitoring.alertmanagerUrl.
Serving through a Gateway¶
Without a gateway, clients reach the fleet through the Service haproxy. If the cluster runs a Gateway API Gateway, gateway.mode attaches the fleet to it in one of two ways:
httpRoute: anHTTPRoutesends requests to the Servicehaproxy. HAProxy forwards them to the router in rotation, and holds a request for up to 10 seconds while the routers take over.inferencePool: the router pods form anInferencePoolof the Gateway API Inference Extension. The chart's endpoint picker sends each request straight to the router that holds the router Lease.
Both modes attach the same HTTPRoute, named after the release, to the Gateways in gateway.parentRefs. Its matches are POST /v1/completions, POST /v1/chat/completions, GET /v1/models, GET /health and GET /ready, each by method and exact path. These are the routes HAProxy forwards, less GET /narwhal/targets, which HAProxy forwards because the chart's Prometheus reads it there. The chart reads them from src/narwhal/deployment/serving-routes.json, the file HAProxy's route filter is rendered from, so the two cannot drift. Any other request, such as GET /narwhal/targets, GET /narwhal/state, POST /narwhal/engines or GET /metrics, matches no rule and gets 404 from the Gateway. The Gateway still owns TLS, client authentication and rate limits, as an ingress in front of HAProxy does.
Tested with Istio 1.32.0 as the Gateway implementation, on the Gateway API v1.7.0 standard-channel CRDs and the inference.networking.k8s.io/v1 InferencePool CRD of Inference Extension v1.6.2. make chart-e2e installs all three on kind and serves completions through each mode.
Attaching an HTTPRoute¶
Install the Gateway API CRDs and a Gateway implementation, then create a Gateway whose listener admits routes from the fleet's namespace. With Istio:
kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.7.0/standard-install.yaml
istioctl install -y --set profile=minimal
kubectl create namespace gateway
kubectl apply -f - <<'YAML'
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: inference
namespace: gateway
spec:
gatewayClassName: istio
listeners:
- name: http
port: 80
protocol: HTTP
allowedRoutes:
namespaces:
from: All
YAML
Then point the release at it:
kubectl get httproute narwhal --namespace <namespace> shows the route Accepted once the Gateway has taken it. gateway.hostnames limits it to some hostnames of the listener.
Istio serves the Gateway through a Service of type LoadBalancer. On a cluster without a load balancer, no external address arrives, so the Gateway stays Programmed=False with reason AddressNotAssigned. The Service's ClusterIP still serves the routes. kubectl get service --namespace gateway shows it. To have Istio make a ClusterIP Service instead, annotate the Gateway with networking.istio.io/service-type: ClusterIP.
Registering an InferencePool¶
With gateway.mode: inferencePool, the chart also renders the InferencePool <release>, which selects the two router pods on port 8000. It also renders the endpoint picker <release>-endpoint-picker, which the pool's endpointPickerRef names. The HTTPRoute's backend is the pool. Install the InferencePool CRD as well, and turn the Inference Extension on in the Gateway implementation:
kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api-inference-extension/releases/download/v1.6.2/v1-manifests.yaml
istioctl install -y --set profile=minimal \
--set values.pilot.env.ENABLE_GATEWAY_API_INFERENCE_EXTENSION=true \
--set meshConfig.defaultHttpRetryPolicy.attempts=0
gateway:
mode: inferencePool
parentRefs:
- name: inference
namespace: gateway
peers:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: gateway
podSelector:
matchLabels:
gateway.networking.k8s.io/gateway-name: inference
gateway.peers selects the Gateway's pods. The routers' NetworkPolicy admits them to port 8000. The picker's NetworkPolicy admits only them to its gRPC port. The chart refuses inferencePool without peers while networkPolicy.enabled is set.
The Gateway asks the picker about each request over the Envoy ext_proc gRPC stream the endpoint picker protocol defines, on port 9002. The picker answers with the Lease holder's ip:port in the x-gateway-destination-endpoint header and in the envoy.lb dynamic metadata, and passes the bodies back unchanged. It picks the holder only while:
- the Lease
narwhal-routernames it, and the picker saw the Lease renewed within itsleaseDurationSecondslessgateway.endpointPicker.leaseSafetyMarginand half a second. That is 3.5 seconds with the defaults. The controller refuses a fleet whose routers'--lease-safety-margininspec.routers.argsexceeds the picker's. - the holder's pod is Ready and is not being deleted. It runs the same router container as when the picker first saw it hold the Lease. A router container that restarts comes back as the other router's standby while the Lease still names its pod.
Otherwise it holds the request, looking again every 50 ms, for up to gateway.endpointPicker.holdSeconds, 10 seconds by default, the window HAProxy holds a request for. A request that still finds no ready holder gets a 503 that carries retry-after: 1. The 503 has a JSON error whose code is no_router and whose reason says why. When the active router's pod is deleted, the picker stops picking it at once and holds the requests that arrive meanwhile. It sends them to the other router as soon as that router takes the Lease, inside the takeover window. The Gateway must wait that long for the picker's answer: Istio's ext_proc message timeout is 1000 seconds. The picker sees the Lease and the pods, not the router's own readiness. A new holder that has the Lease but has not finished taking over therefore answers a request itself, with its not_ready 503 and retry-after: 1. HAProxy would hold the request until /ready passes.
Turn off the Gateway's retries for this route, as meshConfig.defaultHttpRetryPolicy.attempts=0 does for Istio. Istio sends a retry, and any request whose picked endpoint has left the pool, to another pod of the pool, which may be the standby. The pool's failureMode is FailClose for the same reason. While the Gateway cannot reach the picker, it answers with an error instead of choosing a router itself.
The picker runs python -m narwhal.gateway.cli from images.narwhal. That needs the image built from the repository's Dockerfile. Two replicas run by default, gateway.endpointPicker.replicas, and each reads the Lease and the pods itself. Its gRPC health service answers readiness once it has read the Lease and both router pods, and liveness while it runs. It serves Prometheus metrics on port 9090 at /metrics:
| Metric | Meaning |
|---|---|
narwhal_endpoint_picker_picks_total{router} |
Requests sent to the Lease holder, by router pod |
narwhal_endpoint_picker_no_router_total{reason} |
Requests answered with 503: no_lease, released, lease_unconfirmed, lease_stale, holder_unknown, holder_not_ready, holder_restarted or holder_outside_subset |
narwhal_endpoint_picker_lease_changes_total |
Changes of the Lease's holder or epoch the picker saw |
narwhal_endpoint_picker_held_total |
Requests the picker held while no ready router held the Lease. They then went to a router or got the 503 |
narwhal_endpoint_picker_synced |
1 once the picker has read the Lease and both router pods |
With monitoring.serviceMonitors.enabled, the PodMonitor <release>-endpoint-picker has the cluster's Prometheus scrape each picker pod under the job endpoint-picker, with the fleet label. Admit the Prometheus namespace in networkPolicy.monitoring, which the picker's NetworkPolicy admits to the metrics port. The chart's own Prometheus runs the configuration of make observe and does not scrape the picker.
Routing by model name across pools¶
One Gateway can front a Narwhal fleet and other inference pools, and choose by the model a request names. The model is in the JSON body, which HTTPRoute matches cannot read. A body-based router in front of the routes has to copy it into the X-Gateway-Model-Name header. gateway.headers adds a header match to every route of the fleet:
gateway:
mode: inferencePool
parentRefs:
- name: inference
namespace: gateway
headers:
- name: X-Gateway-Model-Name
value: <served model>
Other pools attach their own routes to the same Gateway, each matching its own model:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: other-model
namespace: <other namespace>
spec:
parentRefs:
- name: inference
namespace: gateway
rules:
- matches:
- path:
type: Exact
value: /v1/chat/completions
method: POST
headers:
- name: X-Gateway-Model-Name
value: <other model>
backendRefs:
- group: inference.networking.k8s.io
kind: InferencePool
name: <other pool>
A request for the Narwhal model reaches the fleet's pool. A request for the other model reaches the other pool. A request that names neither gets 404. With gateway.headers, every route of the fleet needs the header. That includes GET /v1/models and GET /health, which carry no body. Reach those through the Service haproxy or a route without the header. make chart-e2e runs no body-based router, so this example is not part of the tested setup.
Security and access¶
The controller runs as the ServiceAccount <release>-controller. Its Role in the namespace grants:
| Resources | Verbs |
|---|---|
narwhalfleets and narwhalfleets/status |
get, list and watch on the first, patch on the second |
jobs |
get, list, watch, create, delete |
pods and pods/log |
get, list, watch, patch and delete on pods, get on pods/log |
configmaps, services, statefulsets, deployments |
get, list, watch, create, patch, delete |
leases |
create on any Lease. Get and update on controller.narwhal-inference.com only. Get on the routers' narwhal-router only |
A second Role, <release>-controller-secrets, grants create on secrets, which RBAC cannot limit to a name. It grants get on narwhal-router-token and narwhal-engine-key only, the Secrets the controller generates. The Secret admission policy <namespace>-narwhal-secrets lets the controller's ServiceAccount create only these Secrets, each Opaque and immutable. They are the two fleet Secrets, owned by a NarwhalFleet. With the chart's Grafana and no monitoring.grafana.admin, the policy also allows Grafana's admin login, owned by the Deployment grafana. The ClusterRole <namespace>-<release>-narwhal-secret-policy lets it get that policy and its binding by name. The controller lists, watches, updates and deletes no Secret, and never reads Grafana's.
Its ClusterRole <namespace>-<release>-narwhal-nodes grants get and list on nodes, for discovery. It also grants get by name on the CRD narwhalfleets.narwhal-inference.com and on the namespace's admission policy and its binding. It has no verb on RBAC objects or pods/exec. The pod mounts no ServiceAccount token. The controller container alone mounts a projected token that lasts an hour. It runs as a non-root user, 10001 by default, on a read-only root filesystem, with no capabilities and the RuntimeDefault seccomp profile.
Whoever writes the fleet needs the Role <release>-fleet-editor. The chart creates it without binding it. It grants get, list, watch, create, update, patch and delete on narwhalfleets, and get on narwhalfleets/status. Kubernetes' edit and admin roles do not include it. Bind it to each person or tool that writes the fleet:
kubectl create rolebinding fleet-editors --namespace <namespace> \
--role <release>-fleet-editor --group <group>
The workstation that runs narwhal deploy --target kubernetes needs two Roles. One is the fleet-editor Role, of which it uses get, create, patch and delete. The other is narwhal-workstation-pods, with get on pods and pods/log. It reads the engine, sidecar and router pods for the live checks of plan and status. It also reads the log of each export Job's pod that the controller names. The controller creates those Jobs when the workstation sets the fleet's narwhal-inference.com/export-request annotation. To give the workstation a ServiceAccount identity, bind both Roles to the account. Then write a kubeconfig with the token from kubectl create token <account> --namespace <namespace> --duration 8h. narwhal deploy gives both Roles and the commands. The identity cannot kubectl port-forward. That page gives a separate Role for the forwards.
The routers run as the ServiceAccount narwhal-router. Its Role grants get and update on the Lease narwhal-router and nothing else. The chart makes that Lease, so the routers need no create verb. Only the router container mounts the token, a projected token that lasts an hour. The routers run as UID 10001 on a read-only root filesystem with no capabilities and the RuntimeDefault seccomp profile.
The endpoint picker, with gateway.mode: inferencePool, runs as the ServiceAccount <release>-endpoint-picker. Its Role grants get and watch on the Lease narwhal-router and on the pods router-0 and router-1, by name, and nothing else. Only the picker container mounts the token, a projected token that lasts an hour. It runs as UID 10001 on a read-only root filesystem with no capabilities, and holds neither the engine key nor the routers' control token.
The engines' ServiceAccount <release>-engine may get the namespace's pods and nothing else. The attestation sidecars and the sidecar-verify Jobs run as it, to bind each engine process to its pod. No other gate Job mounts a token.
Write access to a NarwhalFleet is close to write access to the namespace's nodes. Whoever writes the fleet chooses the engine image, and that image receives the engine API key. The controller starts the engine image in host-network engine pods with IPC_LOCK on the nodes the fleet names. It starts the fleet's spec.images.host, when the fleet names one in place of the chart's, in host-network Jobs. It hands the engines and routers the Secrets that apiKeySecret and controlTokenSecret name. That amounts to read access to every Secret in the namespace.
The namespace's admission policy bounds the rest:
- Only the controller's engine StatefulSet and its fabric and
transfer-measureJobs may use the host network or addIPC_LOCK. No pod is privileged, and every image is named by digest. - The model volume follows the admin's allow-lists, which must keep it off the state claim's storage.
- Only an engine pod that requests an
amd.comGPU may run without a seccomp filter. - Only the controller's Deployment and the ReplicaSets and pods made for it run as the controller's ServiceAccount. The policy takes a Deployment of that name as the controller's only from someone who may update the policy, as the chart's installer may.
- Only the router StatefulSet the controller applies and its pods run as the routers' ServiceAccount, whose token renews the router Lease.
- Only the controller's workloads and its Deployment mount the state claim, and of those only the controller's own pods mount its root.
The chart's README lists every rule.
What the chart cannot close:
- Kubernetes'
editandadminroles may impersonate the namespace's ServiceAccounts, request their tokens and exec into pods. Anyone withedit,admin,impersonateorpods/execin the fleet's namespace therefore has the controller's power. That includes reading the state claim and starting host-network engine pods withIPC_LOCK. Keep them to the people who install the chart, and give the people who run fleets only the fleet-editor Role. - The admission policy allows Secret volumes. Anyone who can create pods or Jobs in the namespace can therefore mount its Secrets, the engine key's among them, as volumes. The workstation's role creates neither.
- Attestations carry no signature. The router trusts the attestation that an engine's attestation URL serves once it matches the engine's contract. A process that serves a copy of the attestation from that address therefore receives the engine key. Another host-network workload on the node can do this once the sidecar stops.
- Anyone who can create pods in the namespace can give a pod the label the routers' NetworkPolicy admits for the chart's Prometheus. With the cluster's Prometheus, admitted through
networkPolicy.monitoring, the NetworkPolicy leaves that label out. - With
gateway.mode: inferencePool, anyone who can create pods in the namespace can give a pod the endpoint picker's labels. The picker's Service then sends it a share of the Gateway'sext_procstreams. Such a pod sees each request's headers and can answer in the picker's place.
Run each fleet in a namespace of its own, which runs nothing else.
Reusing an earlier fleet's evidence¶
A fleet deleted and made again starts a new run directory, so it profiles and calibrates the engines again. Set spec.reuseFrom to the earlier fleet's UID, from status.previousRuns. The controller then copies profile and calibrate from that run directory instead, while every input they depend on matches:
narwhal deploy run --target kubernetes --reuse-from <uid> sets the field when it applies the fleet. It refuses a UID that differs from the one the file names. The controller compares the same digests and engine node fingerprints as on SSH hosts, which Reusing profiles and calibration lists. It leaves out the fleet's namespace and uid, which name the run. Discovery, the engine checks, fabric qualification, the attestations, preflight and the routers run again. Pruning keeps the run directory spec.reuseFrom names, and status.previousRuns lists it. When a digest differs, the stage runs and its condition names the mismatch, as in reuse of run <uid> blocked: binding[engine-1] differs. When that directory is gone, the pass logs a warning and runs both stages.
Rerunning after a change¶
| Stage | Runs | After | Reusable | Gate section |
|---|---|---|---|---|
access |
Once per run, for the whole fleet | No | Checking cluster access | |
model |
Once per run, for the whole fleet, on runs with a model source | access |
No | Fetching the checkpoint into the model volume |
discover |
Once per run, for the whole fleet | access, model |
No | Discovering the engine nodes |
engine-prepare |
Once for each engine pod | discover |
No | Preparing the engine pods |
install |
Once per run, for the whole fleet | engine-prepare |
No | Applying the engines |
engine-start |
Once for each engine pod | install |
No | Starting the engine pods |
engine-check |
Once for each engine pod | engine-start |
No | Checking the engine pods |
cache-capture |
Once for each engine pod, on TensorRT-LLM or vLLM | engine-check |
No | Capturing the live cache layout |
transfer-measure |
Once for each engine pod, on SGLang | engine-check |
No | Measuring KV handoffs |
cache-groups |
Once per run, for the whole fleet | engine-check, cache-capture, transfer-measure |
No | Deriving cache-equivalence groups |
fabric-budget |
Once for each cache-equivalence group | cache-groups |
No | Building the source budget |
fabric-edge |
Once for each directed edge between the engines' nodes | fabric-budget |
No | Binding each sample to a directed route |
attest-capture |
Once for each engine pod | fabric-edge |
No | Reading the sidecar's attestation |
sidecar-start |
Once for each engine pod | attest-capture |
No | Checking the sidecar container |
sidecar-verify |
Once for each engine pod | sidecar-start |
No | Verifying the sidecar |
finalize-fleet |
Once per run, for the whole fleet | sidecar-verify |
No | Finalizing the fleet contract |
profile |
Once per run, for the whole fleet | finalize-fleet |
Yes | Profiling idle engines |
calibrate |
Once per run, for the whole fleet | profile |
Yes | Calibrating the first-token deadline |
fleet-limits |
Once per run, for the whole fleet | calibrate |
No | Reusing or repeating the calibration |
preflight |
Once per run, for the whole fleet | fleet-limits |
No | Running preflight |
router-start |
Once per run, for the whole fleet | preflight |
No | Starting the router pair |
| Change | Recorded as | Reruns |
|---|---|---|
| Namespace or fleet, such as a fleet deleted and made again, the nodes it may run on, or a node of the inventory that left the cluster | The fleet's namespace and uid, its engines.nodeCount, engines.nodeSelector and engines.tolerations, and the access attempt whose inventory discover found a node gone from. It names the run, so reuse from an earlier run leaves it out |
access and every stage after it |
| Engine node, model volume, image, checkpoint, launch policy or transport | The fleet's images other than haproxy, and its engines fields other than apiKeySecret and each node's rdma |
discover and every stage after it |
| Model source, revision or endpoint, or the checkpoint's digest | The fleet's engines.model.fetch fields other than tokenSecret, and engines.model.treeSha256 |
model on runs with a model source and every stage after it |
| Topology discover derived | Each engine's node, GPU IDs, ports, fabric interface, transport, HCA port, GID index and RoCE mode, and the source of each derived value | engine-prepare and every stage after it |
| Narwhal release | The SHA-256 of the installed package's Python files, which build every object | discover and every stage after it |
| Engine API key Secret, or the key in it | engines.apiKeySecret, and an HMAC of the key under the fleet's salt from a key-check Job, never the key itself |
engine-prepare, router-start |
| Router control token Secret, or the token in it | controlTokenSecret, and an HMAC of the token under the fleet's salt from a key-check Job, never the token itself |
router-start |
| SLO targets, router overhead, or the router's controller, serving and recovery settings | slo.ttft_s, slo.tpot_s, slo.router_overhead_s, and the controller, serving and recovery sections the fleet file sets |
fleet-limits, preflight, router-start |
| First-token deadline margin | The margin above the calibrated first-token candidate | fleet-limits, preflight, router-start |
| Profiling sweep or warmup | The prefill and decode sweep lengths, the decode concurrency and the warmup requests | profile, fleet-limits, preflight, router-start |
| First-token calibration inputs | The input tokens, samples and observation timeout | calibrate, fleet-limits, preflight, router-start |
| Fabric budget workload | The prompt tokens, handoffs per second, burst, transfer budget and headroom | transfer-measure on SGLang when the prompt tokens change, fabric-budget, fabric-edge |
| Fabric test settings | The test port, and each engine's RDMA GID index and RoCE mode | fabric-edge |
| Router settings | The fleet's routers, haproxy and images.haproxy |
router-start |
| Prepared engine pod | The SHA-256 of the launch directory's launch.json and kubernetes.json |
install; engine-start, engine-check for that engine |
| Engine pod replaced or its engine container restarted | The pod UID and node, and the engine container's ID, image ID and start, checked live on every run | engine-check, cache-capture on TensorRT-LLM or vLLM, transfer-measure on SGLang, attest-capture, sidecar-start, sidecar-verify for that engine; finalize-fleet, preflight, router-start to readmit the engine to a router pair that still runs |
| Engine cache geometry | The SHA-256 of cache-layout.json without plan_sha256, which names its launch directory's plan |
cache-groups; fabric-budget for the engine's cache group; fabric-edge for every edge leaving a node of the engine's group |
| Measured KV handoff size of an engine | The SHA-256 of the engine's transfer.json handoff measurement |
cache-groups; fabric-budget for the engine's cache group; fabric-edge for every edge leaving a node of the engine's group |
| Fabric route of a directed node edge | The link fingerprint: roles, addresses, interfaces, both live routes, transport, tool version and test parameters, checked live on every run | fabric-edge for that edge; calibrate, fleet-limits, preflight, router-start |
| Attested binding digest of an engine | The launch_digest, or the attestation_digest when the attestation has no launch evidence |
profile, calibrate, fleet-limits, preflight, router-start |
| Engine contract fields of an engine | The EngineContract fields of its attestation |
attest-capture for every engine; finalize-fleet, profile, calibrate, fleet-limits, preflight, router-start |
| Attestation sidecar container restarted | The sidecar container's ID, image ID and start, checked live on every run | sidecar-start, sidecar-verify for that engine; finalize-fleet |
| Router pod replaced or restarted | Each router pod's UID and its router container's ID and start, checked live on every run | router-start |
A Job runs once, within a time limit. spec.timeouts limits a whole stage attempt, from its start. On SSH hosts the same fields limit each command a stage runs, on a host or on the workstation, instead. Each Job of the stage gets the same limit, and so do the waits of engine-start, sidecar-start and router-start. An attempt past its limit ends timeout, and the fleet stalls as it does for a failed stage. A stage that spec.timeouts sets no limit for has no limit of its own. Each of its Jobs then runs within its kind's limit, such as two hours for profile. engine-start waits up to 30 minutes for each engine container to become ready, and router-start up to 10 minutes for the router pair. A Job's outputs come back in its log. The log holds each file gzip-compressed and base64-encoded on a narwhal-file-gz line. A manifest of their uncompressed SHA-256 values and sizes follows. A log whose files differ from the manifest fails the stage.
A fabric Job mounts only its own keep directory. It drops every capability but IPC_LOCK, which an RDMA sample needs, and may not gain more. The engine API key reaches only the key check and two groups of Jobs. The first group calls engines: transfer-measure, sidecar-verify, finalize-fleet, profile, calibrate and preflight. The second reads an engine pod's evidence from its sidecar: engine-check, cache-capture and attest-capture. The model token reaches only the model-fetch Job, which is also the one workload the admission policy lets mount the model volume read-write.
A Job or pod that cannot run fails its stage at once. Three cases apply:
- A container whose configuration the kubelet cannot build, such as one that names a missing Secret.
- A Job pod that the kubelet refuses at admission on its pinned node, such as
OutOf<resource>. - An engine or router pod that no node can schedule.
A router pod may wait up to five minutes for a node, as for a cluster autoscaler.
A pod that the cluster ends for its own reasons does not fail its stage. These are an eviction for node pressure, a graceful node shutdown and a preemption, which Kubernetes marks with the pod condition DisruptionTarget. The Job's pod failure policy ignores such a pod, and the Job starts another within its time limit. engine-start pins the replacement of an engine pod the cluster ended, and router-start waits for the StatefulSet to replace a router pod. A Job pod that the kubelet refuses while its node shuts down, with reason NodeShutdown, carries no such condition, so its Job fails. The attempt then ends interrupted, and the next pass runs it again.
A node that returns ends only then the fleet's pods that were deleted while it was lost, and until they go they hold its GPUs and HCAs. The kubelet may therefore refuse a new Job pinned there with OutOf<resource>. When an engine or gate pod of the fleet was being deleted on that node as the Job was made, or still is, the refusal does not fail the stage. The gate deletes its Job and waits for those pods to go, within the gate's and the stage's time limit. The attempt then ends interrupted, and the next pass runs the gate again. A refusal with no such pod is a shortage of the node's resources, and fails the stage at once.
Checking cluster access¶
access checks that the namespace holds the fleet the pass runs for, by uid. When spec.engines.nodes names the engines' nodes, it checks that each node exists and offers at least one GPU and one HCA under the fleet's resource names. It also checks that each carries no taint that keeps the engine pods off it, with the fleet's tolerations. It fails and names each missing node, resource or taint. Otherwise it takes the Ready, schedulable nodes that offer the GPU resource, as Choosing the engine nodes describes, and fails when there is none. access.json holds the namespace, the fleet, the GPU resource in gpu_resource and, under inventory, each of these nodes with its allocatable resources. discover derives the engine topology from this inventory.
Fetching the checkpoint into the model volume¶
model runs when spec.engines.model.fetch names a source, before discover. It runs one model-fetch Job. When the model volume is a hostPath, which each node holds apart, it runs one Job on each node of the inventory access recorded. The Job runs the controller's image as the controller's user. It mounts the model volume read-write at /model. When tokenSecret names one, it reads the token from that Secret as NARWHAL_MODEL_TOKEN. The controller never reads the token.
engines:
model:
name: <served model name>
treeSha256: <model_tree_sha256>
fetch:
source: s3://<bucket>/<prefix>
region: <region>
tokenSecret:
name: model-token
key: token
source is a hf://<owner>/<name> repository at the commit revision names by its full hash, or the objects under an s3://<bucket>/<prefix>. endpoint names a Hub mirror or an S3-compatible store other than AWS, by an https URL. An object storage token is <access key ID>:<secret access key>, with :<session token> after them for temporary credentials. A path source works on SSH hosts only.
The Job downloads into /model/.cache/huggingface/narwhal/, which the tree digest leaves out. It resumes each file a stopped Job left part way with a range request onto the same source version, as Fetching the checkpoint describes. Once the downloaded tree's digest equals treeSha256, the Job links each file into place and removes every file the tree lacks. A volume that refuses hard links gets copies, which the Job hashes again. The record of the staged tree, written last, is /model/.cache/huggingface/narwhal-staged.json. A Job that stops part way leaves a tree in place that fails the digest check, so no engine starts on it. The engine pods' checkpoint init container and discover both hash the tree. The Job fails and names the digest it found when the tree differs from treeSha256.
The stage runs again, with discover and every stage after it, when a fetch field other than tokenSecret or treeSha256 changes. A new token Secret reruns nothing. The engines may still run while the Job replaces their files. They keep the weights they loaded until discover stops them.
Discovering the engine nodes¶
discover first lays out the engines on the inventory access recorded, as Engine topology describes. It then checks that every engine node is in the cluster and Ready. It stops any engines that run, because their pods hold the GPUs it inspects, and runs one discovery Job on each engine node. With a node that is not Ready, it stops nothing and the attempt ends interrupted, for the pass after the node returns. With a node that is gone, it stops nothing either, and the next pass runs access again. The Job runs the engine image with every GPU the node offers and the model volume. For every engine of the node, it reads the GPU inventory, the image's packages and environment, and the model configuration, and hashes the checkpoint. discover fails an engine whose checkpoint tree differs from spec.engines.model.treeSha256. A fleet that sets none trusts the tree on first use. The first discover takes the tree every engine node holds. It fails when the nodes hold different trees. Once every check of discover passes, it pins the tree in the run directory, which status.model.treeSha256 reports. A discover that fails pins nothing, so the next one takes the tree the nodes hold then. Every later discover of the fleet then fails on another tree. A fleet made again under the name starts a new run directory and pins again. A probe Job for each engine, on the host network, lists the node's addresses, default routes and HCA ports. From these, discover derives each engine's fabric interface, HCA port, GID index, RoCE mode and transport where the fleet sets none. The controller then builds the fleet, the launch records and the role files as package does for SSH hosts.
A Job that ran another image than spec.engines.image, or a checkpoint whose tree digest differs from spec.engines.model.treeSha256, fails the stage. inspection/ holds each engine's records, each Job's log and topology.json, the derived topology with the source of each value. The topology changes when access takes another inventory, as Choosing the engine nodes describes.
Engine pods run on the host network and take every GPU the fleet gives them. Each GPU node therefore runs the engines of one fleet only. Without spec.engines.nodes, every Ready, schedulable GPU node that spec.engines.nodeSelector and nodeCount keep runs the fleet's engines. On a shared cluster, choose the fleet's nodes with nodeSelector or spec.engines.nodes, and give no other fleet, in any namespace, those nodes. The controller sees only its own namespace, so discover checks the node once the fleet's own engines are gone. It fails the stage when the kubelet refuses the discovery Job for want of GPUs that another workload holds. It also fails the stage when the probe Job finds a port already listening on the node. The port may be one of the engine or of its UCX TCP port range.
Preparing the engine pods¶
engine-prepare runs narwhal-engine prepare --backend kubernetes for each engine, in a Job on its node with the model volume. It returns the launch directory to launch/. Every engine of a fleet transfers KV over one transport. Over ucx_rdma, each pod checks that the HCA its RDMA resource hands it is the one NARWHAL_TRANSFER_NET_DEVICES names, which discover derives or engines.launch sets. Discovery refuses a ucx_rdma engine without NARWHAL_TRANSFER_DEVICES, the device paths the launch record keeps, although each pod opens the devices the device plugin gives it.
Applying the engines¶
install applies the engine StatefulSet engine, its headless Service engines and the hook ConfigMaps of each prepared launch. It then deletes the engine objects that the fleet does not hold. A hook ConfigMap that a running engine pod mounts stays until engine-start replaces that pod, which keeps the spec it started with. objects.json holds what was applied, with each ConfigMap's content as its digest.
Starting the engine pods¶
Each new engine pod waits at the narwhal-inference.com/placement scheduling gate. engine-start adds node affinity for the node discovery measured the engine on, removes the gate, and waits for the engine container to be ready. The patch that removes the gate also sets the pod's narwhal-inference.com/attestation-port annotation to its sidecar's port, which the PodMonitor scrapes. The admission policy lets only the controller set the annotation. If an earlier attempt half applied the pin, with the affinity already naming this node, engine-start only removes the gate. Affinity for another node fails the stage, and deleting the pod lets the StatefulSet make a new one. engine-start replaces a pod that runs on another node, and a pod of an older template that runs another plan. It fails when the engine container cannot start. pod.json holds the pod's status.
Checking the engine pods¶
The engine pod keeps its init steps' records in an emptyDir. Its attestation sidecar serves them, and later its published attestation, on GET /v1/pod-evidence of the attestation port, to callers that send the engine API key. engine-check fetches the records and runs narwhal-engine check on them in a copy of the launch directory. It returns checked.json and the copies of the records the check kept. Once the check names the pod that engine-start started, the controller writes checked.json to the pod's narwhal-inference.com/checked-launch annotation. The sidecar waits for that annotation, reading its pod through the API, and attests only a checked plan. The admission policy lets only the controller set the annotation. A rejected check is a failed gate: the Job's log names the record to inspect.
Reading the sidecar's attestation¶
The sidecar captures the attestation once the pod carries its check. cache-capture reads the cache layout from the attestation it published, and attest-capture reads the attestation itself. Each fetches it from the sidecar's /v1/pod-evidence. attest-capture then checks that the engine's live cache resolved the layout its cache group's representative resolved, as an SSH capture does. It fails when the layouts differ. A sidecar that publishes nothing within fifteen minutes fails the stage. Read the sidecar container's log.
The sidecar runs as the chart's sidecarUser, 10002 by default, with controller.runAsGroup as its primary group. The controller, the routers and every gate Job in the Narwhal image run as controller.runAsUser and controller.runAsGroup, whatever user the image sets. Both are 10001 by default. The routers' fsGroup is the same group. The chart therefore refuses a sidecarUser equal to controller.runAsUser or to 10001, the image's own user. In the pod's emptyDir:
- Only the sidecar's user reads the sidecar's private files, which it keeps at 0700 or 0600.
controller.runAsGroupreads the attempt the sidecar published and the record that names it. Once a capture passes, the sidecar gives them to that group at 0750 and 0640. No other pod mounts the emptyDir: the gate Jobs read what the sidecar serves.- The engine and runtime-check containers run as root, user and group 0, whatever user the engine image sets, without
CAP_DAC_OVERRIDEorCAP_SYS_PTRACE. They read none of the sidecar's files, and cannot reach its token or key through the pod's shared process namespace. The vLLM, SGLang and TensorRT-LLM images run as root anyway. An engine image that ran as the sidecar's user could do both. The admission policy therefore refuses an engine pod whose containers run as any user but these, or that sets a supplementary group orfsGroup. - An engine may print its own arguments as it starts. The
enginestep therefore replaces the engine key and the routers' control token in the engine's output. That output reaches bothkubectl logsand the startup log. The sidecar removes both from the startup log again before it keeps it. If an attempt still holds either, the sidecar shares nothing of it:cache-capturefails with a message that names the file, and the attempt stays private. The sidecar also refuses a symbolic link in the pod's directory, which the engine container can write.
Checking the sidecar container¶
sidecar-start waits for the attestation sidecar container to be ready and records its identity. sidecar-verify then runs verify --pod-evidence in a Job as the engines' ServiceAccount, which reads the engine pod through the API as the sidecar does. The check keeps the sidecar's responses and the live identity in the Job's own scratch directory, with verify --into, and returns them in verify/.
Starting the router pair¶
router-start applies the ConfigMaps of the files fleet-limits wrote, as Storage on a lost node describes. It also applies the router StatefulSet router, its headless Service routers and HAProxy. It waits until both have rolled out, so Ready pods of the old template do not count. The stage then waits for the Lease narwhal-router to name a router that took it after its pod's router container started. It checks the health, readiness, state and one completion through HAProxy in a router-check Job. Each router keeps its recovery state and journal on its own volume, at /narwhal-router, as Router volumes describes. After an engine pod is replaced, a router pair that runs the same fleet and objects readmits it instead of restarting.
On a fresh fleet, router-0 finds no handoff and starts with --first-start-primary. It claims the Lease the chart made, which no router has held yet, and serves one lease duration later. router-1 already answers as the standby. The router-check Job therefore asks both routers each second, for up to 180 seconds, until exactly one answers /narwhal/targets with HTTP 200. It fails at once when both do. Every other router start is a standby of the other router. Both routers may come back together with handoffs older than 30 seconds, as after spec.stopped, a recreated fleet or both pods restarting. One of them then claims the Lease as a cold start, within about 36 seconds of their start with the default timings.
The routers write only their own volume and a /tmp scratch directory. With router claims, fsGroup makes the router volume writable on most storage, but not on local-path or other hostPath volumes. A router claim whose files belong to a UID other than the router's is not writable there. The router stops at start with an error that names the volume. Stop the fleet and delete the claims router-state-router-0 and router-state-router-1. The pair then starts cold.
A stopping router finishes its requests in flight for up to spec.serving.gracefulTimeoutS, 30 seconds by default. If spec.routers.args gives --graceful-timeout, that value applies instead. Any --shutdown-drain there adds to the time. The router pods' terminationGracePeriodSeconds is that time plus 10 seconds, so the kubelet sends SIGKILL only to a router that outlives its own drain.
A topology spread constraint on kubernetes.io/hostname, with maxSkew: 1 and whenUnsatisfiable: DoNotSchedule, keeps the two router pods on different nodes whenever more than one node can take them. Losing one node therefore leaves a router. On a single node both still run. Nodes with a taint the routers do not tolerate, such as a control-plane node, do not count.