Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ The gateway's policy `llm-gateway-perimeter` (`llm/gateway/networkpolicy.yaml`)

The cache Valkey's policy `valkey-perimeter` (`llm/valkey.yaml`) admits Open WebUI on TCP 6379 and the `monitoring` namespace on the exporter port 9121. It allows no egress, and `llm-default-perimeter` leaves the Valkey pods out. Valkey requires the password of `llm/valkey-auth` (see Cluster Secrets). Open WebUI sends it in its Redis URL, and Valkey reads it from a quoted config line. A typed value must therefore use only letters, digits, `-`, `.`, `_` and `~`. The gateway and Portkey use no Valkey: the gateway config turns on no cache, and Portkey reads a cache only from `REDIS_CONNECTION_STRING`, which is not set.

The cache Valkey keeps at most 1536 MiB of data (`--maxmemory`), three quarters of its 2048Mi limit. The rest of the limit holds fragmentation and Valkey's own overhead. At the bound, Valkey refuses writes and evicts no key (`--maxmemory-policy noeviction`). Open WebUI keeps its session pools and token revocations there, and an evicted revocation makes a signed-out token valid again. The run index (`llm/valkey-runs.yaml`) uses the same policy with a bound of 512 MiB.

Qdrant requires the key of `llm/qdrant-api-key` (see Cluster Secrets) on every REST and gRPC request. Only `/`, `/healthz`, `/readyz`, `/livez` and the files of its web UI need no key. The qdrant container reads the key as `QDRANT__SERVICE__API_KEY` through `env` in `llm/values-qdrant.yaml`. Open WebUI is the only workload under `k8s/` that names the Qdrant Service, and it sends the key as `QDRANT_API_KEY`. Alloy scrapes `/metrics` with the key as a bearer token, and devops-cli sends keyring `qdrant_api_key`, which the push keeps equal to the Secret. `tests/test_k8s_qdrant_security.py` fails on a top-level key of `llm/values-qdrant.yaml` that the pinned chart (`tests/fixtures/charts/qdrant/`) does not declare, because Helm drops such a key with no error.

Every tier runs ollama as UID and GID 10001, which no host login account uses, with RuntimeDefault seccomp, no privilege escalation, all capabilities dropped and a read-only root filesystem; `/tmp` is an emptyDir. `HOME` is `/home/ollama`, so the key and `models/` stay in the hostPath `/var/lib/ollama` on each GPU node, mounted at `/home/ollama/.ollama`. `fsGroup` does not apply to a hostPath volume, so the initContainer `own-model-directory` gives that directory to 10001 at every start (`chown -R`). It runs as root with `CAP_CHOWN` alone, no privilege escalation and a read-only root filesystem, and exits before ollama starts. It is the one exception to kube-linter's `run-as-non-root` in `ollama-profiles.yaml`, recorded in the manifest's header rather than suppressed with an ignore annotation.
Expand Down
14 changes: 14 additions & 0 deletions k8s/llm/valkey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ spec:
- ALL
# The password goes into a config file on a memory volume rather than onto the command
# line, where it would show in the process list.
#
# Valkey keeps at most 1536 MiB of data, three quarters of the 2048Mi limit (#711). The
# Valkey administration guide sets maxmemory below the free memory by Valkey's own
# overhead and the fragmentation ("10 GB free: set it to 8 or 9"). maxmemory counts the
# bytes Valkey allocates, not its resident memory, and the allocator keeps the pages it
# frees. At the measured allocator fragmentation of about 1.2, 1536 MiB of data is
# about 1850 MiB resident. This Valkey has no replica, no AOF and no RDB, so it needs
# no replication buffer and no fork.
#
# At the bound Valkey refuses writes and evicts no key. Open WebUI keeps its session
# pools and token revocations here. Its Redis guide names noeviction, because an
# evicted revocation makes a signed-out token valid again.
command:
- sh
- -c
Expand All @@ -58,6 +70,8 @@ spec:
--save ""
--appendonly no
--dir /data
--maxmemory 1536mb
--maxmemory-policy noeviction
env:
- name: VALKEY_PASSWORD
valueFrom:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-24
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Design

## Context

See proposal.md, Why and Feasibility. The cache Valkey holds Open WebUI's state and its websocket pub/sub, and no other workload connects to it. It keeps no data across a restart (`--save ""`, `--appendonly no`). The live data set is 1.44 MiB at its peak, under a 2048Mi container limit.

## Goals / Non-Goals

**Goals:**

- Bound the data of the cache Valkey below its container limit, with room for the fragmentation and Valkey's own overhead.
- At the bound, refuse writes and keep every key, as the run index does.
- Hold both llm Valkeys to their bound and policy in a test.

**Non-Goals:**

- A Checkov step in CI (Decision 3).
- A guard against a returning `:latest` tag (Decision 4).
- An alert on the memory use of the cache Valkey (tasks.md, Workflow follow-up).

## Decisions

### Decision 1: `noeviction`, not `volatile-lru`

- **Rationale**: Open WebUI is the only client (#1654). Its keys with a TTL are token revocations, sign-in rate-limit buckets, task markers and cleanup locks, and none of them is a disposable cache entry. Under `volatile-lru`, Valkey evicts the least recently used of these keys first. Nothing reads a revocation until its revoked token comes back, so a revocation is a likely first victim, and the signed-out token becomes valid again. Open WebUI's Redis guide names `noeviction` for a capped instance. With `noeviction`, Valkey refuses writes at the bound with an error and keeps every key, as the run index does.
- **Rejected alternative**: `volatile-lru`, as the issue proposed. The issue chose it to evict the TTL entries of the LiteLLM and Portkey caches before the persistent keys. Neither connects to this Valkey since #1654, so the only keys that it can evict are Open WebUI's security and coordination keys.
- **Rejected alternative**: `allkeys-lru`. It also evicts the session and usage pools, which breaks the websockets, and the issue rejects it for that reason.

### Decision 2: `--maxmemory 1536mb`, three quarters of the limit

- **Rationale**: Valkey counts its allocated bytes against `maxmemory`, not its resident memory. The allocator keeps the pages that Valkey frees, so the resident memory follows the peak. The live `allocator_frag_ratio` is about 1.2, so 1536 MiB of data is about 1850 MiB resident, and the 18 MiB of the idle process still fits under 2048 MiB. Valkey's `mb` and the Kubernetes `Mi` are both 1024 × 1024 bytes. The pod has no replica, no AOF and no RDB, so `mem_not_counted_for_evict` is 0 and no fork doubles the memory. Each pub/sub client can hold an output buffer of 32 MiB at most (`client-output-buffer-limit pubsub 32mb`), and Valkey counts it inside `used_memory`.
- **Rejected alternative**: 1638 MiB or 1843 MiB, the 80 % to 90 % that Valkey's administration guide gives as an example. At a fragmentation of 1.2 they are about 1966 MiB and 2212 MiB resident, at or above the 2048Mi limit.
- **Rejected alternative**: a larger container limit. The measured peak is 1.44 MiB, so no data shows a need for more memory.

### Decision 3: no Checkov step

- **Rationale**: Checkov 3.3.19 `CKV_K8S_14` fails on `k8s/devops/cronjob.yaml` and `k8s/devops/roadmap-service/deployment.yaml`. They name the service image with no tag by design, because Argo CD Image Updater writes the digest into the `devops` Application (k8s/README.md, Service Image Updates).
- **Rejected alternative**: `k8s/.checkov.yaml` with a `skip-path` for those two workloads and for the CoreDNS patch. That is compensating code that the issue did not ask for, and each new untagged workload would need another skip.

### Decision 4: the `:latest` guard moves to a follow-up issue

- **Rationale**: No workload image under `k8s/` has the tag `latest` now. kube-linter 0.8.3 is in `tools.lock`, but its default `latest-tag` check also blocks an untagged image. A custom check from the `latest-tag` template with `.*:(latest)$` alone flags `:latest` and leaves the untagged service image alone. That is a CI change of its own.

## Open WebUI keys with no TTL

Open WebUI keeps most of its keys with no TTL: the session, usage and model pools, the task index, the collaborative-note documents, the cached tool and terminal server lists and the base model cache. `auth:user:<id>:revoked_at` also has no TTL when the JWT expiry is not set. A key with no TTL is never an eviction candidate, so no policy but `allkeys-*` can free it. Each of these keys follows live state, such as connected sessions, running tasks and open notes, and Open WebUI deletes it when that state ends. A key can stay when Open WebUI stops before its cleanup runs, but each Valkey restart starts empty. With `noeviction`, such growth ends at the bound with write errors that a person can see, not with an out-of-memory kill.

## Risks / Trade-offs

- At the bound, Open WebUI gets write errors, for example at sign-in, until a person finds the cause. The existing `ValkeyCacheErrors` alert does not cover a refused write, so an alert on the memory use moves to a follow-up issue.
- The rollout restarts the pod, and Valkey starts empty, as at each restart. Open WebUI's websocket clients connect again, and revocations from before the restart are lost, as they are at each restart today.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Proposal

## Why

Issue #711: the cache Valkey of the llm stack (`k8s/llm/valkey.yaml`) starts with no `--maxmemory` and no `--maxmemory-policy` under a 2048Mi container limit. Its data can grow until the kernel kills the container for memory. The run index (`k8s/llm/valkey-runs.yaml`) already sets `--maxmemory 512mb` and `--maxmemory-policy noeviction`, but no test holds either manifest to a bound.

## What Changes

- `k8s/llm/valkey.yaml` starts valkey-server with `--maxmemory 1536mb` and `--maxmemory-policy noeviction`. A manifest comment gives the basis of the number and of the policy.
- `tests/test_k8s_valkey_stack.py` holds both llm Valkeys to the flag pair, and holds each bound to at most three quarters of its container memory limit.
- `k8s/README.md` says what the bound is and why Valkey evicts no key.
- The policy is `noeviction`, not the `volatile-lru` of the issue. Open WebUI is the only client of the cache Valkey, and its keys with a TTL are token revocations, sign-in rate-limit counters, task markers and locks. Open WebUI's Redis guide names `noeviction` for a capped instance (design.md, Decision 1).
- The Checkov CI step of the issue is not built: `CKV_K8S_14` fails on the untagged service image, which is untagged by design (Feasibility).
- No image needs a pin: no workload image under `k8s/` has the tag `latest`.

A manifest is observable, so the change carries a spec delta, in the new capability `llm-valkey`.

This change fits in one pull request.

## Capabilities

### New Capabilities

- `llm-valkey`: the memory bound of each Valkey in the llm namespace, and what Valkey does at that bound.

### Modified Capabilities

None.

## Impact

- `k8s/llm/valkey.yaml`: the two flags and their comment. Argo CD syncs the change from `main`, and the pod restarts with an empty data set, as at each restart (`--save ""`, `--appendonly no`).
- `tests/test_k8s_valkey_stack.py`: the bound test, and the full command of the cache Valkey.
- `k8s/README.md`: the bound and the policy of the cache Valkey.

## Feasibility

I confirmed the premise against the real system on 2026-10-24, at `origin/main` bba1f5ce:

- `k8s/llm/valkey.yaml` runs `exec valkey-server /run/valkey/auth.conf --save "" --appendonly no --dir /data` with a 2048Mi memory limit and no `--maxmemory`. `k8s/llm/valkey-runs.yaml` sets `--maxmemory 512mb --maxmemory-policy noeviction` under a 768Mi limit.
- The live pod (read-only `valkey-cli INFO memory`, Valkey 9.1.2, jemalloc-5.3.0) reports `used_memory` 1476520 (1.41M), `used_memory_peak` 1505240 (1.44M), `used_memory_rss` 18.19M, `maxmemory` 0, `maxmemory_policy` noeviction, `allocator_frag_ratio` 1.21 to 1.23, and `mem_not_counted_for_evict`, `mem_replication_backlog` and `mem_aof_buffer` all 0. `INFO keyspace` gives `db0:keys=2,expires=2`: the two Open WebUI cleanup locks. Two clients subscribe to pub/sub channels.
- Open WebUI is the only client. `test_open_webui_is_the_only_workload_that_names_the_cache_valkey` holds that, and `valkey-perimeter` admits only the `open-webui` pods on 6379 (#1654). LiteLLM and Portkey do not connect, so the issue's statement that they write to this Valkey is out of date.
- Open WebUI v0.11.4 source (`backend/open_webui`) sets a TTL on `auth:token:<jti>:revoked` and `auth:user:<id>:revoked_at` (`utils/auth.py`), the cleanup locks (`socket/utils.py`), `tasks:<id>` (`tasks.py`, 300 s) and the sign-in rate-limit buckets (`utils/rate_limit.py`). It sets no TTL on `session_pool`, `usage_pool` and `models` (`socket/main.py`), `tasks` and `tasks:item:<id>` (`tasks.py`), `tasks:response_streams` (only its fields expire, by `HEXPIRE`), the `ydoc:documents:*` lists and sets (`socket/utils.py`), `tool_servers` and `terminal_servers` (`utils/tools.py`), and the base model cache (`utils/models.py`).
- Valkey 9.1.2 `src/evict.c` samples the `volatile-*` candidates from `db->expires` only, the keys with a key-level TTL.
- Open WebUI's Redis guide (`open-webui/docs`, `docs/tutorials/integrations/redis.md`, commit 416b3593 of 2026-10-16) says: "Use **`noeviction`** (the safe default)", and "If you must cap memory, set a `maxmemory` limit paired with **`noeviction`**". It says that `volatile-lru` "can still drop a revocation early".
- Valkey's administration guide (`valkey-doc`, `topics/admin.md`) says: "`maxmemory` should be set by calculating the overhead for Valkey, other than data, and the fragmentation overhead. So if you think you have 10 GB of free memory, set it to 8 or 9." `topics/memory-optimization.md` says to provision for the peak, because the allocator does not give freed pages back. `topics/lru-cache.md` and `valkey.conf` of 9.1.2 add a replication and AOF buffer outside the count only when replicas or AOF are on.
- Checkov: `uvx --from checkov==3.3.19 checkov -d k8s --framework kubernetes --check CKV_K8S_14` exits 1 with 16 passed and 3 failed: `coredns/deployment-patch.yaml`, `devops/roadmap-service/deployment.yaml` and `devops/cronjob.yaml`. The last two name `ghcr.io/dan-petty/devops-cli/service` with no tag. k8s/README.md, Service Image Updates, says: "Git names the image untagged, and that entry sets its tag and digest", where Argo CD Image Updater writes the entry into the `devops` Application. A `skip-path` for those workloads is compensating code, so the Checkov step and `k8s/.checkov.yaml` leave the scope of this change.
- `grep -rnE 'image:.*:latest' k8s/` finds no match. The only `:latest` text under `k8s/` is the `imageName` that Image Updater follows (`k8s/argocd/image-updater-values.yaml`) and the README text about it. #727 removed LightLLM, and #738 pinned Portkey.
- kube-linter 0.8.3, which `tools.lock` pins, has a default `latest-tag` check with the block list `.*:(latest)$`, `^[^:]*$` and `(.*/[^:]+)$`. `kube-linter lint k8s/devops/cronjob.yaml` reports `latest-tag` on the untagged service image. A guard against a returning `:latest` tag therefore needs a custom check with `.*:(latest)$` alone, which moves to a follow-up issue (tasks.md).

## Existing Tool Considered

Valkey's own `maxmemory` and `maxmemory-policy` settings give the bound, so the change builds nothing. The guard against a `:latest` tag uses kube-linter, which `tools.lock` already pins, in a follow-up issue. Checkov 3.3.19 was considered for that guard and rejected: its `CKV_K8S_14` fails on an untagged image, and the service image is untagged by design. The change deletes no internal code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Spec Delta

## Purpose

The Valkey servers of the llm namespace in the cluster manifests: the cache Valkey that holds Open WebUI's state and the run index that workstations share. It says how much memory each one keeps as data and what each one does when its data reaches that bound.

## ADDED Requirements

### Requirement: Each llm Valkey refuses writes at a memory bound below its container limit
The valkey container of each Valkey Deployment in `k8s/llm/` SHALL start valkey-server with `--maxmemory` at most three quarters of the container's memory limit, and with `--maxmemory-policy noeviction`, so that Valkey refuses writes at the bound and evicts no key.

#### Scenario: The cache Valkey keeps at most 1536 MiB of data
- **WHEN** the Deployment `valkey` is read from `k8s/llm/valkey.yaml`
- **THEN** its valkey container starts valkey-server with `--maxmemory 1536mb` and `--maxmemory-policy noeviction`, and 1536 MiB is at most three quarters of the container's 2048Mi memory limit

#### Scenario: The run index keeps at most 512 MiB of data
- **WHEN** the Deployment `valkey-runs` is read from `k8s/llm/valkey-runs.yaml`
- **THEN** its valkey container starts valkey-server with `--maxmemory 512mb` and `--maxmemory-policy noeviction`, and 512 MiB is at most three quarters of the container's 768Mi memory limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Tasks

## 1. Memory bound of the llm Valkeys

- [x] 1.1 Write a failing test that holds the cache Valkey and the run index to `--maxmemory` at most three quarters of the container memory limit and to `--maxmemory-policy noeviction`, and add the two flags to the full command of the cache Valkey (`uv run devops ci test tests/test_k8s_valkey_stack.py`).
- [x] 1.2 Start the cache Valkey in `k8s/llm/valkey.yaml` with `--maxmemory 1536mb` and `--maxmemory-policy noeviction`, with the basis of both in a manifest comment (`uv run devops ci test tests/test_k8s_valkey_stack.py`).
- [x] 1.3 Describe the bound and the policy of the cache Valkey in `k8s/README.md`, and sync the documentation with `uv run devops docs generate --sync-readme` (`uv run devops docs check`).

## Workflow follow-up

- moved to #2093, after #2095: evaluate kube-linter's `latest-tag` check, or an equal open tool, in CI. It must flag a `:latest` tag and leave an untagged image that Argo CD Image Updater pins. kube-linter 0.8.3 is in `tools.lock`, but its default `latest-tag` block list also blocks an untagged image, so the check needs a custom check from the `latest-tag` template with `.*:(latest)$` alone. `devops k8s lint` exits 0 when kube-linter finds problems, and prints "passed" when kube-linter is not installed, so CI must not run the guard through it in its current state.
- moved to #2094: alert when the cache Valkey's memory use nears its bound (`redis_memory_used_bytes` over `redis_memory_max_bytes` of its redis-exporter sidecar). With `noeviction`, a full Valkey refuses writes, and `ValkeyCacheErrors` does not cover a refused write.
- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).
Loading