Appendix C: Cleaning up and rebuilding the lab
What this appendix is for: You have finished the course or want to use the VMs for something else. This appendix lists what the course left behind on rag1, rag2 and your computer, how to save compute without deleting anything, how to remove everything and how to start over. The inventory comes from the final state after Day 16 (3 Dec 2026). The author did not run the teardown – the lab stays in place for the next course. Wherever an output is shown, it comes from a real run; where exactly is stated each time.
What lives in the lab
| Where | What | Size in the lab | Day |
|---|---|---|---|
| your computer | key ~/.ssh/rag and ~/.ssh/rag.pub, entries
rag1/rag2 in ~/.ssh/config |
– | 0 |
| rag1, rag2 | lines rag1/rag2 in /etc/hosts
and in /etc/cloud/templates/hosts.debian.tmpl (backup
….orig),
/etc/cloud/cloud.cfg.d/99-hostname.cfg |
– | 0 |
| rag1 | packages jq, python3-venv,
zstd; /usr/local/bin/helm |
– | 0 |
| rag1 | Ollama on the host: /usr/local/bin/ollama,
/usr/local/lib/ollama, user ollama with models
in /usr/share/ollama, unit
/etc/systemd/system/ollama.service (switched off since Day
3) |
2.5 GB libraries, 2.6 GB models | 0, 3 |
| rag1 | k3s server: /usr/local/bin/k3s, kubectl,
k3s-killall.sh, k3s-uninstall.sh,
/etc/rancher/k3s/config.yaml,
~/.kube/config |
– | 0 |
| rag2 | k3s agent: /usr/local/bin/k3s,
k3s-killall.sh, k3s-agent-uninstall.sh,
/etc/rancher/k3s/config.yaml |
– | 0 |
| cluster | namespaces rag and cnpg-system, Helm
releases qdrant and cnpg |
– | 3–5 |
| rag1 | volumes under /var/lib/rancher/k3s/storage:
modelle (embedding), llm-modell,
rerank-modell, qdrant-storage-qdrant-1 |
1.7 GB · 1.3 GB · 466 MB · 5 MB | 3, 8, 9, 11 |
| rag2 | volumes pg-1, qdrant-storage-qdrant-0 |
208 MB · 15 MB | 4, 5 |
| rag1 | working folders ~/kurs/00 to
~/kurs/16 |
5.7 MB | 0–16 |
The volumes use the storage class local-path: each one
is a folder on exactly one node. Running
kubectl delete namespace rag deletes these folders together
with the claims (reclaim policy Delete).
Three commands show you your own state.
# on rag1
helm list -AExpected:
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
cnpg cnpg-system 1 2026-12-01 20:40:19.17856461 +0000 UTC deployed cloudnative-pg-0.29.2 1.30.2
gateway-api-crd kube-system 1 2026-12-01 12:27:50.069410264 +0000 UTC deployed gateway-api-crd-1.6.301 v1.6.3
qdrant rag 3 2026-12-02 22:47:23.89245344 +0000 UTC deployed qdrant-1.20.3 v1.20.3
gateway-api-crd comes with k3s itself; the course
installed the other two. REVISION 3 for
qdrant: installation (Day 4), two peers (Day 11), keys (Day
14).
# on rag1
kubectl -n rag get pvcExpected:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
llm-modell Bound pvc-26626101-03db-480d-8c8b-0779c5cd578d 5Gi RWO local-path <unset> 23h
modelle Bound pvc-b6dff131-03cb-4e19-8d59-38108fa2d28e 10Gi RWO local-path <unset> 42h
pg-1 Bound pvc-1f9a84bb-88b8-4082-bdca-45f84e0692e1 2Gi RWO local-path <unset> 39h
qdrant-storage-qdrant-0 Bound pvc-48a95998-cdb1-468d-afba-542c27954fce 2Gi RWO local-path <unset> 39h
qdrant-storage-qdrant-1 Bound pvc-48e012f0-5976-478f-b3e8-96e3558766e1 2Gi RWO local-path <unset> 18h
rerank-modell Bound pvc-e8f40226-fe87-49de-ab11-bdffd44cd02a 5Gi RWO local-path <unset> 24h
# on rag1
systemctl is-enabled ollamaExpected:
disabled
The Ollama service on the host has been switched off since Day 3; its models still take up 2.6 GB.
The inventory with all measurements is in
roh/90-anhang-c-messung.txt.
Pause instead of tearing down
When idle, the lab needs little CPU (321m on rag1, 170m on rag2 in the lab), but the language model holds on to a good 2 GiB of memory. If you want to use rag1 for something else for a while, switch it off without deleting anything:
# on rag1
kubectl -n rag scale deployment llm --replicas=0Expected (measured on Day 10):
deployment.apps/llm scaled
Meanwhile the answer service responds with an error
(502, see the diagnosis task on Day 10). To go back, use
the same command with --replicas=1; the model lives in the
volume llm-modell and does not have to be downloaded again.
Afterwards kubectl -n rag rollout status deployment/llm
shows successfully rolled out again.
Tearing down the course
There are two ways. Way 1 removes only what the course created in the cluster; k3s stays for the next course. Way 2 removes everything, including k3s and Ollama. Both delete data for good – copy the snapshots and dumps from Day 12 elsewhere first if you want to keep them.
Way 1: only the course, from the cluster
Step 1 – the namespace rag. It contains
all services, the database, secrets, fences and volumes. First
rag, then the operator: CloudNativePG must still be running
to remove its cluster pg cleanly.
# on rag1
kubectl delete namespace ragExpected (measured on Day 12 with the namespace
rag-neu; the command waits until everything is gone):
namespace "rag-neu" deleted
Yours says rag instead of rag-neu.
Afterwards the namespace must be missing:
# on rag1
kubectl get namespace ragExpected (measured with rag-neu):
Error from server (NotFound): namespaces "rag-neu" not found
Step 2 – the operator.
# on rag1
helm uninstall cnpg -n cnpg-systemExpected: one line
release "cnpg" uninstalled – in the same form as on Day 12
(release "qdrant" uninstalled).
# on rag1
kubectl delete namespace cnpg-systemStep 3 – the check.
# on rag1
kubectl get pvIf a volume with rag/… in the CLAIM column
is still listed, it has not been deleted yet; wait a few seconds and ask
again.
Step 4 – the working folder.
# on rag1
rm -r ~/kursrm -r deletes the folder with everything in it;
-r means recursive. No output.
Way 2: remove everything
The k3s uninstall scripts delete the whole cluster including
/var/lib/rancher/k3s – and with it all volumes. Way 1 is
then not needed. First the agent, then the server.
# on rag2
sudo /usr/local/bin/k3s-agent-uninstall.sh# on rag1
sudo /usr/local/bin/k3s-uninstall.shThe scripts print many lines. Check one by one whether k3s is gone:
# on rag1
systemctl is-enabled k3sExpected (measured on rag2, where there never was a k3s server):
not-found
# on rag1
ls /usr/local/bin/k3s-uninstall.shExpected (measured on rag2):
ls: cannot access '/usr/local/bin/k3s-uninstall.sh': No such file or directory
On rag2 you check the same with k3s-agent and
k3s-agent-uninstall.sh.
Ollama on the host. The service is switched off; program, libraries, unit and user remain.
# on rag1
sudo rm /etc/systemd/system/ollama.service# on rag1
sudo systemctl daemon-reloaddaemon-reload rereads the unit files so that systemd
forgets the deleted unit.
# on rag1
sudo rm -r /usr/local/lib/ollama /usr/local/bin/ollama# on rag1
sudo userdel -r ollamauserdelremoves the userollama,-rdeletes its home directory/usr/share/ollamawith the 2.6 GB of models.
Helm and the working folder.
# on rag1
sudo rm /usr/local/bin/helm# on rag1
rm -r ~/kursThe packages jq, python3-venv and
zstd are small and often useful for other things; if you
want to get rid of them, use
sudo apt-get remove jq python3-venv zstd.
Names and access. Remove the lines
rag1/rag2 from /etc/hosts with
sudo nano – and, if you did Step 7a of Day 0, from
/etc/cloud/templates/hosts.debian.tmpl (or restore the
backup hosts.debian.tmpl.orig). On your computer,
~/.ssh/rag, ~/.ssh/rag.pub and the two entries
in ~/.ssh/config remain. On the VMs the public key is in
~/.ssh/authorized_keys – the line ends with
rag-labor.
Rebuilding
Each day builds on the state of the day before; there is deliberately no shortcut. Start at Day 0: two VMs with Ubuntu 24.04, access, tools, k3s on rag1 and rag2, Ollama and the first models. Two lessons from the lab:
- After every reboot of a VM check
getent hosts rag1andgetent hosts rag2on both nodes. If/etc/hostsstarts with# Your system has configured 'manage_etc_hosts' as True., the two lines also belong in/etc/cloud/templates/hosts.debian.tmpl(Day 0, Step 7a; Appendix B, B2). - From Day 10, rag1 needs 12 vCPU and 12 GB of RAM; rag2 stays at 2 vCPU and 8 GB.
| Day | What is created | Files in the companion code |
|---|---|---|
| 0 | access, k3s on two nodes, Ollama, models | – |
| 1–2 | RAG by hand, measuring embeddings (only files in
~/kurs) |
– |
| 3 | namespace rag, embedding service embed,
helper pod curl |
– |
| 4 | Qdrant with Helm, collection handbuch |
– |
| 5 | CloudNativePG, cluster pg with pgvector |
– |
| 6 | ingestion as a job, collection wissen |
code/06 |
| 7 | test bench, variants of the collection | code/07 |
| 8 | full-text index, reranker | code/08 |
| 9 | language model llm, answer service
antwort |
code/09 |
| 10 | load, prompt cache, seats at the counter | code/10 |
| 11 | Qdrant with two peers, copies, two answer services | code/11 |
| 12 | snapshots, dump, restore | code/12 |
| 13 | second collection wissen-qwen3, sign
auskunft |
code/13 |
| 14 | keys, tenants, output rule, fences | code/14 |
| 15 | metrics, Prometheus, alert rules | code/15 |
| 16 | final case, fourth alert rule | code/16 |
Every file is created in its chapter in
~/kurs/<day>; later days refer to it as
../<day>/…. The companion code
code/<day> contains the same files from Day 6 on for
comparison; the few files from Days 0 to 5 are printed in full in the
chapters.