Skip to content

feat(k8s): keep gateway virtual keys in a CloudNativePG database - #3747

Merged
dan-petty merged 3 commits into
mainfrom
feat/1635-gateway-database
Nov 6, 2026
Merged

dan-petty merged 3 commits into
mainfrom
feat/1635-gateway-database

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The LiteLLM gateway keeps virtual keys only in a Postgres database. This adds the CloudNativePG Cluster llm-gateway-db with its network policy. The operator generates the Secret that the gateway reads as DATABASE_URL, so git holds no password and no person step is needed. The gateway migrates on a read-only root, stops its start-up on a failed migration, and stays in the Service while the database is down, so only virtual keys are refused. The operator moves to stack infra, and deploy-stack applies the database after the Helm releases.

Closes #1635

Change: openspec/changes/archive/2026-11-06-1635-gateway-database/

…database

Add Cluster llm-gateway-db with its perimeter, let the operator generate
the Secret that the gateway reads as DATABASE_URL, migrate on a read-only
root through LITELLM_MIGRATION_DIR, and install the operator with stack
infra so stack llm applies the database after the Helm releases.

Refs #1635
@dan-petty dan-petty added type/feature Type feature: a new function scope/k8s Kubernetes commands, Helm charts, pods, services, and policies labels Nov 6, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Rollout: what happens to the gateway

Argo CD applies the merge at once. No person runs a command, and the gateway has no downtime that a person must plan for.

  1. Argo CD creates policy llm-gateway-db-perimeter and the Cluster llm-gateway-db. The operator creates Secret llm-gateway-db-app with a generated password.
  2. The Deployment changes, so Kubernetes starts one new gateway pod beside the old pod (one replica, maxSurge 1, maxUnavailable 0). The old pod keeps all traffic until the new pod is ready.
  3. The new pod cannot start its container until the Secret exists. Then LiteLLM runs prisma migrate deploy on the empty database. ENFORCE_PRISMA_MIGRATION_CHECK=true makes a failed migration end the process, so the pod restarts until the database accepts connections. The startupProbe allows ten minutes for this. A few restarts of the new pod are normal.
  4. The new pod passes its readiness probe, and Kubernetes stops the old pod.

Migrations: the first start applies all LiteLLM migrations to the empty database. A later LiteLLM upgrade runs the new migrations the same way, and a failed one stops the pod instead of a start on an old schema.

Risk that a person should know about: the database has one instance and no backup yet (#3741). A lost node loses the virtual keys, and a person mints them again. The cluster Jobs keep the master key, which needs no database.

If the new pod never becomes ready (for example the operator is missing), the old pod stays in service, and the rollout waits. The operator is Helm release cloudnative-pg of stack infra. It already runs in the cluster for Mattermost.

Review findings

  1. Readiness depended on the database (major). Verified in LiteLLM 1.103.0: _resolve_public_readiness_db sets 503 on /health/readiness when the database is not connected and allow_requests_on_db_unavailable is false, and the master key is checked without the database. Fixed: the readinessProbe uses /health/liveliness. /health/readiness stays a manual post-sync check. A gate check pins the path, and k8s/README.md states the effect.
  2. No ENFORCE_PRISMA_MIGRATION_CHECK (minor). Verified in proxy_cli.py: after 4 failed tries LiteLLM prints "continuing startup" unless the variable is true. Fixed: the variable is "true", a gate check pins it, and the README says what it does.
  3. OpenSpec change not archived (minor). Fixed: archived in the last commit. openspec/specs/k8s-helm-deploy/spec.md now has the modified chat requirement, and openspec/specs/llm-gateway-database/ exists.

All three findings were correct.

Checks run

  • uv run devops ci --only k8s --check: 92 cases, 0 failed (after the fixes).
  • Full uv run devops ci on the rebased branch before the archive commit: 2 failed, 19575 passed, 1 error, and every other check passed. The failures are the known host failures that fail on origin/main too: tests/commands/test_devcontainer_install_tools_dry_run.py::test_mark_only_commands_under_global_dry_run and tests/ai/test_tool_executor_contract.py (fix(ci): host state fails four tests and one case #3585, one failure and one teardown error). The test row took 6m 40s, over the 5 minute budget (fix(ci): the pytest step of devops ci exceeds the 5-minute budget #3593). Coverage did not run because the test row failed.
  • Not run: kubectl apply --dry-run=client (the gate check renders the kustomization and the k8s row passed). Nothing was applied to the cluster. The fail-to-pass run does not apply: this is a feature, and its checks were written first.

@dan-petty
dan-petty marked this pull request as ready for review November 6, 2026 06:33
@dan-petty
dan-petty merged commit 44d9196 into main Nov 6, 2026
24 checks passed
@dan-petty
dan-petty deleted the feat/1635-gateway-database branch November 6, 2026 06:37
dan-petty pushed a commit that referenced this pull request Nov 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.67.0](v0.66.0...v0.67.0)
(2026-11-06)


### Features

* **k8s:** keep gateway virtual keys in a CloudNativePG database
([#3747](#3747))
([44d9196](44d9196)),
closes [#1635](#1635)


### Bug Fixes

* **docs:** rule documents name files that are gone or moved
([#3756](#3756))
([0be8f7f](0be8f7f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/k8s Kubernetes commands, Helm charts, pods, services, and policies type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(k8s): the LiteLLM gateway keeps virtual keys in an in-cluster Postgres, so devops-cli can mint scoped, expiring gateway keys

1 participant