Skip to content

fix(k8s): let gateway rollouts and database restarts finish open calls - #5342

Merged
dan-petty merged 2 commits into
mainfrom
fix/5301-let-gateway-rollouts-and-database-restarts
Nov 13, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/5301-let-gateway-rollouts-and-database-restarts

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Three defaults of the LiteLLM gateway and its database cut open model calls or stopped the start of the gateway.

  • The gateway pod sets terminationGracePeriodSeconds: 600. On SIGTERM, uvicorn waits for each open call, and LiteLLM sets no timeout_graceful_shutdown, so the default of 30 s cut long calls at a rollout.
  • The Cluster llm-gateway-db sets smartShutdownTimeout: 15. The idle sessions of the old gateway pod kept the default smart shutdown of 180 s open, and the new gateway pod stopped after its migration check.
  • The three gateway probes set timeoutSeconds: 5. One slow request holds the one uvicorn worker for some seconds, and the default of 1 s made probes fail.

allow_requests_on_db_unavailable stays unset. Three checks of the k8s row hold the values, and k8s/README.md tells how the gateway and its database stop.

Closes #5301

Change: openspec/changes/archive/2026-11-13-5301-let-gateway-rollouts-and-database-restarts/

Three defaults of the gateway and its database cut open model calls or
stopped the start of the gateway.

- The gateway pod sets terminationGracePeriodSeconds 600. On SIGTERM,
  uvicorn waits for each open call, and LiteLLM sets no
  timeout_graceful_shutdown, so the default of 30 s cut long calls.
- The Cluster llm-gateway-db sets smartShutdownTimeout 15. The idle
  sessions of the old gateway pod kept the default smart shutdown of
  180 s open, and the new gateway pod stopped after its migration check.
- The startup, liveness and readiness probes of the gateway set
  timeoutSeconds 5. One slow request holds the one uvicorn worker for
  some seconds, and the default of 1 s made probes fail.

allow_requests_on_db_unavailable stays unset. Three checks of the k8s
row hold the values, and k8s/README.md tells how the gateway and its
database stop.

Closes #5301
@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/k8s Kubernetes commands, Helm charts, pods, services, and policies labels Nov 13, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results

  • Fail-to-pass: the CI run Fail-to-Pass Test Replay passed. The k8s row had 3 of 113 cases fail on the base and 0 of 113 fail on the head: check_a_rollout_lets_the_old_gateway_pod_finish_its_open_calls, check_a_restart_of_the_database_waits_15_s_for_the_open_sessions and check_one_slow_request_does_not_fail_a_probe_of_the_gateway each failed on the base and passed on the head.
  • Local replay, uv run devops ci fail-to-pass --base origin/main: the k8s row had 3 of 113 cases fail on the base and 0 of 113 fail on the head. Each of the 3 new checks of tests/gate/k8s_checks/gateway_database.py failed on the base and passed on the head.
  • uv run devops ci --check --only k8s,lint,format,docs: pass.
  • MYPYPATH=src:typings uv run mypy --strict --follow-imports=silent tests/gate/k8s_checks/gateway_database.py: no issues.
  • uv run pytest on the tests that read the changed files (tests/ai/benchmark/test_k8s_llm_gateway.py, tests/commands/k8s/test_k8s_network_policies.py, tests/commands/k8s/test_k8s.py, tests/docs/test_docs_inventory.py, tests/invariants/test_k8s_manifests.py, tests/core/test_k8s_local_path_placement.py, tests/core/test_third_party_telemetry.py): 348 passed.
  • uv run devops openspec check: pass.

Render difference

kubectl kustomize at origin/main (fbb7c72) and at the head:

  • k8s/llm (Argo CD Application llm): Deployment llm-gateway adds terminationGracePeriodSeconds: 600 to the pod template and timeoutSeconds: 5 to startupProbe, livenessProbe and readinessProbe. Cluster llm-gateway-db adds smartShutdownTimeout: 15. Nothing else changes. The name of the gateway ConfigMap does not change, because config.yaml does not change.
  • k8s/llm/gateway (deploy-stack): the same 4 lines of the Deployment. Nothing else changes.

A server-side dry run of kubectl diff against the live objects (no apply) shows the same fields: terminationGracePeriodSeconds 30 to 600, timeoutSeconds 1 to 5 on each probe, and smartShutdownTimeout 180 to 15. The admission webhook of CloudNativePG accepts 15.

What restarts at the merge

  1. The gateway rolls one time, because its pod template changes. The rolling update with 1 replica (maxSurge 1, maxUnavailable 0) starts the new pod first, so the gateway stays available. The old pod keeps the grace period of its own spec, 30 s, so this one rollout can still cut a call that is open for more than 30 s. The rollouts after it use 600 s.
  2. The database does not restart. In CloudNativePG 1.30.1, pkg/specs/pods.go sets the terminationGracePeriodSeconds of the instance pod from stopDelay only, and the environment hash (CreatePodEnvConfig) does not hold smartShutdownTimeout. TryShuttingDownSmartFast in pkg/management/postgres/instance.go reads the value from the cached Cluster at each stop. Argo CD changes only the Cluster spec.

Steps for a person after the merge

  • kubectl -n llm get cluster llm-gateway-db -o jsonpath='{.spec.smartShutdownTimeout}' shows 15, and the database pod has the same restart count and start time as before the merge.
  • A rollout of the gateway during a call that is open for more than 30 s ends with Finished server process in the log of the old pod, and the client gets a full reply.
  • The next restart of the gateway database ends in less than 30 s, and the restart count of the running gateway pod does not increase.
  • A v1 /spend/logs call of 10,000 rows causes no Unhealthy probe event on the gateway.

@dan-petty
dan-petty marked this pull request as ready for review November 13, 2026 03:06
@dan-petty
dan-petty merged commit 1f928c1 into main Nov 13, 2026
24 checks passed
@dan-petty
dan-petty deleted the fix/5301-let-gateway-rollouts-and-database-restarts branch November 13, 2026 03:09
dan-petty pushed a commit that referenced this pull request Nov 13, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.125.5](v0.125.4...v0.125.5)
(2026-11-13)


### Bug Fixes

* **k8s:** let gateway rollouts and database restarts finish open calls
([#5342](#5342))
([1f928c1](1f928c1))

---
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/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(k8s): let gateway rollouts and database restarts finish open calls

1 participant