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
4 changes: 3 additions & 1 deletion k8s/argocd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ redis:
tag: 9.1.2-alpine
exporter:
enabled: true
# The exporter uses about 2m at peak, but CFS throttled it in 57% of the periods of 7 d at a
# 100m limit, and a throttled scrape is slow (#4991).
resources:
requests:
cpu: 10m
memory: 16Mi
limits:
cpu: 100m
cpu: 500m
memory: 64Mi
metrics:
enabled: true
Expand Down
4 changes: 3 additions & 1 deletion k8s/devops/roadmap-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ spec:
# 150 MiB each hour from about 460 MiB, so 1Gi killed the pod after
# about 4 hours. #4116 holds the analysis of the leak. #4125 is the
# open 6-hour flat check. Revisit the limit when the working set is flat.
# The CPU limit is 2: the container reached 1.00 core at a limit of 1 (#4991). The event
# loop uses one core, so the raise is for the bursts of subprocesses and native threads.
resources:
requests:
cpu: 100m
memory: 768Mi
limits:
cpu: "1"
cpu: "2"
memory: 3Gi
volumes:
- name: tmp
Expand Down
5 changes: 4 additions & 1 deletion k8s/llm/gateway/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@ spec:
mountPath: /tmp
- name: migrations-volume
mountPath: /var/lib/litellm/migrations
# The working set grows from about 660 to 1330 MiB in 4 days between rollouts, so the
# memory limit is 4Gi (#4991). Do not set MAX_REQUESTS_BEFORE_RESTART: with one uvicorn
# worker and one replica, every model call fails until the container starts again.
resources:
requests:
cpu: 200m
memory: 512Mi
limits:
cpu: 1000m
memory: 2048Mi
memory: 4Gi
# The proxy opens its port only after it has applied the migrations, which take longer
# on an empty database. This probe holds the other two back for up to ten minutes, so
# the kubelet does not kill a pod that is still migrating.
Expand Down
4 changes: 3 additions & 1 deletion k8s/llm/valkey-devops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ spec:
- name: metrics
containerPort: 9121
protocol: TCP
# The exporter uses 21m or less, but CFS throttled it in more than half of the
# periods of 7 d at a 100m limit, and a throttled scrape is slow (#4991).
resources:
requests:
cpu: 10m
memory: 16Mi
limits:
cpu: 100m
cpu: 500m
memory: 64Mi
livenessProbe:
httpGet:
Expand Down
4 changes: 3 additions & 1 deletion k8s/llm/valkey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ spec:
- name: metrics
containerPort: 9121
protocol: TCP
# The exporter uses 21m or less, but CFS throttled it in more than half of the
# periods of 7 d at a 100m limit, and a throttled scrape is slow (#4991).
resources:
requests:
cpu: 10m
memory: 16Mi
limits:
cpu: 100m
cpu: 500m
memory: 64Mi
livenessProbe:
httpGet:
Expand Down
5 changes: 3 additions & 2 deletions k8s/monitoring/grafana-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ service:
port: 80
targetPort: 3000

# The 7 d peak of the working set was 1014 MiB of a 1024Mi limit (#4991).
resources:
requests:
cpu: 100m
memory: 256Mi
memory: 512Mi
limits:
cpu: 500m
memory: 1024Mi
memory: 2Gi

persistence:
enabled: true
Expand Down
10 changes: 7 additions & 3 deletions k8s/monitoring/k8s-monitoring-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,14 @@ telemetryServices:
- --collector.tcpstat
env:
DBUS_SYSTEM_BUS_ADDRESS: unix:path=/host/root/run/dbus/system_bus_socket
# CFS throttled node-exporter in 29% of the periods of 7 d at a 200m limit, and the median
# scrape took up to 1.9 s. The CPU limit is 500m (#4991).
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 200m
cpu: 500m
memory: 256Mi

# ── Collectors ───────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -347,13 +349,14 @@ collectors:
extra:
- name: alloy-wal
mountPath: /var/lib/alloy
# The 7 d peak of the working set was 737 MiB, 72% of 1024Mi (#4991).
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 1000m
memory: 1024Mi
memory: 1536Mi
alloy-singleton:
# clusterEvents runs unclustered, so exactly one pod watches and ships the events.
presets:
Expand All @@ -376,13 +379,14 @@ collectors:
- host-storage
alloy:
enableReporting: false
# The 7 d peak of the working set was 342 MiB, 67% of 512Mi, and it rises (#4991).
resources:
requests:
cpu: 50m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
memory: 768Mi
alloy-profiles:
# `privileged` is deprecated in 4.5.2: `root` sets the privileged securityContext, and the eBPF
# profiler needs the host PID namespace only, not the host network (#1955).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-12
skip_specs: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Design

## Decisions

- **Raise each memory limit to at least 1.5 times the 7 d peak.**: Grafana 2Gi is 2.0 times 1014 MiB, the gateway 4Gi is 3.1 times 1333 MiB (it grows about 170 MiB each day between rollouts), `alloy-metrics` 1536Mi is 2.1 times 737 MiB, and `alloy-logs` 768Mi is 2.2 times 342 MiB, which still rises.
- **Raise the Grafana memory request to 512Mi.**: The working set was 444 MiB at the time of the check, above the old request of 256Mi. The other requests stay, because the scheduler needs no change for them.
- **Raise the exporter CPU limits to 500m and keep the requests.**: The exporters use 2m to 33m, but CFS throttles them in 29% to 69% of the periods, so a short burst at the scrape waits for the next period. 500m lets a scrape burst finish in one period. A limit is not reserved on the node.
- **Raise the CPU limit of the Service to 2.**: The container reached 1.00 core at a limit of 1. The event loop uses one core, so the raise is for the bursts of subprocesses and native threads.
- **Do not set `MAX_REQUESTS_BEFORE_RESTART` on the gateway.**: The gateway runs one uvicorn worker in one replica, so a restart of the worker stops every model call until the container starts again. The comment above `resources` says so.
- **Keep Tempo at 2Gi.**: Its 7 d peak is 76% of the limit. The near-limit rule of #4993 watches it.
- **Hold the new values in the tests that already read these `resources` blocks.**: A later cut of a limit then fails a test.

## Rejected alternatives

- **Run KRR first and size every container from it.**: #4992 does that next. The data here already shows that these limits are too low, and Grafana is at 99% of its limit.
- **Remove the CPU limits of the exporters.**: The project sets a CPU limit on every container, and #4992 keeps that rule.
- **Raise the limits with `kubectl patch`.**: Argo CD self-heal reverts it. The live limits read the same values as git.
- **Use `MAX_REQUESTS_BEFORE_RESTART` instead of a higher gateway limit.**: With one worker and one replica, each restart fails every model call in flight.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Proposal

## Why

#4991: on 2026-11-12 the owner said that the cluster limits look unnecessarily low. 7 days of Prometheus data show that some memory limits are near the peak use, and that some CPU limits throttle containers that use only a few millicores. Today each limit is fixed only after a kill (#4116, #4149, #2806, #1815, #2391, #4939). This item is rank 1 of the cluster integration plan #4989.

## What Changes

- `k8s/monitoring/grafana-values.yaml`: the Grafana memory request goes from 256Mi to 512Mi, and the memory limit from 1024Mi to 2Gi.
- `k8s/llm/gateway/deployment.yaml`: the memory limit of container `litellm` goes from 2048Mi to 4Gi. A comment says why, and says not to set `MAX_REQUESTS_BEFORE_RESTART`.
- `k8s/monitoring/k8s-monitoring-values.yaml`: the memory limit of `alloy-metrics` goes from 1024Mi to 1536Mi, of `alloy-logs` from 512Mi to 768Mi, and the CPU limit of node-exporter from 200m to 500m.
- `k8s/llm/valkey.yaml`, `k8s/llm/valkey-devops.yaml` and `k8s/argocd/values.yaml`: the CPU limit of the redis_exporter sidecars goes from 100m to 500m.
- `k8s/devops/roadmap-service/deployment.yaml`: the CPU limit of container `service` goes from 1 to 2.
- Each changed `resources` block gets a comment with the measured value and #4991. The requests stay, except the Grafana memory request.
- Tempo stays at 2Gi (7 d peak 76%). The near-limit rule of #4993 watches it.
- Tests: `tests/commands/k8s/test_k8s.py`, `tests/ai/benchmark/test_k8s_llm_gateway.py` and `tests/server/routes/test_k8s_roadmap_service.py` hold the new values.
- The change carries spec deltas, because a manifest is observable: the new capability `workload-resource-limits` holds the memory limits and the exporter CPU limits, and `roadmap-service-deployment` changes the CPU limit of its requirement "The Service container has memory for the observed growth".
- The change fits one pull request.
- Rollout: Argo CD syncs the manifests from `main`. Each changed pod restarts once. No ConfigMap key changes. Nobody changes the cluster by hand.

## Capabilities

### New Capabilities

- `workload-resource-limits`: The memory limits have room above the measured peak; the exporter CPU limits do not throttle a scrape

### Modified Capabilities

- `roadmap-service-deployment`: The Service container has memory for the observed growth

## Impact

- Manifests: `k8s/monitoring/grafana-values.yaml`, `k8s/llm/gateway/deployment.yaml`, `k8s/monitoring/k8s-monitoring-values.yaml`, `k8s/llm/valkey.yaml`, `k8s/llm/valkey-devops.yaml`, `k8s/argocd/values.yaml`, `k8s/devops/roadmap-service/deployment.yaml`
- Tests: `tests/commands/k8s/test_k8s.py`, `tests/ai/benchmark/test_k8s_llm_gateway.py`, `tests/server/routes/test_k8s_roadmap_service.py`
- Scheduling: only the Grafana memory request grows (by 256Mi). Limits are not reserved on a node. Each node had 21 GiB or more of allocatable memory that no running pod requests.

## Feasibility

- The values were read again from Prometheus on 2026-11-12, through the Grafana datasource, with no write to the cluster.
- `max_over_time(container_memory_working_set_bytes[7d])` against `kube_pod_container_resource_limits`: Grafana 1014 MiB of 1024 MiB (99%), `litellm` 1333 MiB of 2048 MiB (65%), `alloy-metrics` 737 MiB of 1024 MiB (72%), `alloy-logs` 342 MiB of 512 MiB (67%).
- `increase(container_cpu_cfs_throttled_periods_total[7d]) / increase(container_cpu_cfs_periods_total[7d])`: `redis-exporter` of `valkey` 69%, of `valkey-devops` 52%, the Argo CD exporter (`metrics` of `argocd-redis`) 57%, node-exporter 29%, `service` of `roadmap-service` 8%. The peak 1-minute CPU rate of the exporters is 2m to 21m and of node-exporter 33m.
- The 7 d median scrape takes 0.19 s to 0.46 s for the Valkey exporters, 0.25 s for the Argo CD exporter and up to 1.9 s for node-exporter, against 0.008 s for the Prometheus self scrape.
- `max_over_time(rate(container_cpu_usage_seconds_total{container="service"}[2m])[7d:1m])` is 1.00 core at a limit of 1.
- The live limits match git: `kube_pod_container_resource_limits` reads 1 GiB (Grafana), 2 GiB (`litellm`), 1 GiB (`alloy-metrics`), 512 MiB (`alloy-logs`), 0.1 CPU (each exporter), 0.2 CPU (node-exporter) and 1 CPU (`service`). Argo CD syncs `main` with self-heal, so a change in git is the only change that stays.
- The first run of the changed tests on the base fails for the right reason: `['100m', '100m'] != ['500m', '500m']`, `('768Mi', '3Gi', '100m', '1') != ('768Mi', '3Gi', '100m', '2')`, and the gateway tuple without `4Gi`.
- Documents that name the old values: `git grep` finds only `openspec/specs/roadmap-service-deployment/spec.md` (the CPU limit `1`), which the delta changes. `k8s/README.md` names the memory of the Service, not its CPU limit, and names no limit of the other containers.

## Existing Tool Considered

KRR (robusta-dev/krr, MIT) recommends requests and limits from Prometheus history. #4992 adopts it for every container after this item. This item changes only the limits that the 7 d data already shows are too low, so it does not wait for #4992. The Vertical Pod Autoscaler needs a new controller and changes requests in the cluster, but the homelab keeps every request in git (Argo CD with prune and self-heal). The change deletes no internal code.

## Dependencies

None. #4993 (workload alerts) and #4992 (KRR) come after this item.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## MODIFIED Requirements

### Requirement: The Service container has memory for the observed growth
Container `service` of `deployment/roadmap-service` SHALL request `768Mi` of memory and limit it to `3Gi`, and SHALL keep the CPU request `100m` with a CPU limit of `2`. The memory limit SHALL be at least 460 MiB plus 10 hours of growth at 150 MiB each hour, so the alert `RoadmapServiceMemoryNearLimit` fires before a kill. The comment above `resources` SHALL say that the memory raise is a stopgap and SHALL link #4116 and #4125.

#### Scenario: The manifest is read
- **WHEN** `k8s/devops/roadmap-service/deployment.yaml` is read
- **THEN** the resources of container `service` are a memory request of `768Mi`, a memory limit of `3Gi`, a CPU request of `100m` and a CPU limit of `2`

#### Scenario: The limit is cut
- **WHEN** the memory limit of container `service` is below 460 MiB plus 10 times 150 MiB
- **THEN** the test fails and its message names #4116
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Purpose
The resource limits of the long-running workloads in the cluster manifests: each limit has room above the peak use that Prometheus measured over 7 days, so the kernel does not kill a container for memory and CFS does not throttle a container that uses only a few millicores.

## ADDED Requirements

### Requirement: The memory limits have room above the measured peak
The manifests SHALL give Grafana (`k8s/monitoring/grafana-values.yaml`) a memory request of `512Mi` and a memory limit of `2Gi`, the container `litellm` of `deployment/llm-gateway` (`k8s/llm/gateway/deployment.yaml`) a memory limit of `4Gi`, and the collectors of `k8s/monitoring/k8s-monitoring-values.yaml` the memory limits `1536Mi` (`alloy-metrics`) and `768Mi` (`alloy-logs`). The other requests and limits of these containers SHALL stay.

#### Scenario: The monitoring manifests are read
- **WHEN** `k8s/monitoring/grafana-values.yaml` and `k8s/monitoring/k8s-monitoring-values.yaml` are read
- **THEN** Grafana requests `100m` of CPU and `512Mi` of memory and limits them to `500m` and `2Gi`, `alloy-metrics` limits its memory to `1536Mi`, and `alloy-logs` limits its memory to `768Mi`

#### Scenario: The gateway manifest is read
- **WHEN** `k8s/llm/gateway/deployment.yaml` is read
- **THEN** the first container of the Deployment requests `200m` of CPU and limits it to `1000m`, and limits its memory to `4Gi`

### Requirement: The exporter CPU limits do not throttle a scrape
The `redis-exporter` sidecars of the Deployments `valkey` and `valkey-devops` in `k8s/llm/`, the Valkey exporter of Argo CD (`redis.exporter` in `k8s/argocd/values.yaml`) and node-exporter (`telemetryServices.node-exporter` in `k8s/monitoring/k8s-monitoring-values.yaml`) SHALL have a CPU limit of `500m`. Their CPU requests SHALL stay.

#### Scenario: The exporter manifests are read
- **WHEN** `k8s/llm/valkey.yaml`, `k8s/llm/valkey-devops.yaml`, `k8s/argocd/values.yaml` and `k8s/monitoring/k8s-monitoring-values.yaml` are read
- **THEN** each of the four exporters has a CPU limit of `500m`
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Tasks

## 1. Hold the measured limits in the tests

Kind: other

Reads: `tests/commands/k8s/test_k8s.py`, `tests/ai/benchmark/test_k8s_llm_gateway.py`, `tests/server/routes/test_k8s_roadmap_service.py`. Changes: `tests/commands/k8s/test_k8s.py`, `tests/ai/benchmark/test_k8s_llm_gateway.py`, `tests/server/routes/test_k8s_roadmap_service.py`.

- [x] 1.1 In `test_k8s_workload_resource_limits_and_probes`, hold the CPU limit `500m` of the three Valkey exporters and node-exporter, the memory limits `1536Mi` (`alloy-metrics`) and `768Mi` (`alloy-logs`), and the Grafana resources (request `100m` and `512Mi`, limit `500m` and `2Gi`). Hold the gateway memory limit `4Gi` and the Service CPU limit `2`. See the three tests fail on the base
- Verification: `$ uv run devops ci fail-to-pass --base origin/main`

## 2. Raise the limits in the manifests

Kind: other

Reads: `k8s/monitoring/grafana-values.yaml`, `k8s/llm/gateway/deployment.yaml`, `k8s/monitoring/k8s-monitoring-values.yaml`, `k8s/llm/valkey.yaml`, `k8s/llm/valkey-devops.yaml`, `k8s/argocd/values.yaml`, `k8s/devops/roadmap-service/deployment.yaml`. Changes: the same files.

- [x] 2.1 Set the values of the table of #4991, and write above each changed `resources` block a comment with the measured value and #4991. In the gateway comment, say not to set `MAX_REQUESTS_BEFORE_RESTART`
- Verification: `$ uv run devops ci test tests/commands/k8s/test_k8s.py tests/ai/benchmark/test_k8s_llm_gateway.py tests/server/routes/test_k8s_roadmap_service.py`
- [x] 2.2 Check the rendered manifests and the change
- Verification: `$ uv run devops ci --check --only k8s,openspec`

## Workflow follow-up

- Pending a person: 7 d after the merge, read the peak working set against the new limit and the throttled share of each container, and record them in a comment on the pull request.
- #4992 sizes every container with KRR, and #4993 adds the workload alerts. Both come after this item.
4 changes: 2 additions & 2 deletions openspec/specs/roadmap-service-deployment/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ The ConfigMap template `k8s/devops/configmap.example.yaml` SHALL name `deepseek-
- **THEN** they name #4204, the date 2026-11-09, the cost of 0.27 USD for each stage case, and #3874 as the rule to return to

### Requirement: The Service container has memory for the observed growth
Container `service` of `deployment/roadmap-service` SHALL request `768Mi` of memory and limit it to `3Gi`, and SHALL keep the CPU request `100m` and the CPU limit `1`. The memory limit SHALL be at least 460 MiB plus 10 hours of growth at 150 MiB each hour, so the alert `RoadmapServiceMemoryNearLimit` fires before a kill. The comment above `resources` SHALL say that the raise is a stopgap and SHALL link #4116 and #4125.
Container `service` of `deployment/roadmap-service` SHALL request `768Mi` of memory and limit it to `3Gi`, and SHALL keep the CPU request `100m` with a CPU limit of `2`. The memory limit SHALL be at least 460 MiB plus 10 hours of growth at 150 MiB each hour, so the alert `RoadmapServiceMemoryNearLimit` fires before a kill. The comment above `resources` SHALL say that the memory raise is a stopgap and SHALL link #4116 and #4125.

#### Scenario: The manifest is read
- **WHEN** `k8s/devops/roadmap-service/deployment.yaml` is read
- **THEN** the resources of container `service` are a memory request of `768Mi`, a memory limit of `3Gi`, a CPU request of `100m` and a CPU limit of `1`
- **THEN** the resources of container `service` are a memory request of `768Mi`, a memory limit of `3Gi`, a CPU request of `100m` and a CPU limit of `2`

#### Scenario: The limit is cut
- **WHEN** the memory limit of container `service` is below 460 MiB plus 10 times 150 MiB
Expand Down
Loading