---
title: "Clusters"
description: "Join workers, pin them to a GPU, drain and remove them, and move a model between workers without failing a request."
url: "https://opod.io/docs/core/clusters/"
markdown_url: "https://opod.io/docs/core/clusters.md"
section: "Core"
last_updated: "2026-10-30"
---

# Clusters

> Join workers, pin them to a GPU, drain and remove them, and move a model between workers without failing a request.

## In short

A cluster is one leader and the workers that join it. You mint a join token on the leader, run `opod join` on each new machine, and the leader routes requests to every worker that holds the model. You can drain a worker, remove it, or move a model to another worker without a failed request.

## Join a worker

1. **Mint a join token on the leader**

   ```bash
   opod token create --node
   ```

   The key is printed once. Copy it.

2. **Join from the new machine**

   ```bash
   opod join "http://leader.example.com:8080?token=sk-orc-<node-token>"
   ```

   ```text
   ✔ joining cluster at http://leader.example.com:8080 as n_abc123
   ```

   The command stays in the foreground while the worker runs.

3. **Put a model on it**

   On the leader:

   ```bash
   opod model add llama-3.2-3b --node n_abc123
   ```

A token in the URL is visible to anyone who can list processes. A process manager or container image should leave the URL bare and pass the token in `OPOD_JOIN_TOKEN` instead:

```bash
OPOD_JOIN_TOKEN=sk-orc-<node-token> opod join https://leader.example.com
```

A URL without a scheme gets `http://`. Joining a non-local leader over plain `http` with a token prints a warning: use `https` (see [Security](https://opod.io/docs/core/security/)).

### What the worker does

1. Detects its hardware: OS, architecture, RAM, CPU cores and GPUs.
2. Picks the address the leader should dial: the LAN address on its default route, port `8081`, or `OPOD_ADVERTISE_ADDR` when set.

   ```bash
   OPOD_ADVERTISE_ADDR=192.0.2.51:8081 opod join "http://leader:8080?token=sk-orc-<node-token>"
   ```
3. Saves `~/.opod/node.yaml` with its node id, so the next join keeps the same id.
4. Starts its HTTP API and its heartbeat loop. Each heartbeat carries the engine's loaded models and load sample.
5. With `OPOD_LOAD_MODEL=<catalog id>`, loads that model itself once its engine answers.

   ```bash
   OPOD_LOAD_MODEL=llama-3.2-3b opod join "http://leader:8080?token=sk-orc-<node-token>"
   ```

**Figure: From an empty leader to a served request.** A sequence diagram of every call between your CLI, the leader, a worker and its engine: token create, join, register, heartbeat, model load and a proxied chat request. The interactive figure is on the web page: <https://opod.io/docs/core/clusters/>

### One GPU and a memory budget per worker

Several workers can share one machine or one card:

```bash
opod join "http://leader:8080?token=sk-orc-<node-token>" --gpu 1 --vram-budget 20
```

- `--gpu 1` pins the worker's engine to device 1. It sets `CUDA_VISIBLE_DEVICES` and `HIP_VISIBLE_DEVICES` to `1` and `ONEAPI_DEVICE_SELECTOR` to `level_zero:1` for the engine, unless the variable is already set.
- `--vram-budget 20` caps the engine at 20 GB. For vLLM and SGLang, opod turns this into the engine's memory fraction: (budget − the engine's own overhead) ÷ card memory, clamped to 0.05–0.95. The card memory comes from `OPOD_CARD_MIB`, else from `nvidia-smi`; without either, the budget is not applied. See [`opod join`](https://opod.io/docs/core-cli/join/) for the formula.

The same values can come from `OPOD_GPU_INDEX` and `OPOD_VRAM_BUDGET_GB`. The flags win.

```bash
OPOD_GPU_INDEX=1 OPOD_VRAM_BUDGET_GB=20 opod join "http://leader:8080?token=sk-orc-<node-token>"
```

On a box that a manager measured, pass the card size so the budget applies without `nvidia-smi`:

```bash
OPOD_CARD_MIB=49140 opod join "http://leader:8080?token=sk-orc-<node-token>" --vram-budget 20
```

### Join with a certificate

A worker with `OPOD_NODE_CERT` and `OPOD_NODE_KEY` can join with no token.

```bash
OPOD_NODE_CERT=/etc/opod/node.crt OPOD_NODE_KEY=/etc/opod/node.key \
  OPOD_LEADER_CA=/etc/opod/ca.crt opod join https://leader.example.com
```

Its node id is read from the certificate's SPIFFE URI SAN `spiffe://<domain>/opod/node/<id>`. The leader must have certificate checking on in its auth snapshot. See [Security](https://opod.io/docs/core/security/).

## List and inspect nodes

```bash
opod node ls
```

```text
ID             HOSTNAME             OS/ARCH      ADDRESS                STATE      LAST HB
local          mac-studio-1         darwin/arm64 127.0.0.1:8080         ready      2026-10-30T10:12:44Z
n_abc123       gpu-tower            linux/amd64  192.0.2.51:8081        ready      2026-10-30T10:12:43Z
n_def456       lab-mac              darwin/arm64 192.0.2.52:8081        lost       2026-10-30T10:06:40Z
```

`opod node show <id>` prints the stored record as JSON, plus `loadedModels`.

> **node show prints the worker token**
>
> The record includes the worker's token (`WorkerToken`), which signs leader-to-worker calls. Treat the output as a secret.

## Drain, undrain, remove

```bash
opod node drain n_abc123     # no new requests or gang parts; running requests finish
opod node undrain n_abc123   # back in rotation
opod node remove n_abc123    # the leader forgets it (prompts; --yes skips)
```

- A drain lasts across heartbeats and worker restarts, until you undrain.
- These commands call the running leader, so its router drops the node's cached connection, cooldown and placements at once. When no leader answers, they write the store directly. Each command says which it did.
- A gang with a part on a drained node stops serving.
- When every worker holding a model is drained, requests for that model get `503` with `Retry-After` and a message that names the drain. Other models keep serving.
- The leader's own `local` node cannot be drained. Unload its models or stop the leader.
- `remove` does not stop the worker process. If the worker still runs, its next heartbeat registers it again.

## Move a model to another worker

```bash
opod model move llama-3.2-3b --from n_abc123 --to n_ghi789
```

A move hands a whole (not sharded) model to another worker. The two copies overlap, so no request fails and none waits for a cold load:

1. **started** — the target loads the model while the source keeps serving.
2. **loaded** — the target's heartbeat shows it serving.
3. **flipped** — the router stops choosing the source.
4. **drained** — requests on the source finish (bounded by `placement.drain_timeout_seconds`).
5. **finished** — the source unloads.

If the target never serves (30 minutes by default, which includes a download), the target unloads again and the source keeps serving. That outcome is **aborted**.

A move is refused before anything changes when:

- the source does not hold the model, or serves LoRA adapters of it;
- the target is drained or lost;
- the target cannot hold the model beside what it already holds (the message has the numbers);
- the target runs a one-model engine (vLLM, SGLang, llama.cpp, TensorRT-LLM) that serves another model;
- the model is sharded. Rebuild a gang with `opod shard create`.

No KV cache moves. A conversation recomputes its prompt on the target at its next turn. An Ollama source keeps the weights on disk; its placement is marked `released` and is not routed to until the model loads there again.

A move needs the running leader. If the leader restarts during a move, the move is abandoned: the source serves, and the target's copy is a second replica. The steps also appear as events `model.move_started`, `model.move_loaded`, `model.move_flipped`, `model.move_drained`, `model.move_finished` and `model.move_aborted`.

**Figure: opod model move, over time.** Four lanes over time: the source's memory and requests and the target's memory and requests, with the move's stages marked (the target loads, the router flips, then the source unloads). The interactive figure is on the web page: <https://opod.io/docs/core/clusters/>

## Worker shutdown

On `SIGINT` or `SIGTERM` a worker:

1. tells the leader it is leaving, so the router stops sending it requests at once;
2. lets requests already running finish, for at most `OPOD_DRAIN_SECONDS` (default `10`; `0` stops at once);
3. stops its engine.

```bash
OPOD_DRAIN_SECONDS=60 opod join "http://leader:8080?token=sk-orc-<node-token>"   # let long answers finish
```

Give a container a termination grace period longer than `OPOD_DRAIN_SECONDS`.

## Check it worked

```bash
opod node ls
```

```text
ID             HOSTNAME             OS/ARCH      ADDRESS                STATE      LAST HB
local          leader-1             linux/amd64  127.0.0.1:8080         ready      2026-10-30T10:12:44Z
n_abc123       gpu-tower            linux/amd64  192.0.2.51:8081        ready      2026-10-30T10:12:43Z
```

The new worker shows `ready` and a `LAST HB` less than 5 seconds old. `opod node show n_abc123` lists the models its engine holds in `loadedModels`.

## If it fails

| Symptom                                                                                    | Fix                                                                                                                                                                                                                     |
| ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `opod: no join token (?token= in the URL, or OPOD_JOIN_TOKEN) and no worker certificate …` | Put the token in the URL or in `OPOD_JOIN_TOKEN`.                                                                                                                                                                       |
| `join token refused 6 times in a row: …` and the worker exits                              | The token was revoked or rotated. Mint a new one with `opod token create --node`.                                                                                                                                       |
| The worker is `ready` but no request reaches it                                            | The leader cannot dial the advertised address. Set `OPOD_ADVERTISE_ADDR=host:port` to an address the leader can reach. It must be this machine's own, unless `OPOD_BIND_ADDR` names the one it owns (from core v0.4.0). |
| The worker goes `lost`                                                                     | No heartbeat for 30 s: the process stopped, or the network broke.                                                                                                                                                       |
| HMAC calls are refused                                                                     | The clocks of the two machines differ by more than 5 minutes. Fix NTP.                                                                                                                                                  |
| `opod: the leader's own node cannot be drained — …`                                        | Unload the leader's models, or stop it.                                                                                                                                                                                 |
| A move ends `aborted`                                                                      | The target did not serve within 30 minutes. The source still serves. Read the reason on the `model.move_aborted` event.                                                                                                 |

More in [Troubleshooting](https://opod.io/docs/core/troubleshooting/).

## Network requirements

| From        | To          | Port                                                      | Purpose                                     |
| ----------- | ----------- | --------------------------------------------------------- | ------------------------------------------- |
| clients     | leader      | `8080` (`listen`)                                         | `/v1`, `/admin/v1`, probes                  |
| workers     | leader      | `8080`                                                    | register, heartbeat                         |
| leader      | each worker | `8081`, or `OPOD_ADVERTISE_ADDR`                          | requests, model loads, process control      |
| coordinator | gang parts  | `rpc_port_base` + part index (llama.cpp, default `50052`) | the gang's own traffic                      |
| scrapers    | leader      | `probe_listen`, if set                                    | `/healthz`, `/readyz`, `/loadz`, `/metrics` |

Leader-to-worker traffic is signed but not encrypted. Keep it on a trusted network or a VPN you run.
