# Ollama / Open WebUI → Kubernetes migration plan ## Current state - Ollama runs on the workstation `pop-os` as a systemd service (`/usr/local/bin/ollama serve`). - It listens on `0.0.0.0:11434`. - Local models are stored under `/usr/share/ollama/.ollama/models` (≈ 24 GB). The Kubernetes Ollama instance will **not** use these; it will use **Ollama Cloud models only**. - The GPU is an NVIDIA GeForce RTX 2070 (8 GB VRAM) on `pop-os` — it stays on the workstation; Kubernetes has no GPU. - The Kubernetes cluster currently runs on three Hetzner nodes with **no GPU** and **no NVIDIA device plugin**. - Open WebUI runs on `pop-os` as a Docker container (`open-webui`), image `ghcr.io/open-webui/open-webui:main`, exposing host port `3000` mapped to container port `8080`. - Open WebUI stores data in a Docker volume (`/var/lib/docker/volumes/open-webui/_data`, ≈ 1.4 GB) mounted at `/app/backend/data`. - Current Open WebUI points to Ollama at `OLLAMA_BASE_URL=/ollama` via `host.docker.internal`. - The Kubernetes cluster has an existing PostgreSQL instance (`postgres-hetzner` in the `database` namespace) with pgvector support. ## Goal Move Ollama and Open WebUI into the existing Kubernetes cluster: - Ollama will run **CPU-only** on the Hetzner nodes and use **Ollama Cloud models only**. - Ollama is exposed **only inside the cluster** (Service `ollama.ollama.svc.cluster.local:11434`), no Ingress. - Open WebUI is exposed on `chat.mariushome.lt` via Cilium dedicated LB Ingress. - Open WebUI connects to the in-cluster Ollama service and uses the existing PostgreSQL for its main database and pgvector RAG store. - This is a **fresh start** for Open WebUI data: existing chats/settings on `pop-os` are not migrated to PostgreSQL. - `pop-os` Ollama will be shut down after the migration. ## Important limitation / warning The Hetzner worker nodes have only **~7.8 GB allocatable memory** and the master only **~3.8 GB**. Because Kubernetes Ollama uses **Ollama Cloud models only**, it does not download or run large models locally, so the small CPU/memory footprint is safe. If you later want to run local models in Kubernetes, you must add a larger/GPU node. ## Manifests added All manifests are in `Ollama/`: | File | Purpose | |------|---------| | `ollama_namespace.yaml` | `ollama` namespace (shared) | | `ollama_pvc.yaml` | PVC for Ollama state on `slow` StorageClass | | `ollama_secret_example.yaml` | Example Secret for `OLLAMA_API_KEY` (do NOT commit) | | `ollama_deployment.yaml` | CPU-only Ollama Deployment with cloud API key + PVC | | `ollama_service.yaml` | ClusterIP Service `ollama:11434` | | `openwebui_secret_example.yaml` | Example Secret with admin credentials and DB URLs (do NOT commit) | | `openwebui_db_setup.yaml` | One-time Job to create the `openwebui` DB/user in PostgreSQL | | `openwebui_deployment.yaml` | Open WebUI Deployment (PostgreSQL + pgvector) | | `openwebui_service.yaml` | ClusterIP Service `open-webui:8080` | | `openwebui_ingress.yaml` | Cilium dedicated LB ingress `chat.mariushome.lt` | | `openwebui_imagegen_config.yaml` | ConfigMap `openwebui-imagegen` — enables ComfyUI image generation (see below) | ## Image generation (ComfyUI on pop-os) Image generation runs on the `pop-os` workstation (RTX 2070, 8 GB) where ComfyUI listens on `http://192.168.8.28:8188`. The cluster reaches it over the home-gw / WireGuard route: every node has a route for `192.168.8.0/24` (master via `wg0`, workers via `home-gw` with SNAT `10.0.0.0/8 → 169.254.8.x`), so pods can connect directly. No tunnel or master proxy is needed. - `openwebui_imagegen_config.yaml` (`openwebui-imagegen` ConfigMap) sets `ENABLE_IMAGE_GENERATION=true`, `IMAGE_GENERATION_ENGINE=comfyui`, `IMAGE_GENERATION_MODEL=qwen-image`, `IMAGE_SIZE`, `IMAGE_STEPS`, and the full `COMFYUI_WORKFLOW` / `COMFYUI_WORKFLOW_NODES` (Qwen-Image 2512 + Lightning 4-step txt2img). - `openwebui_deployment.yaml` consumes it via `envFrom.configMapRef`. - **PersistentConfig caveat:** Open WebUI stores `image_generation.*` in the `config` table of the `openwebui` Postgres DB, and **DB values override env**. Setting the ConfigMap alone is not enough on an existing install — the DB rows must match too. Either use Admin → Settings → Images, or update the DB: ```bash POD=$(kubectl -n database get pods -l app=postgres-hetzner -o jsonpath='{.items[0].metadata.name}') kubectl -n database exec $POD -- sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -U "${POSTGRES_USER:-admin}" -d openwebui' <<'SQL' UPDATE config SET value='true'::json WHERE key='image_generation.enable'; UPDATE config SET value=to_json('comfyui'::text) WHERE key='image_generation.engine'; UPDATE config SET value=to_json('qwen-image'::text) WHERE key='image_generation.model'; UPDATE config SET value=to_json('http://192.168.8.28:8188'::text) WHERE key='image_generation.comfyui.base_url'; SQL ``` - Requirements on pop-os: ComfyUI bound to the LAN (`--listen ...,192.168.8.28`, handled by `comfy-mode`), static IP `192.168.8.28`, and the machine powered on (generation fails while it is offline/asleep). ## Storage ### Ollama Kubernetes Ollama uses **Ollama Cloud models only**, so no model blobs are stored locally. The Deployment mounts a PVC (`slow` StorageClass) at `/root/.ollama` to persist the Ollama Cloud login session / API key state across pod restarts. ### Ollama Cloud authentication Ollama Cloud models require authentication. Two options: 1. **API key (recommended for Kubernetes)**: create an API key at https://ollama.com/settings/keys, then create the `ollama-cloud` Secret from `ollama_secret_example.yaml`. The Deployment injects `OLLAMA_API_KEY` automatically. 2. **Interactive signin**: exec into the pod and run `ollama signin`: ```bash kubectl -n ollama exec -it deploy/ollama -- ollama signin ``` Because `/root/.ollama` is now persisted on a PVC, the session survives pod restarts. ### Open WebUI Open WebUI uses the existing PostgreSQL (`postgres-hetzner.database.svc.cluster.local:5432`) for both the main relational database and the pgvector vector store. Uploaded files are still written to `/app/backend/data`, but since this is a fresh install, an `emptyDir` is sufficient. If you later want persistence for uploads, create a small PVC using the **`slow`** StorageClass (SMB CSI — the cluster default). Do **not** use `hcloud-volumes` for Open WebUI uploads. Example: ```yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: open-webui-uploads namespace: ollama spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi storageClassName: slow ``` ## Pre-deployment database setup 1. The existing `postgres-secret` in the `database` namespace already contains the superuser password, so no new Secret is needed. 2. Edit `Ollama/openwebui_db_setup.yaml` and replace the placeholder password `openwebui-password` in the `CREATE USER` statement with a strong, unique password. 3. Create the database and user: ```bash kubectl apply -f Ollama/openwebui_db_setup.yaml kubectl wait job/openwebui-db-setup -n database --for=condition=complete kubectl delete -f Ollama/openwebui_db_setup.yaml ``` If the user/database already exists from a previous run with the old password, drop them first (requires the postgres superuser): ```bash kubectl run -it --rm -n database psql-cleanup --image=rg.mariushome.lt/custom-postgres --restart=Never --env="PGUSER=admin" --env="PGPASSWORD=$(kubectl get secret -n database postgres-secret -o jsonpath='{.data.POSTGRES_PASSWORD}' | base64 -d)" -- psql -h postgres.database.svc.cluster.local -d postgres -c "DROP DATABASE IF EXISTS openwebui; DROP USER IF EXISTS openwebui;" ``` ## Secret creation (interactive) The `openwebui-secret` must be created out-of-band because it contains passwords. Use the helper script and enter the same password you set in `openwebui_db_setup.yaml`: ```bash ./Ollama/create_openwebui_secret.sh ``` Or create it manually, replacing `YOUR-OPENWEBUI-DB-PASSWORD` with the password from `openwebui_db_setup.yaml`: ```bash kubectl create secret generic -n ollama openwebui-secret \ --from-literal=WEBUI_SECRET_KEY="977a7a4e9051d31575f17ed7610c7bf7f9af9475205cc636ead271e699f1a680" \ --from-literal=WEBUI_ADMIN_EMAIL="admin@mariushome.lt" \ --from-literal=WEBUI_ADMIN_PASSWORD="fsbubSHADBJKASDs4s4ds5" \ --from-literal=DATABASE_URL="postgresql://openwebui:YOUR-OPENWEBUI-DB-PASSWORD@postgres-hetzner.database.svc.cluster.local:5432/openwebui" \ --from-literal=PGVECTOR_DB_URL="postgresql://openwebui:YOUR-OPENWEBUI-DB-PASSWORD@postgres-hetzner.database.svc.cluster.local:5432/openwebui" ``` ## Rollout steps 1. Recreate the `openwebui` database/user with the new password (see "Pre-deployment database setup" above). 2. Create the Open WebUI namespace: ```bash kubectl apply -f Ollama/ollama_namespace.yaml ``` 3. Create the `openwebui-secret` interactively (see "Secret creation" above) using the new password. 4. Create the Ollama PVC and (optionally) cloud Secret: ```bash # PVC for /root/.ollama state kubectl apply -f Ollama/ollama_pvc.yaml # Optional: if using an Ollama Cloud API key, create the Secret first: # (Get your key from https://ollama.com/settings/keys) kubectl apply -f Ollama/ollama_secret_example.yaml ``` 5. Apply Ollama manifests: ```bash kubectl apply -f Ollama/ollama_service.yaml kubectl apply -f Ollama/ollama_deployment.yaml ``` 6. Verify Ollama is running and accessible inside the cluster: ```bash kubectl -n ollama get pods -o wide kubectl -n ollama logs -f deploy/ollama kubectl -n ollama exec -it deploy/ollama -- ollama list ``` 7. Apply Open WebUI manifests: ```bash kubectl apply -f Ollama/openwebui_service.yaml kubectl apply -f Ollama/openwebui_deployment.yaml kubectl apply -f Ollama/openwebui_ingress.yaml ``` 8. Verify: ```bash kubectl -n ollama get pods -o wide kubectl -n ollama logs -f deploy/open-webui kubectl -n ollama get ingress ``` 9. Update DNS for `chat.mariushome.lt` to point to the Cilium LB IP assigned to the `open-webui` Ingress. 10. After confirming Open WebUI works on `chat.mariushome.lt`, shut down the local `pop-os` services (keep the Docker volume as a backup): ```bash sudo systemctl stop ollama sudo systemctl disable ollama docker stop open-webui # Keep the volume for backup; only remove the container. docker rm open-webui ``` ## Client / consumer reconfiguration - Update Open WebUI access from `http://pop-os:3000` to `http://chat.mariushome.lt`. - Ollama consumers inside the cluster should use `http://ollama.ollama.svc.cluster.local:11434`. No external Ollama endpoint is exposed. - For OpenCode, change the Ollama host to `http://ollama.ollama.svc.cluster.local:11434` if OpenCode runs inside the cluster, or use the Open WebUI endpoint externally. ## Important security notes - Ollama is **not exposed via Ingress**; it is reachable only inside the cluster. - Open WebUI is exposed on `chat.mariushome.lt` inside the LAN. Do not publish it to the public Internet without an authenticating proxy. - Signups are disabled (`ENABLE_SIGNUP=false`). The initial admin account is bootstrapped from the Secret. - `openwebui_secret_example.yaml` and `openwebui_db_setup.yaml` contain sensitive values and must be created out-of-band; do not commit them. ## Rollback ```bash kubectl delete -f Ollama/openwebui_ingress.yaml kubectl delete -f Ollama/openwebui_deployment.yaml kubectl delete -f Ollama/openwebui_service.yaml kubectl delete -f Ollama/ollama_deployment.yaml kubectl delete -f Ollama/ollama_service.yaml # Restart local services on pop-os if needed: sudo systemctl start ollama docker start open-webui ``` ## Decisions made - The `openwebui` PostgreSQL user must use a **different password than the example `openwebui-password`**. Edit `openwebui_db_setup.yaml`, replace the password in the `CREATE USER` statement, and re-run the Job to recreate the user/database before creating the `openwebui-secret`. - The `pop-os` Open WebUI Docker data (`/var/lib/docker/volumes/open-webui/_data`, ≈ 1.4 GB) will be **kept as a backup** after shutdown. Do not delete the Docker volume when stopping the container.