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
5 changes: 5 additions & 0 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ High-density product roadmap, engineering milestones, and open-source integratio
- *Context & Rationale*: `api_base_url` outranked `gateway_url` and every task inherited the global value. A task on `provider: gateway` under a global OpenAI setup sent its requests and the gateway master key to OpenAI. Any task switching provider sent its key to the global provider's endpoint, and the pydantic-ai bridge resolved `litellm:` models the same way.
- *Delivered*: Provider `gateway` always sends to `gateway_url`, and a gateway task's own `api_base_url` becomes that task's gateway address. The global `api_base_url` carries over only to tasks that keep the global provider. The bridge's `litellm:`, `portkey:` and `lightllm:` prefixes use `gateway_url`, `portkey_url` and `lightllm_url`.

- [x] **One Gateway Deployment per Ollama Node (`#463`) (P2 - Medium)**:
- *Context & Rationale*: Through the `ollama` Service, LiteLLM's long-lived connections pinned all gateway traffic to one Ollama pod: in a full review, one node served 15 requests and the other 0. With one deployment covering every node, LiteLLM could neither match load to each node's single request slot nor cool down a failing node on its own.
- *Delivered*: Ollama runs as a StatefulSet (`k8s/llm/ollama.yaml`) with per-pod DNS through the headless `ollama-nodes` Service and one pod per GPU node. The gateway lists every pod for `devops-chat`, `devops-embedding`, the Ollama tier of `devops-review` and `ollama/*`. Embedding deployments are health-checked as embeddings, and the wildcard with a real model.
- *Remaining*: `replicas` and the gateway's per-pod entries are set by hand to match the number of Ollama GPU nodes; a test keeps them in step.

### Reactive Workstation Command Center, Interactive TUI & Unified Operations Hub (v0.2.24 - Scheduled)
- [ ] **Reactive Multi-Workspace Textual TUI Architecture & Master-Detail Navigation (`devops dashboard`, `devops tui`) (P0 - Critical)**:
- *Context & Rationale*: Modernizes the basic Textual dashboard from static read-only tables into a reactive, multi-workspace workstation command center with non-blocking async workers (`work()`), real-time push events, and master-detail ergonomic split screens (navigation tree/list on left, contextual detail inspector with YAML/logs/markdown on right).
Expand Down
65 changes: 65 additions & 0 deletions docs/agent/tasks/task-463-ollama-per-node-routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Task 463: One Gateway Deployment per Ollama Node

**Issue**: [#463](https://github.com/dan-petty/devops-cli/issues/463)
**PR**: [#464](https://github.com/dan-petty/devops-cli/pull/464)
**Status**: In Review
**Milestone**: `v0.2.23`
**Priority**: `priority/p2-medium`
**Scope**: `type/feature`, `scope/k8s`, `scope/ai`, `priority/p2-medium`

---

## 1. Description & Objectives

The gateway reached Ollama through the `ollama` Service. kube-proxy balances per TCP connection
and LiteLLM keeps its connections open, so all gateway traffic to Ollama went to whichever pod
the first connections landed on. In a full review, one Ollama node served 15 requests and the
other served 0. Because every Ollama node sat behind one gateway deployment, LiteLLM could not
match load to each node's single request slot (`OLLAMA_NUM_PARALLEL=1`), and it could not cool
down a failing node without cooling down all of them.

The gateway's health report was also wrong. `devops-embedding` was reported unhealthy because it
was probed with a generate call, and the `ollama/*` wildcard was probed with a placeholder model.

### Key Deliverables Completed:

- [x] **Ollama StatefulSet** (`k8s/llm/ollama.yaml`, formerly `ollama-daemonset.yaml`): pods
get stable DNS names through the headless `ollama-nodes` Service. Required pod anti-affinity
keeps one pod per GPU node, and `podManagementPolicy: Parallel` stops an offline node from
blocking the others. Architecture affinity, `hostPort`, node-local `hostPath` models and the
`ollama` NodePort Service are unchanged.
- [x] **Per-Pod Gateway Deployments**: `devops-chat`, `devops-embedding`, the Ollama tier of
`devops-review` and the `ollama/*` pass-through each list every pod. Review entries take
`max_parallel_requests: 1`, matching `OLLAMA_NUM_PARALLEL`. `devops-chat` moves to
`ollama_chat/`, the same chat endpoint the review tier uses.
- [x] **Health Checks**: `mode: embedding` for embedding deployments, and a real
`health_check_model` for the wildcard.
- [x] **Automated Tests & Quality Gates**:
- `tests/test_k8s_llm_gateway.py`: per-pod deployments track the StatefulSet's replica count
and `OLLAMA_NUM_PARALLEL`; the headless Service, anti-affinity and shared Service; health
check modes; review windows per pod.
- `tests/test_k8s.py`, `tests/test_k8s_squid.py`: probes, storage and proxy settings on the
StatefulSet.
- 100% passing status across Gated CI validation suite (`uv run devops ci`).

## 2. Rollout

The DaemonSet holds host port 11434, so it must be deleted before the StatefulSet can start:

```bash
kubectl -n llm delete daemonset ollama
kubectl apply -f k8s/llm/ollama.yaml
kubectl -n llm rollout status statefulset/ollama
kubectl apply -f k8s/llm/gateway/configmap.yaml
kubectl -n llm rollout restart deployment/llm-gateway
```

Models stay on each node's `hostPath`, so nothing is downloaded again.

## 3. Verification on a Live Cluster

After the rollout, one pod ran on each Ollama node, and both still had their models. Gateway
`/health` reported all 12 deployments healthy and none unhealthy. Before, `devops-embedding` and
the wildcard were reported unhealthy. Of eight concurrent `devops-chat` requests, one node served
five and the other three. Before the change, a full review sent 15 requests to one node and 0 to
the other.
2 changes: 1 addition & 1 deletion docs/cheatsheets/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Compare standard `kubectl`, `helm`, and `kustomize` workflows with unified `devo
| Action / Goal | Original Command (`kubectl`) | `devops-cli` Command | Key Enhancements in `devops-cli` |
| :--- | :--- | :--- | :--- |
| **List Stack Pods** | `kubectl get pods -A -l app.kubernetes.io/part-of=devops-cli-stack` | `devops k8s pods [-n <namespace>]` | Color-coded status tables highlighting crashloops, restart counts, and container resource limits. |
| **Check Stack Health** | Multiple `kubectl get svc,deploy,ds,statefulsets` | `devops k8s status [-c <context>]` | Complete health audit evaluating DaemonSets (Ollama GPUs), deployments, and ingress reachability. |
| **Check Stack Health** | Multiple `kubectl get svc,deploy,ds,statefulsets` | `devops k8s status [-c <context>]` | Complete health audit evaluating StatefulSets (Ollama GPUs), deployments, and ingress reachability. |
| **Auto-Detect Service Endpoints** | `kubectl get svc -A -o jsonpath=...` | `devops k8s configure-urls [-c <context>]` | Discovers cluster IP/NodePort/hostPort targets and automatically updates local `devops config` settings. |

---
Expand Down
2 changes: 1 addition & 1 deletion docs/squid-failover-and-observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ graph TD
end

subgraph "Client Workloads"
ollama["Ollama GPU DaemonSet<br/>(llm namespace)"]
ollama["Ollama GPU StatefulSet<br/>(llm namespace)"]
end

ollama -->|"HTTP_PROXY (port 3128)"| squid
Expand Down
4 changes: 2 additions & 2 deletions k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ Inference engines are placed by GPU architecture, using node labels from NVIDIA
| :--- | :--- | :--- | :--- | :--- |
| `vllm` Deployment | 2+ Ampere-or-newer GPUs | Qwen2.5-Coder-32B-Instruct-AWQ, tensor parallel 2, 64K context (YaRN) | `qwen2.5-coder-32b-instruct` | `devops-reasoning` |
| `vllm-single` Deployment | 1 Ampere-or-newer GPU with 16 GiB+ | Qwen2.5-Coder-14B-Instruct-AWQ, FP8 KV cache, 16K context | `qwen2.5-coder-14b-instruct` | `devops-coder` |
| `ollama` DaemonSet | GPUs older than Ampere | Pulled on demand | Ollama model tags | `devops-chat`, `devops-embedding` |
| `ollama` StatefulSet, one pod per node | GPUs older than Ampere | Pulled on demand | Ollama model tags | `devops-chat`, `devops-embedding`, `ollama/*` |

Both vLLM Deployments keep weights on a PersistentVolumeClaim (`vllm-model-cache`, `vllm-single-model-cache`), download through the Squid proxy (trusting its CA, with Hugging Face Xet transfers disabled because they fail through SSL bumping), and are reachable only inside the cluster, through the gateway. A vLLM pod stays `Pending` until a node carries matching GPU labels. The first start downloads the weights, which can take hours on a home connection; the startup probe allows 3 hours before restarting the pod. The Ollama-backed aliases expect `qwen2.5-coder:7b` and `bge-m3` on every Ollama node, since the `ollama` Service balances across them (`ollama pull qwen2.5-coder:7b`).
Both vLLM Deployments keep weights on a PersistentVolumeClaim (`vllm-model-cache`, `vllm-single-model-cache`), download through the Squid proxy (trusting its CA, with Hugging Face Xet transfers disabled because they fail through SSL bumping), and are reachable only inside the cluster, through the gateway. A vLLM pod stays `Pending` until a node carries matching GPU labels. The first start downloads the weights, which can take hours on a home connection; the startup probe allows 3 hours before restarting the pod. The gateway lists each Ollama pod (`ollama-<n>.ollama-nodes`) as its own deployment, so it balances load and cools down failures per node. Through the `ollama` Service, LiteLLM's long-lived connections would pin every request to one pod. The Ollama-backed aliases therefore expect `qwen2.5-coder:7b`, `bge-m3` and `gpt-oss:20b` on every Ollama node (`ollama pull qwen2.5-coder:7b`). Set `replicas` in `llm/ollama.yaml` to the number of GPU nodes Ollama may use, and keep one gateway entry per replica in `llm/gateway/configmap.yaml`. A replica with no node to run on stays `Pending`, and requests sent to it fail over to the other nodes.

## Port Forwarding & Automated Configuration

Expand Down
52 changes: 44 additions & 8 deletions k8s/llm/gateway/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ metadata:
app.kubernetes.io/part-of: devops-cli-stack
data:
config.yaml: |
# Ollama-backed groups list every Ollama pod (ollama-<n>.ollama-nodes, one per GPU node) as
# its own deployment, so LiteLLM balances load and cools down failures per node. Through the
# `ollama` Service its long-lived connections would pin all traffic to one pod. Keep one
# entry per replica of k8s/llm/ollama.yaml.
model_list:
- model_name: devops-chat
litellm_params:
model: ollama/qwen2.5-coder:7b
api_base: http://ollama.llm.svc.cluster.local:11434
model: ollama_chat/qwen2.5-coder:7b
api_base: http://ollama-0.ollama-nodes.llm.svc.cluster.local:11434
- model_name: devops-chat
litellm_params:
model: ollama_chat/qwen2.5-coder:7b
api_base: http://ollama-1.ollama-nodes.llm.svc.cluster.local:11434
- model_name: devops-coder
litellm_params:
model: openai/qwen2.5-coder-14b-instruct
Expand All @@ -31,10 +39,19 @@ data:
# Prompt budget inside the 64K vLLM window, leaving 4K tokens for the reply.
model_info:
max_input_tokens: 61440
# mode: embedding makes health checks embed rather than generate, which bge-m3 rejects.
- model_name: devops-embedding
litellm_params:
model: ollama/bge-m3
api_base: http://ollama-0.ollama-nodes.llm.svc.cluster.local:11434
model_info:
mode: embedding
- model_name: devops-embedding
litellm_params:
model: ollama/bge-m3
api_base: http://ollama.llm.svc.cluster.local:11434
api_base: http://ollama-1.ollama-nodes.llm.svc.cluster.local:11434
model_info:
mode: embedding

# devops-review: one virtual model spread over every inference server, so a review's
# parallel persona and verification calls use all of them. least-busy routing plus
Expand All @@ -58,23 +75,42 @@ data:
max_parallel_requests: 2
model_info:
max_input_tokens: 12288
# One request at a time per Ollama node (OLLAMA_NUM_PARALLEL=1). max_input_tokens is
# OLLAMA_CONTEXT_LENGTH (48000) minus 4K tokens for the reply.
- model_name: devops-review
litellm_params:
model: ollama_chat/gpt-oss:20b
api_base: http://ollama.llm.svc.cluster.local:11434
# One request per Ollama node (OLLAMA_NUM_PARALLEL=1); raise with the node count.
max_parallel_requests: 2
# OLLAMA_CONTEXT_LENGTH (48000) minus 4K tokens for the reply.
api_base: http://ollama-0.ollama-nodes.llm.svc.cluster.local:11434
max_parallel_requests: 1
model_info:
max_input_tokens: 43904
- model_name: devops-review
litellm_params:
model: ollama_chat/gpt-oss:20b
api_base: http://ollama-1.ollama-nodes.llm.svc.cluster.local:11434
max_parallel_requests: 1
model_info:
max_input_tokens: 43904

# Pass-through: any model on the Ollama nodes by name, e.g. `ollama/gpt-oss:20b`. Ollama's
# OpenAI-compatible API serves both chat (with the model's own template) and embeddings.
# A model pulled on only some nodes still answers: a node without it fails, and the retry
# moves to another node. Health checks need a concrete model; without one LiteLLM probes a
# placeholder that no node has.
- model_name: ollama/*
litellm_params:
model: openai/*
api_base: http://ollama.llm.svc.cluster.local:11434/v1
api_base: http://ollama-0.ollama-nodes.llm.svc.cluster.local:11434/v1
api_key: none
model_info:
health_check_model: openai/qwen2.5-coder:7b
- model_name: ollama/*
litellm_params:
model: openai/*
api_base: http://ollama-1.ollama-nodes.llm.svc.cluster.local:11434/v1
api_key: none
model_info:
health_check_model: openai/qwen2.5-coder:7b

router_settings:
routing_strategy: least-busy
Expand Down
2 changes: 1 addition & 1 deletion k8s/llm/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resources:
- networkpolicy.yaml
- ca-configmap.yaml
- valkey.yaml
- ollama-daemonset.yaml
- ollama.yaml
- gateway/configmap.yaml
- gateway/deployment.yaml
- gateway/service.yaml
Expand Down
44 changes: 43 additions & 1 deletion k8s/llm/ollama-daemonset.yaml → k8s/llm/ollama.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Ollama serves GPUs older than Ampere, one pod per GPU node. A StatefulSet rather than a
# DaemonSet gives each pod a stable DNS name (ollama-<n>.ollama-nodes), so the gateway can list
# every node as its own deployment: through the `ollama` Service, LiteLLM's long-lived
# connections pin all gateway traffic to one pod.
apiVersion: apps/v1
kind: DaemonSet
kind: StatefulSet
metadata:
name: ollama
namespace: llm
Expand All @@ -8,6 +12,12 @@ metadata:
app.kubernetes.io/instance: ollama
app.kubernetes.io/part-of: devops-cli-stack
spec:
# One per GPU node that Ollama may use. Keep one gateway deployment per replica in
# gateway/configmap.yaml (devops-chat, devops-embedding and the Ollama tier of devops-review).
replicas: 2
serviceName: ollama-nodes
# Start and replace pods independently, so a node that is offline never holds up the others.
podManagementPolicy: Parallel
selector:
matchLabels:
app.kubernetes.io/name: ollama
Expand Down Expand Up @@ -35,6 +45,14 @@ spec:
- key: nvidia.com/gpu.architecture
operator: NotIn
values: [ampere, ada-lovelace, hopper, blackwell]
# One pod per node: each owns the node's GPUs, host port and model directory.
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: kubernetes.io/hostname
labelSelector:
matchLabels:
app.kubernetes.io/name: ollama
app.kubernetes.io/instance: ollama
containers:
- name: ollama
image: ollama/ollama:0.32.14
Expand Down Expand Up @@ -122,6 +140,30 @@ spec:
name: squid-ca-cert
optional: false
---
# Per-pod DNS for the gateway: ollama-<n>.ollama-nodes.llm.svc.cluster.local. Only ready pods
# resolve, so the gateway's retries skip a pod that is down.
apiVersion: v1
kind: Service
metadata:
name: ollama-nodes
namespace: llm
labels:
app.kubernetes.io/name: ollama
app.kubernetes.io/instance: ollama
app.kubernetes.io/part-of: devops-cli-stack
spec:
clusterIP: None
selector:
app.kubernetes.io/name: ollama
app.kubernetes.io/instance: ollama
ports:
- name: http
port: 11434
targetPort: 11434
protocol: TCP
---
# Any Ollama node, for clients that need no particular one (Open WebUI, port-forwards, the
# gateway's ollama/* pass-through).
apiVersion: v1
kind: Service
metadata:
Expand Down
2 changes: 1 addition & 1 deletion k8s/llm/vllm-single/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# vLLM single-GPU continuous batching inference engine for nodes with one Ampere-or-newer GPU
# (16 GiB or more). Older architectures run the Ollama DaemonSet instead.
# (16 GiB or more). Older architectures run Ollama (../ollama.yaml) instead.
---
apiVersion: apps/v1
kind: Deployment
Expand Down
2 changes: 1 addition & 1 deletion k8s/llm/vllm/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# vLLM Tensor-Parallel (TP=2) continuous batching inference engine for nodes with two or more
# Ampere-or-newer GPUs. Older architectures run the Ollama DaemonSet instead.
# Ampere-or-newer GPUs. Older architectures run Ollama (../ollama.yaml) instead.
---
apiVersion: apps/v1
kind: Deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ graph TD
- `gitops`: ArgoCD server, controller, and repo server in `argocd` namespace.
- `tracing`: Jaeger distributed tracing query & collector in `otel` namespace.
- `otel`: OpenTelemetry Collector DaemonSet/Deployment and Jaeger in `otel` namespace.
- `llm`: Local LLM stack (Ollama DaemonSet, Open-WebUI, Qdrant Vector DB, Valkey Cache) in `llm` namespace.
- `llm`: Local LLM stack (Ollama StatefulSet, Open-WebUI, Qdrant Vector DB, Valkey Cache) in `llm` namespace.
- `all`: Bootstraps all stacks (`monitoring`, `gitops`, `otel`, `llm`) with automatic port-forwarding and service URL target detection.

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ curl http://localhost:11434/api/embeddings -d '{
## 4. Best Practice Guidance & Performance Tuning

1. **Optimize Concurrency in Kubernetes / Host Daemons**:
- When deploying Ollama via Kubernetes ([`k8s/llm/ollama-daemonset.yaml`](../../../../../../k8s/llm/ollama-daemonset.yaml)), configure:
- When deploying Ollama via Kubernetes ([`k8s/llm/ollama.yaml`](../../../../../../k8s/llm/ollama.yaml)), configure:
```yaml
env:
- name: OLLAMA_NUM_PARALLEL
Expand Down
2 changes: 1 addition & 1 deletion src/devops_cli/commands/k8s/stack_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
],
"llm": [
DEFAULT_K8S_DIR / "llm" / "valkey.yaml",
DEFAULT_K8S_DIR / "llm" / "ollama-daemonset.yaml",
DEFAULT_K8S_DIR / "llm" / "ollama.yaml",
],
"logging": [
DEFAULT_K8S_DIR / "logging" / "networkpolicy.yaml",
Expand Down
Loading
Loading