# Deployment

> Run the Neurouter MCP gateway in production on Docker or Kubernetes with Helm, with PostgreSQL and pgvector, generated encryption keys, zero-downtime key rotation and backups.

Source: https://neurouter.com/docs/deployment · Last updated: 2026-11-24

Neurouter is one container. Run it with Docker on a single host, or on Kubernetes with the bundled Helm chart. Production needs PostgreSQL, an OpenID Connect identity provider, an `https` public URL and three secrets.

## Container image

The image is a multi-stage build on `node:26-bookworm-slim` (glibc, because the ONNX runtime and sqlite-vec prebuilds target glibc). It runs as the non-root `node` user, listens on port 3000, has a health check on `/healthz`, and bakes the embedding model in so it needs no network access for models.

> Pre-built images are planned at `ghcr.io/neurouter/neurouter` with the first public release. Until then, build and push the image to your own registry:

```bash
docker buildx build --platform linux/amd64,linux/arm64 -t <registry>/neurouter:<tag> --push .
```

Health endpoints: `GET /healthz` (liveness, alias `/health`) and `GET /readyz` (database and audit store ready).

## PostgreSQL

- PostgreSQL 16 or newer with the `vector` extension. The migration runs `CREATE EXTENSION IF NOT EXISTS vector` and fails with a clear message if the database role lacks the privilege.
- PostgreSQL is required for more than one replica: SQLite is single-process. Replicas coordinate through PostgreSQL (LISTEN/NOTIFY, advisory locks and leases), so rate limits, approvals and caches are shared and no Redis is needed.
- Optionally put the audit log, sessions and metric rollups in a separate database with `AUDIT_DATABASE_URL`.
- Migrations are forward-only and additive in production, so old and new versions can run side by side during a rolling update.

## Kubernetes with Helm

Create the secrets, then install the chart from `deploy/helm/neurouter`:

```bash
kubectl create secret generic neurouter-crypto \
  --from-literal=NEUROUTER_MASTER_KEYS='k1:…' \
  --from-literal=NEUROUTER_ACTIVE_KEY_ID=k1 \
  --from-literal=HASH_PEPPER='…'
kubectl create secret generic neurouter-db --from-literal=DATABASE_URL='postgres://…'

helm install neurouter deploy/helm/neurouter \
  --set image.repository=<registry>/neurouter --set image.tag=<tag> \
  --set publicUrl=https://mcp.example.com \
  --set crypto.existingSecret=neurouter-crypto \
  --set database.existingSecret=neurouter-db \
  --set oidc.issuer=https://idp.example.com \
  --set oidc.clientId=neurouter \
  --set oidc.existingSecret=neurouter-oidc \
  --set ingress.enabled=true --set ingress.host=mcp.example.com
```

The `neurouter-oidc` secret holds `OIDC_CLIENT_SECRET`.

Chart defaults:

- 2 replicas, `RollingUpdate` with `maxUnavailable: 0`, and a PodDisruptionBudget.
- Non-root, read-only root filesystem with an `emptyDir` on `/tmp`.
- `migrations.mode=job`: a pre-install/pre-upgrade Job migrates and the pods skip it. Set `onStart` to let every pod migrate under a database lock instead.
- `terminationGracePeriodSeconds` is `approvals.maxTimeoutSec + 30` (default 900 + 30), so calls held for human approval can finish during a rollout. Keep `approvals.maxTimeoutSec` at least as large as the maximum approval timeout in the gateway settings.
- Optional: `metrics.serviceMonitor.enabled`, `autoscaling.enabled`, `networkPolicy.enabled` (cloud metadata endpoints are always denied), `archive.url` for audit retention archives, `otel.enabled`.

**Ingress:** `/mcp` (calls held for approval) and `/api/approvals/stream` use server-sent events, so they need proxy buffering off and long read timeouts. The chart's NGINX ingress annotations set both.

## Keys and rotation

| Variable | Protects | Rotation |
|---|---|---|
| `NEUROUTER_MASTER_KEYS` | Key-encryption keys (KEKs) that wrap the data keys encrypting upstream credentials, upstream OAuth tokens and the audit checkpoint MAC key | Supported, no downtime |
| `NEUROUTER_ACTIVE_KEY_ID` | Which KEK wraps new data keys | — |
| `HASH_PEPPER` | HMAC pepper for API keys and OAuth tokens | Changing it invalidates every API key and token |

`npm run keys -- gen [keyId]` prints fresh values. Store them in your secret manager and **back them up**: without the KEKs, stored credentials can't be decrypted, and without the pepper no API key works.

**Rotating a KEK without downtime:**

1. Generate a new key (`npm run keys -- gen k2`) and append it: `NEUROUTER_MASTER_KEYS=k1:…,k2:…`. Set `NEUROUTER_ACTIVE_KEY_ID=k2` and roll the deployment.
2. As an admin, `POST /api/system/keys/rotate` with `{"type":"rewrap"}` to rewrap every data key under `k2`. Poll `GET /api/jobs/:id`; the result's `kekIdsInUse` lists the KEKs still referenced.
3. When `k1` is no longer in `kekIdsInUse`, remove it from `NEUROUTER_MASTER_KEYS` and roll again.

**Rotating the data key:** `POST /api/system/keys/rotate` with `{"type":"dek"}` creates a new data key, re-encrypts every secret under it and deletes retired data keys nothing references. Both jobs are also available in *Settings → Gateway settings*.

## Backup and restore

- **What to back up:** the main database, the audit database if `AUDIT_DATABASE_URL` is separate, and the crypto secret. A database backup without the keys can't decrypt upstream credentials; the keys without the database are useless.
- **PostgreSQL:** `pg_dump -Fc "$DATABASE_URL" > neurouter.dump` (and the same for the audit database). Restore into an empty database with `pg_restore`, start Neurouter with the **same** key values, then run an [audit verification](https://neurouter.com/docs/audit-log#verifying-the-chain).
- **SQLite:** stop the server (or use `sqlite3 neurouter.db ".backup backup.db"` while it runs) and copy the file.
- Audit retention archives (`AUDIT_ARCHIVE_URL`) are written before rows are deleted; keep them under the same retention policy as your backups.
- Restore a backup taken by the same or an older version, then let the newer version migrate it.
