10 KiB
Ollama / Open WebUI → Kubernetes migration plan
Current state
- Ollama runs on the workstation
pop-osas 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-osas a Docker container (open-webui), imageghcr.io/open-webui/open-webui:main, exposing host port3000mapped to container port8080. - 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=/ollamaviahost.docker.internal. - The Kubernetes cluster has an existing PostgreSQL instance (
postgres-hetznerin thedatabasenamespace) 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.ltvia 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-osare not migrated to PostgreSQL. pop-osOllama 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 |
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:
-
API key (recommended for Kubernetes): create an API key at https://ollama.com/settings/keys, then create the
ollama-cloudSecret fromollama_secret_example.yaml. The Deployment injectsOLLAMA_API_KEYautomatically. -
Interactive signin: exec into the pod and run
ollama signin:kubectl -n ollama exec -it deploy/ollama -- ollama signinBecause
/root/.ollamais 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:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: open-webui-uploads
namespace: ollama
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: slow
Pre-deployment database setup
-
The existing
postgres-secretin thedatabasenamespace already contains the superuser password, so no new Secret is needed. -
Edit
Ollama/openwebui_db_setup.yamland replace the placeholder passwordopenwebui-passwordin theCREATE USERstatement with a strong, unique password. -
Create the database and user:
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.yamlIf the user/database already exists from a previous run with the old password, drop them first (requires the postgres superuser):
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:
./Ollama/create_openwebui_secret.sh
Or create it manually, replacing YOUR-OPENWEBUI-DB-PASSWORD with the password from openwebui_db_setup.yaml:
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
-
Recreate the
openwebuidatabase/user with the new password (see "Pre-deployment database setup" above). -
Create the Open WebUI namespace:
kubectl apply -f Ollama/ollama_namespace.yaml -
Create the
openwebui-secretinteractively (see "Secret creation" above) using the new password. -
Create the Ollama PVC and (optionally) cloud Secret:
# 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 -
Apply Ollama manifests:
kubectl apply -f Ollama/ollama_service.yaml kubectl apply -f Ollama/ollama_deployment.yaml -
Verify Ollama is running and accessible inside the cluster:
kubectl -n ollama get pods -o wide kubectl -n ollama logs -f deploy/ollama kubectl -n ollama exec -it deploy/ollama -- ollama list -
Apply Open WebUI manifests:
kubectl apply -f Ollama/openwebui_service.yaml kubectl apply -f Ollama/openwebui_deployment.yaml kubectl apply -f Ollama/openwebui_ingress.yaml -
Verify:
kubectl -n ollama get pods -o wide kubectl -n ollama logs -f deploy/open-webui kubectl -n ollama get ingress -
Update DNS for
chat.mariushome.ltto point to the Cilium LB IP assigned to theopen-webuiIngress. -
After confirming Open WebUI works on
chat.mariushome.lt, shut down the localpop-osservices (keep the Docker volume as a backup):
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:3000tohttp://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:11434if 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.ltinside 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.yamlandopenwebui_db_setup.yamlcontain sensitive values and must be created out-of-band; do not commit them.
Rollback
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
openwebuiPostgreSQL user must use a different password than the exampleopenwebui-password. Editopenwebui_db_setup.yaml, replace the password in theCREATE USERstatement, and re-run the Job to recreate the user/database before creating theopenwebui-secret. - The
pop-osOpen 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.