Kubernetes¶
This page deploys engine pods on every Ready, schedulable GPU node of a cluster, with a router pair behind HAProxy. Deploying on Kubernetes covers each stage, and the NarwhalFleet reference lists every field.
The cluster admin provides these:
- a GPU device plugin on the nodes
- a default StorageClass that offers ReadWriteMany
- a PersistentVolumeClaim for the checkpoint
- a network plugin that enforces NetworkPolicy
- the images, each pinned by digest
To send KV between nodes over RDMA, each node also needs an RDMA device plugin, as Sending KV over RDMA describes. Cluster requirements gives the details. The workstation needs kubectl, helm, cosign v3 and the narwhal-inference package:
Writing the fleet¶
A Kubernetes fleet needs no init. Start from the reference layout deploy/layouts/kubernetes: its fleet.yaml holds only the inputs the controller cannot default or derive. Each has an example value under a Set: comment. Copy the file to narwhal-fleet.yaml, which narwhal deploy plan reads by default:
curl -fsSL -o narwhal-fleet.yaml \
https://raw.githubusercontent.com/athrael-soju/Narwhal/main/deploy/layouts/kubernetes/fleet.yaml
Set each value under a Set: comment to your cluster's:
metadata.namespace: the namespace the fleet runs in,narwhalbelow.engines.model.name: the served model name.engines.modelVolume.persistentVolumeClaim.claimName: the claim that serves the checkpoint. To serve it from a directory on the node, replacepersistentVolumeClaimwithhostPath. Then set the narwhal chart'smodelVolumeSources: [hostPath], and setmodelHostPathPrefixesto a list with the directory that holds the checkpoint, such as[/models]. Annfsvolume takesmodelNfsServersandmodelNfsPathPrefixesin the same way. Acsivolume takesmodelCsiDrivers. The chart's README describes them.
To have the model stage fetch the checkpoint into the claim, add engines.model.fetch. Set its source to hf://<owner>/<name> or s3://<bucket>/<prefix>. For a hf:// source, set revision to the full commit hash. A fetched model also needs engines.model.treeSha256. The model stage checks the fetched tree against it.
A private or gated source needs engines.model.fetch.tokenSecret, a Secret that holds its token. Fetching the checkpoint into the model volume describes it. The controller's user, controller.runAsUser, must be able to write to the claim.
On nodes whose default container runtime exposes no GPUs, also set engines.resources.runtimeClassName to the GPU RuntimeClass.
The controller works out the rest:
accesstakes the GPU resource the nodes' device plugin offers, such asnvidia.com/gpu. On nodes that offer more than one, setengines.resources.gputo the one the engines request.discoverderives the engines from every Ready, schedulable node that offers the GPU resource, as Engine topology describes. Each node runs the fewest engines that keep two engines after the loss of any one node, with one GPU for each engine. To use fewer nodes, setengines.nodeCount, which takes the first nodes by name, orengines.nodeSelector, which takes only the nodes that carry its labels. Choosing the engine nodes describes which nodes count.- The engines send KV over
ucx_tcp, unless the fleet names an RDMA resource (see below). - The first
discoverpins the checkpoint's tree digest, as Discovering the engine nodes describes. To choose the tree before the firstdiscover, setengines.model.treeSha256, computed as Staging and identifying the checkpoint shows for a host. - The controller generates the routers' control token and the engine API key. To rotate either, name a Secret of your own in
controlTokenSecretorengines.apiKeySecret, as Credentials describes. - The engines run the release's tested engine image for the backend. HAProxy and the fabric Jobs run the images that the released chart names.
engines.image,images.haproxyandimages.hostoverride these images. fleet-limitsderives the SLO targets from the measured fleet, as Deriving the targets describes. Setslo.ttftSandslo.tpotSbefore a load test or production traffic, as Setting production SLOs describes.
Sending KV over RDMA¶
Set engines.resources.rdma to the RDMA resource that every engine node offers. On each node, the resource must hold only the HCA that the engines send KV through. The engine pods and the fabric Jobs must be able to hold it at the same time. An RDMA resource from the generic device plugin gives a plugin configuration that does this.
discover derives ucx_rdma when every node has an ACTIVE HCA port whose verbs device the resource gives. It reads the interface probes, which hold the resource as the engine pods do. For each engine it derives the HCA port, verbs device, GID index, RoCE mode and fabric interface. To override a wrong value, set engines.nodes[].fabricInterface and rdma, or the NARWHAL_NODE_<n>_TRANSFER_NET_DEVICES and NARWHAL_NODE_<n>_TRANSFER_DEVICES entries of engines.launch. Fabric qualification inputs shows how to read the values from sysfs on the node.
Engines that share a node need HCA port counters, as Cluster requirements says. discover refuses a fleet whose node lists its HCAs without them, and names the port. On those nodes, delete engines.resources.rdma to send KV over ucx_tcp, or place one engine on each node (see below).
Placing the engines yourself¶
spec.engines.nodes, with one entry that names each node, overrides the derived layout. Each engine takes spec.engines.gpusPerEngine GPUs, or without that field an equal share of its node's GPUs. A NARWHAL_NODE_<n>_GPU_IDS entry in spec.engines.launch sets fewer. plan notes each node whose loss would leave fewer than two engines.
Long prompts over TCP¶
Over ucx_tcp the first token of a long prompt waits for its KV to cross TCP. For a small model with one GPU for each engine and a 2 s TTFT target, plan --model estimates 1.442 s at 8,190 tokens. At 16,382 tokens it warns:
narwhal: deploy plan: warning: the first-token budget may not fit slo.ttft_s 2.000s: the estimate first-token deadline 1.564s + prefill of 16382 tokens 0.392s + router overhead 0.050s = 2.006s is within its 25% margin of it. The longest calibration length the estimate fits is 16310; end spec.calibration.inputTokens there, or raise spec.slo.ttftS
To serve a longer context over TCP, set the spec.engines.launch entry NARWHAL_CONTEXT_LENGTH and the longest of spec.calibration.inputTokens together, and run plan --model before you apply the fleet.
Installing the chart¶
The released chart installs with no values file. It takes the state volume from the cluster's default StorageClass and runs Prometheus and Grafana. The controller generates Grafana's admin login.
Check the signatures of the images and the chart first, as Verifying a release shows. A cluster that cannot reach ghcr.io runs images you build yourself. Create the namespace, then install the chart:
kubectl create namespace narwhal
kubectl label namespace narwhal pod-security.kubernetes.io/enforce=privileged
helm install narwhal oci://ghcr.io/athrael-soju/charts/narwhal --version <version> \
--namespace narwhal
Add the namespace label only where the cluster enforces the Pod Security baseline level by default. Helm installs the NarwhalFleet CRD with the chart. If a release in another namespace installed the CRD, Helm leaves it unchanged. Upgrading the chart and its CRD applies a newer CRD.
Add a setting only where the site differs from the defaults:
- Where the nodes' default container runtime exposes no GPUs:
--set 'runtimeClassNames={<GPU RuntimeClass>}'. - Where the default StorageClass offers no ReadWriteMany, or the cluster has none:
--set state.storageClassName=<ReadWriteMany storage class>. - For a checkpoint in a directory on the node:
--set 'modelVolumeSources={persistentVolumeClaim,hostPath}' --set 'modelHostPathPrefixes={<directory>}'.
Checking the fleet with plan¶
plan reads narwhal-fleet.yaml and keeps its run in .narwhal/runs/narwhal, named after the fleet's namespace. It names each field the controller would refuse and exits 2.
Give --model a local copy of the model's config.json, or a directory that holds it. plan then estimates from the model's configuration whether the first-token budget can fit slo.ttftS. If it cannot, plan exits 1 and names the longest calibration length that fits. Estimating the budget before the run describes the estimate.
Otherwise plan dry-runs the apply on the API server and prints each stage and why it would run. It needs a kubeconfig that may apply the fleet, such as the workstation identity of narwhal deploy.
Applying and following the fleet¶
kubectl apply --server-side --namespace narwhal -f narwhal-fleet.yaml
kubectl wait --namespace narwhal --for=condition=Ready narwhalfleet/fleet --timeout=4h
kubectl wait returns when the fleet is Ready for the spec you applied, which is when router-start passes.
While the fleet starts, kubectl get narwhalfleet --namespace narwhal shows the running stage in STAGE. kubectl describe narwhalfleet fleet --namespace narwhal shows whether the fleet is Stalled, with the stage and its failure. Recovery says what clears a stall. If the slo gate fails, When the first-token budget fails says what to change. To clear a stall, edit the file and apply it again. A changed context reruns the fleet from discover.
To reach Grafana, Prometheus and the fleet from the workstation, forward the services grafana, prometheus and haproxy as Monitoring shows, with a kubeconfig that may create pods/portforward in the namespace. Open http://127.0.0.1:13000/d/narwhal-router/narwhal-orchestrator, sign in as admin with the password that the controller generated. This command prints the password: kubectl get secret grafana-admin --namespace narwhal -o jsonpath='{.data.password}' | base64 -d. Send completions to http://127.0.0.1:18000/v1/completions.
Stopping and deleting the fleet¶
To stop the fleet and keep its volumes, set spec.stopped: true in the file and apply it again. Set it back to false to start the fleet.
kubectl delete narwhalfleet fleet --namespace narwhal deletes the fleet. The garbage collector then deletes the engines, the routers, HAProxy and the Jobs. A fleet that you apply again under the same name starts a new run directory. To copy the old fleet's profiles and calibration into it, set spec.reuseFrom to the old fleet's UID from status.previousRuns, as Reusing an earlier fleet's evidence describes.
helm uninstall narwhal --namespace narwhal removes the chart. Recovery shows how to delete the namespace and the admission policy.