Skip to content
RAG infrastructure on Kubernetes · Chapter 1 of 20 Preparation: Building the Library – Two VMs, a Cluster and the First Models

Preparation: Building the Library – Two VMs, a Cluster and the First Models

Goal: Set up access to two VMs, build a Kubernetes cluster with two nodes, install Ollama with an embedding model and a small language model, and measure a baseline · Duration: approx. 90 min · Prerequisite: two fresh VMs with Ubuntu 24.04, a computer with SSH

State before this chapter

You need two VMs with Ubuntu 24.04 that you can log in to via SSH with a user name and password, and your own computer with a terminal. The first VM needs at least 4 vCPU, 8 GB of memory and 40 GB of free disk, because the models, the vector databases and the Kubernetes server run on it. The second one gets by with 2 vCPU, 4 GB and 20 GB. (In the author’s lab, the first VM had 12 vCPU and 12 GB from Day 10 on; with 4 vCPU everything works the same way, the model just reads more slowly – the chapters point this out where the numbers matter.) Both must be able to reach each other on the network and access the internet. You do not need a graphics card: all models in this course run on the CPU.

Introduction

Retrieval Augmented Generation, RAG for short, sounds like a prompt trick: you search for a few matching passages and hand them to a language model so it does not have to guess. In a company, however, RAG is above all infrastructure. Documents have to be accepted, split up and translated into numbers, a database has to search these numbers quickly, a service has to answer questions – and all of this has to keep running when a node fails, when a new model arrives or when someone slips in a prepared document. This kind of operation is exactly what you practise in this course.

Today you build the grounds: two VMs, a small Kubernetes cluster with two nodes, and Ollama, which runs the models on the CPU. At the end, you measure for the first time how long an embedding and an answer take. These numbers accompany you through the whole course: whenever something gets slow later, you compare it with today’s baseline.

Today you learn:

  • to create your own SSH key for the lab and set up short names for the VMs,
  • to verify a downloaded program by its checksum before you install it,
  • to install k3s as a Kubernetes server and join a second node,
  • to set up Ollama as a service and pull models,
  • to request an embedding and an answer and read where the time goes.

Every chapter is built the same way: first you read in words what you do and why, then comes exactly one command, then every option explained, then the real output from the lab and what it means. At the end of every drill, a Remember box sums up the core in one sentence, and before the interview note you check yourself with a few questions.

Background

The picture for today: a library with an information desk

Picture the whole course as a library. Books are delivered, unpacked at the intake desk and copied onto index cards. Every card gets a place on the shelf – not in alphabetical order but by meaning: cards about printers stand next to cards about printer drivers, far away from cards about leave requests. When someone comes to the information desk with a question, the librarian fetches the few cards that stand closest to the question, and the person at the desk answers only from these cards.

Today the building goes up:

  • rag1 is the main building. This is where the card cabinets (the vector databases) will stand, where the information desk (the language model) sits, and where the administration (the Kubernetes server) is.
  • rag2 is the annex. Later, a second card cabinet stands here as a reserve, and deliveries start from here.
  • Ollama is the workshop in the main building. It has two tools: the classification system, which assigns a text its place on the shelf (the embedding model), and the person at the desk, who phrases sentences (the language model).

The terms

Term Meaning in the picture
RAG Retrieval Augmented Generation: first search for matching texts, then answer with them information from the cards that were brought
Embedding a list of numbers (a vector) that describes the meaning of a text the place of a card on the shelf
Embedding model the model that turns text into an embedding the classification system
Language model (LLM) the model that writes an answer from a question and context the person at the information desk
Ollama a service that loads models and offers them through an HTTP API the workshop with both tools
k3s a small, complete Kubernetes distribution the building’s administration
Node a machine in the Kubernetes cluster a building

Remember: RAG has two models with different jobs: the embedding model classifies, the language model phrases. Today both run in the same workshop, but they can be measured separately.

Why two VMs

Almost everything in this course could be shown on one VM. Two things could not: a replica of the vector database on a different machine, and the failure of that machine. For that you need a second node from Day 11 on. Until then, rag2 serves as the source of load and deliveries, so that the load generator does not occupy the same CPU as the thing it measures.

Why k3s and Ollama

k3s is a complete Kubernetes in a single file, with simple storage for volumes (local-path) already built in. That suits small VMs. Ollama loads models in GGUF format and runs them on the CPU with llama.cpp. It offers a simple HTTP API that you talk to directly with curl on Day 1. Today Ollama still runs as an ordinary service on rag1; on Day 3 you move the embedding service into the cluster.

The models

Model Job Size on disk Why this one
bge-m3 embeddings, 1024 numbers per text 1.2 GB multilingual – the course documents are German and English
nomic-embed-text embeddings, for comparison on Day 2 274 MB small and fast, but trained on English
qwen3:1.7b writing answers 1.4 GB small enough for the CPU, speaks German

The grounds

VM Address (in the author’s lab) Role
rag1 172.16.0.182 k3s server, Ollama, later Qdrant and PostgreSQL
rag2 172.16.0.83 k3s agent, later second replica, deliveries and load

Your addresses are different. Wherever the book shows an address, use yours.

Drill 1: Access to the two VMs

Where you are: on your own computer, in a terminal.

What you have afterwards: your own SSH key and short names with which ssh rag1 works without a password, and VMs that are called rag1 and rag2 and know each other by name.

You work on the VMs via SSH throughout the course. A key of your own just for this lab keeps it separate from your other access; at the end you can simply delete it.

Step 1 – create a key.

# on your computer
ssh-keygen -t ed25519 -f ~/.ssh/rag -C rag-labor

ssh-keygen creates a key pair made of a private and a public key.

  • -t ed25519 selects the key type Ed25519 – short, fast and today’s standard.
  • -f ~/.ssh/rag sets the file name: the private key ends up in ~/.ssh/rag, the public one in ~/.ssh/rag.pub.
  • -C rag-labor is a comment. It later appears in authorized_keys on the VMs, so that you recognise the key there.

The program asks for a passphrase. For a lab you may leave it empty by pressing Enter.

Expected (excerpt, paths shortened):

Generating public/private ed25519 key pair.
Your identification has been saved in ~/.ssh/rag
Your public key has been saved in ~/.ssh/rag.pub
The key fingerprint is:
SHA256:llx7R7Irs4Di+TA17kWUFuzlCEQKRU9YToETS/tN2R8 rag-labor

What you see: two files and a fingerprint – a short checksum of the public key. Yours looks different.

Step 2 – copy the public key to rag1.

# on your computer
ssh-copy-id -i ~/.ssh/rag.pub [email protected]

ssh-copy-id logs in once with the password and appends the public key to the user’s ~/.ssh/authorized_keys file on the VM.

  • -i ~/.ssh/rag.pub says which public key is transferred.
  • [email protected] is the user and address of the VM. If your user has a different name, replace ubuntu.

Expected (excerpt, after the password prompt):

Number of key(s) added:        1

Step 3 – the same for rag2.

# on your computer
ssh-copy-id -i ~/.ssh/rag.pub [email protected]

Here, too, Number of key(s) added: 1 appears after the password.

Step 4 – set up short names. So that you do not have to type key, user and address every time, you enter the VMs in the SSH configuration. Open the file in the nano editor:

# on your computer
nano ~/.ssh/config

nano <file> opens the file in the terminal; if it does not exist yet, nano creates it when you save. nano is the editor you use throughout the course:

  • You move the cursor with the arrow keys and simply type text.
  • You paste text from the clipboard with Cmd+V on the Mac and with Ctrl+Shift+V on Linux.
  • Ctrl+O saves, Enter confirms the file name. Ctrl+X exits nano.
  • Files under /etc belong to root. You open them with sudo nano <file>.

Go to the end of the file and append these lines. Anything already in the file stays unchanged; what you add is highlighted in green:

~/.ssh/config changes in green
Host rag1
    HostName 172.16.0.182
Host rag2
    HostName 172.16.0.83
Host rag1 rag2
    User ubuntu
    IdentityFile ~/.ssh/rag

Each Host section applies to the short names it lists. HostName is the real address, User the user on the VM and IdentityFile the private key. The last section names both hosts, so that you only have to write user and key once.

Step 5 – check the login.

# on your computer
ssh rag1 hostname

ssh rag1 <command> logs in, runs the command and logs out again. hostname prints the name of the VM.

Expected (on a fresh VM this shows its previous name):

argo

What you see: the login went through without a password. The name is still the old one – you change that in the next step.

Step 6 – give the VMs their names. Kubernetes takes the host name as the name of the node, and that name appears in many outputs in this course. So that your outputs match those in the book, the VMs are called rag1 and rag2. Log in to rag1:

# on your computer
ssh rag1
# on rag1
sudo hostnamectl set-hostname rag1

hostnamectl set-hostname rag1 sets the host name permanently; sudo is needed because this is a system setting. The command prints nothing.

Ubuntu cloud images sometimes reset the name at boot to the value from the hypervisor configuration. A small file for cloud-init, the program that sets up these images at boot, prevents that:

# on rag1
sudo nano /etc/cloud/cloud.cfg.d/99-hostname.cfg
/etc/cloud/cloud.cfg.d/99-hostname.cfg new file
preserve_hostname: true

preserve_hostname: true tells cloud-init: leave the name the system already has alone.

Step 7 – know the neighbours by name. rag1 and rag2 should reach each other by name. Without a DNS server in the lab, you enter the names in the hosts file:

# on rag1
sudo nano /etc/hosts

Go to the end of the file and append two lines (your addresses):

/etc/hosts changes in green
172.16.0.182 rag1
172.16.0.83 rag2

Log out with exit and do steps 6 and 7 the same way on rag2 – there with sudo hostnamectl set-hostname rag2 and the same two lines.

Step 7a – do the lines survive a reboot? Some images rewrite /etc/hosts from a template at every boot – then your two lines are gone after the next reboot. The first line of the file tells you:

# on rag1
head -1 /etc/hosts

head -1 shows only the first line of a file.

Expected (in the author’s lab on both VMs):

# Your system has configured 'manage_etc_hosts' as True.

If this line is there, cloud-init manages the file. The setting does not have to be in /etc/cloud/cloud.cfg – in the author’s lab it comes from the VM’s user data, passed in by the hypervisor. So check the first line, not cloud.cfg. Exactly this happened in the lab: after the reboot when rag1 was enlarged (Day 10) the two lines were gone, and getent hosts rag2 printed nothing on rag1. k3s did not notice because it works with IP addresses.

In that case the two lines belong in the template. First a backup:

# on rag1
sudo cp /etc/cloud/templates/hosts.debian.tmpl /etc/cloud/templates/hosts.debian.tmpl.orig
# on rag1
sudo nano /etc/cloud/templates/hosts.debian.tmpl

Add the two lines below 127.0.0.1 localhost:

/etc/cloud/templates/hosts.debian.tmpl changes in green
## template:jinja
{#
This file (/etc/cloud/templates/hosts.debian.tmpl) is only utilized
if enabled in cloud-config.  Specifically, in order to enable it
you need to add the following to config:
   manage_etc_hosts: True
-#}
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#
{# The value '{{hostname}}' will be replaced with the local-hostname -#}
127.0.1.1 {{fqdn}} {{hostname}}
127.0.0.1 localhost
172.16.0.182 rag1
172.16.0.83 rag2

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

The lines with {{…}} and {#…#} are placeholders and comments of the template; cloud-init fills in the host name there. Check that the lines are in:

# on rag1
grep -n rag /etc/cloud/templates/hosts.debian.tmpl

grep -n shows matching lines with their line number.

Expected:

18:172.16.0.182 rag1
19:172.16.0.83 rag2

Without a reboot, let cloud-init rewrite the hosts file from the template now:

# on rag1
sudo cloud-init single --name update_etc_hosts --frequency always
  • single runs exactly one cloud-init module,
  • --name update_etc_hosts is the module that writes /etc/hosts from the template,
  • --frequency always runs it even though it has already run for this boot.

Expected (the time since boot differs):

Cloud-init v. 26.2-0ubuntu1~24.04.2 running 'single' at Thu, 03 Dec 2026 12:01:41 +0000. Up 80838.62 seconds.
# on rag1
grep -n rag /etc/hosts

Expected:

10:172.16.0.182 rag1
11:172.16.0.83 rag2

The two lines are now in lines 10 and 11 – exactly where the template puts them. cloud-init has replaced your lines from Step 7; from now on they come from the template at every boot. Do Step 7a the same way on rag2. If head -1 /etc/hosts shows a different first line for you, skip Step 7a.

Step 8 – check the names.

# on rag1
getent hosts rag2

getent hosts <name> queries the system’s name resolution – exactly what k3s uses as well.

Expected:

172.16.0.83     rag2

From rag2 you check the other way round:

# on rag2
getent hosts rag1

Expected:

172.16.0.182    rag1

Remember: Access and names first, then everything else: every later command in the course starts with # on rag1 or # on rag2 – that only works if both names are correct everywhere.

If it does not work

If ssh rag1 still asks for a password, the path after IdentityFile usually does not match the key from step 1, or ssh-copy-id ran against a different address. ssh -v rag1 shows which keys ssh offers and which one is rejected.

Save your progress? Sign up for free

Drill 2: Installing the tools

Where you are: on rag1.

What you have afterwards: jq for reading JSON, Python’s venv for small programs from Day 6 on, and Helm, with which you install the databases from Day 4 on – verified by its checksum.

Almost every answer in this course is JSON: from Ollama, from Qdrant, from Kubernetes. jq turns it into readable excerpts. Helm is the package manager for Kubernetes.

Step 1 – refresh the package lists.

# on rag1
sudo apt-get update

apt-get update downloads the current package lists from the Ubuntu servers. Without this step the system does not know about new versions. The output is a list of addresses with Hit or Get.

Step 2 – install jq and venv.

# on rag1
sudo apt-get install -y jq python3-venv
  • install installs the named packages including their dependencies.
  • -y answers the question “Do you want to continue?” with yes.
  • jq is the JSON tool, python3-venv allows separate, isolated Python environments.

Step 3 – check the versions.

# on rag1
jq --version

Expected:

jq-1.7
# on rag1
python3 --version

Expected:

Python 3.12.3

Step 4 – determine the architecture. Helm and Ollama exist for Intel/AMD (amd64) and for ARM (arm64). Instead of hard-coding the architecture in the commands, you ask the system:

# on rag1
ARCH=$(dpkg --print-architecture)

dpkg --print-architecture prints the architecture in the notation used by Debian and Ubuntu. ARCH=$( … ) stores this output in the shell variable ARCH. Check it:

# on rag1
echo $ARCH

Expected (on an ARM VM this shows arm64):

amd64

The variable only applies to this session. If you log in again, set it again.

Step 5 – download Helm.

# on rag1
curl -fsSLO https://get.helm.sh/helm-v4.3.2-linux-$ARCH.tar.gz
Option Meaning
-f abort on an HTTP error instead of saving the error page
-s silent, no progress bar
-S still show errors
-L follow redirects
-O save under the file name from the URL

Step 6 – fetch the checksum. Next to every archive there is a file with its SHA-256 checksum.

# on rag1
curl -fsSLO https://get.helm.sh/helm-v4.3.2-linux-$ARCH.tar.gz.sha256sum

Step 7 – compare.

# on rag1
sha256sum -c helm-v4.3.2-linux-$ARCH.tar.gz.sha256sum

sha256sum -c <file> reads checksum and file name from the file, recomputes the checksum of the downloaded file and compares them.

Expected:

helm-v4.3.2-linux-amd64.tar.gz: OK

What you see: OK means the file is bit for bit the one the Helm project published. If it says FAILED, do not install it.

Step 8 – unpack.

# on rag1
tar -xzf helm-v4.3.2-linux-$ARCH.tar.gz
  • -x extracts, -z decompresses gzip, -f names the archive file.

The archive contains a folder linux-amd64 with the program helm.

Step 9 – install.

# on rag1
sudo install -m 0755 linux-$ARCH/helm /usr/local/bin/helm

install copies a file and sets its permissions at the same time. -m 0755 means: everyone may read and execute it, only root may change it. /usr/local/bin is the place for programs you install yourself.

Step 10 – check.

# on rag1
helm version

Expected:

version.BuildInfo{Version:"v4.3.2", GitCommit:"8346aaa55e7161f7c547212d0a87f01367976727", GitTreeState:"clean", GoVersion:"go1.27.4", KubeClientVersion:"v1.37"}

Remember: Checksum first, then installation. A program you install without comparing is in the hands of anyone who sits between you and the server.

If it does not work

If curl only reports curl: (22) The requested URL returned error: …, the file is currently not available at this address. In the author’s lab this happened occasionally with GitHub; a second attempt a few seconds later went through. If sha256sum -c reports No such file or directory, the checksum file from step 6 is missing.

Save your progress? Sign up for free

Drill 3: Installing the k3s server on rag1

Where you are: on rag1.

What you have afterwards: a running Kubernetes server and kubectl, which talks to it without sudo.

k3s is set up with an installation script. You do not run it blindly; you download it first and look at it. Before that, you create a configuration file that the script reads when it starts k3s.

Step 1 – write the configuration.

# on rag1
sudo mkdir -p /etc/rancher/k3s

mkdir -p creates the folder including any missing parent folders and reports no error if it already exists.

# on rag1
sudo nano /etc/rancher/k3s/config.yaml
/etc/rancher/k3s/config.yaml new file
disable:
  - traefik
node-ip: 172.16.0.182
  • disable: [traefik] leaves out the bundled ingress controller. You do not need it, and it costs memory that the models need.
  • node-ip sets the address under which the node appears in the cluster. If the VM has several network cards, this prevents k3s from picking the wrong one. Use your address.

Step 2 – download the script.

# on rag1
curl -sfL https://get.k3s.io -o install-k3s.sh

-o install-k3s.sh saves under this name instead of writing the output to the terminal.

Step 3 – look inside.

# on rag1
head -12 install-k3s.sh

head -12 shows the first twelve lines.

Expected (excerpt):

#!/bin/sh
set -e
set -o noglob

# Usage:
#   curl ... | ENV_VAR=... sh -
#       or
#   ENV_VAR=... ./install.sh

What you see: a shell script controlled by environment variables. Feel free to read all of it with less install-k3s.sh – it downloads the k3s file, checks its checksum and sets up a systemd service.

Step 4 – install.

# on rag1
sudo INSTALL_K3S_VERSION=v1.37.2+k3s1 sh install-k3s.sh
  • INSTALL_K3S_VERSION=v1.37.2+k3s1 pins the version. Without it, the script takes the latest one, and your outputs differ from the book.
  • sh install-k3s.sh runs the script. sudo applies to the whole command including the variable.

Expected (excerpt):

[INFO]  Using v1.37.2+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.37.2%2Bk3s1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.37.2%2Bk3s1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  systemd: Enabling k3s unit
[INFO]  systemd: Starting k3s

What you see: the script checks the checksum itself (Verifying binary download), creates kubectl as a link to k3s and starts the service.

Step 5 – put the access file in place for you. k3s writes the credentials for the cluster to /etc/rancher/k3s/k3s.yaml, readable only by root. You copy it into your home directory:

# on rag1
mkdir -p ~/.kube
# on rag1
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
# on rag1
sudo chown ubuntu:ubuntu ~/.kube/config

chown ubuntu:ubuntu makes you the owner of the copy – sudo cp left it owned by root.

# on rag1
chmod 600 ~/.kube/config

chmod 600 allows reading and writing only for you. The file contains the key to the whole cluster.

Step 6 – tell kubectl where the file is. The kubectl from k3s looks for its access file in a place of its own. You enter the path in your shell configuration:

# on rag1
nano ~/.bashrc

Append one line at the end:

~/.bashrc (Ende) changes in green
export KUBECONFIG=~/.kube/config

export sets an environment variable for all programs started from this shell. So that the line takes effect immediately, you reload the file:

# on rag1
source ~/.bashrc

Step 7 – look at the node.

# on rag1
kubectl get nodes -o wide

-o wide shows additional columns.

Expected:

NAME   STATUS   ROLES           AGE   VERSION        INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION              CONTAINER-RUNTIME
rag1   Ready    control-plane   12s   v1.37.2+k3s1   172.16.0.182   <none>        Ubuntu 24.04.5 LTS   6.8.0-149-generic (amd64)   containerd://2.3.7-k3s1
Column Value Meaning
STATUS Ready the node accepts pods
ROLES control-plane the Kubernetes server runs here
INTERNAL-IP 172.16.0.182 the address from node-ip
CONTAINER-RUNTIME containerd://2.3.7-k3s1 k3s brings its own container runtime

Remember: The cluster’s access file is a master key. It belongs in your home directory with permissions 600 – not in a Git repository, not in an e-mail.

If it does not work

Without step 6, kubectl reports in the author’s lab:

error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied

Without KUBECONFIG, the kubectl from k3s reads the server’s file, and only root may read that. Check with echo $KUBECONFIG whether the variable is set, and reload ~/.bashrc with source.

Save your progress? Sign up for free

Drill 4: Joining rag2 as a second node

Where you are: first on rag1, then on rag2.

What you have afterwards: a cluster with two nodes.

A new node identifies itself to the server with a token – a secret that the server generated during installation.

Step 1 – read the token.

# on rag1
sudo cat /var/lib/rancher/k3s/server/node-token

Expected: one line of 108 characters that starts with K10 and contains ::server: in the middle. The book does not print it: whoever has this token can attach their own machines to your cluster. Copy it to the clipboard, not into a file.

Step 2 – write the configuration on rag2.

# on rag2
sudo mkdir -p /etc/rancher/k3s
# on rag2
sudo nano /etc/rancher/k3s/config.yaml
/etc/rancher/k3s/config.yaml (auf rag2) new file
server: https://172.16.0.182:6443
token: <das Token aus Schritt 1>
node-ip: 172.16.0.83
  • server is the address of the Kubernetes API on rag1, port 6443.
  • token is the secret from step 1, without quotes.
  • node-ip is the address of rag2.

Step 3 – protect the file.

# on rag2
sudo chmod 600 /etc/rancher/k3s/config.yaml

Now only root may read the file with the token.

Step 4 – fetch the script and install as an agent.

# on rag2
curl -sfL https://get.k3s.io -o install-k3s.sh
# on rag2
sudo INSTALL_K3S_VERSION=v1.37.2+k3s1 INSTALL_K3S_EXEC=agent sh install-k3s.sh

INSTALL_K3S_EXEC=agent sets up k3s as an agent: it runs pods but is not a server. Because server is in the configuration, it registers there.

Expected (excerpt):

[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh
[INFO]  systemd: Enabling k3s-agent unit
[INFO]  systemd: Starting k3s-agent

Step 5 – see both nodes.

# on rag1
kubectl get nodes -o wide

Expected:

NAME   STATUS   ROLES           AGE   VERSION        INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION              CONTAINER-RUNTIME
rag1   Ready    control-plane   62s   v1.37.2+k3s1   172.16.0.182   <none>        Ubuntu 24.04.5 LTS   6.8.0-149-generic (amd64)   containerd://2.3.7-k3s1
rag2   Ready    <none>          8s    v1.37.2+k3s1   172.16.0.83    <none>        Ubuntu 24.04.5 LTS   6.8.0-151-generic (amd64)   containerd://2.3.7-k3s1

What you see: rag2 is Ready and has no role – a pure worker node.

Step 6 – check the system services.

# on rag1
kubectl get pods -A -o wide

-A shows pods from all namespaces.

Expected:

NAMESPACE     NAME                                      READY   STATUS      RESTARTS   AGE   IP          NODE   NOMINATED NODE   READINESS GATES
kube-system   coredns-577d995dff-g8kb5                  1/1     Running     0          56s   10.42.0.2   rag1   <none>           <none>
kube-system   helm-install-gateway-api-crd-gt9lm        0/1     Completed   0          56s   10.42.0.5   rag1   <none>           <none>
kube-system   local-path-provisioner-56c6584955-pvrmm   1/1     Running     0          56s   10.42.0.3   rag1   <none>           <none>
kube-system   metrics-server-778c4649b4-r89w4           1/1     Running     0          56s   10.42.0.4   rag1   <none>           <none>
Pod Job
coredns name resolution in the cluster – services find each other by names like qdrant.rag.svc
local-path-provisioner creates folders on the node for volumes; this is where the data of Qdrant and PostgreSQL will live
metrics-server supplies CPU and memory values for kubectl top
helm-install-gateway-api-crd a one-off job that installs Gateway API definitions; Completed is correct

Remember: A node joins the cluster with a token. The token is worth as much as the cluster itself – it belongs in a file with permissions 600 and nowhere else.

If it does not work

If rag2 does not show up in kubectl get nodes, sudo journalctl -u k3s-agent --since "5 min ago" on rag2 shows what it is stuck on. Often it is a typo in the token or a firewall that blocks port 6443 on rag1.

Save your progress? Sign up for free

Drill 5: Ollama and the first models

Where you are: on rag1.

What you have afterwards: Ollama as a service, three models and a baseline: how long an embedding and an answer take on this VM.

Ollama comes as an archive with the program and libraries. As with Helm, you verify it by its checksum and set up the service yourself – that way you know exactly which user it runs as.

Step 1 – download. The archive is 1.6 GB; most of it is libraries for graphics cards that you do not use.

# on rag1
curl -fsSLO https://github.com/ollama/ollama/releases/download/v0.40.19/ollama-linux-$ARCH.tar.zst

Step 2 – fetch the checksums.

# on rag1
curl -fsSLO https://github.com/ollama/ollama/releases/download/v0.40.19/sha256sum.txt

This file contains the checksums of all archives of the release.

Step 3 – compare.

# on rag1
sha256sum -c --ignore-missing sha256sum.txt

--ignore-missing skips the archives you did not download.

Expected:

./ollama-linux-amd64.tar.zst: OK

Step 4 – unpack. The archive is compressed with zstd:

# on rag1
sudo apt-get install -y zstd
# on rag1
sudo tar --zstd -xf ollama-linux-$ARCH.tar.zst -C /usr/local
  • --zstd decompresses zstd.
  • -C /usr/local extracts there: the program ends up in /usr/local/bin/ollama, the libraries in /usr/local/lib/ollama.

Step 5 – create a dedicated user. Ollama should not run as root.

# on rag1
sudo useradd -r -s /bin/false -U -m -d /usr/share/ollama ollama
Option Meaning
-r system user without login
-s /bin/false no shell – nobody can log in as ollama
-U create a group with the same name
-m -d /usr/share/ollama create a home directory; Ollama stores the models here

Step 6 – describe the service.

# on rag1
sudo nano /etc/systemd/system/ollama.service
/etc/systemd/system/ollama.service new file
[Unit]
Description=Ollama
After=network-online.target

[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
  • ExecStart is the command systemd starts: ollama serve starts the API service.
  • User/Group make it run as ollama.
  • Restart=always and RestartSec=3 restart it three seconds after a crash.
  • WantedBy=multi-user.target starts it at boot.

Without further settings, Ollama only listens on 127.0.0.1:11434 – reachable only on rag1 itself. That is enough until Day 3.

Step 7 – start.

# on rag1
sudo systemctl daemon-reload

daemon-reload reads in new and changed service files.

# on rag1
sudo systemctl enable --now ollama

enable starts the service at every boot, --now starts it right away.

Expected:

Created symlink /etc/systemd/system/multi-user.target.wants/ollama.service → /etc/systemd/system/ollama.service.

Step 8 – ask the API.

# on rag1
curl -s http://127.0.0.1:11434/api/version

Expected:

{"version":"0.40.19"}

Step 9 – pull the models. ollama pull fetches a model from the Ollama library. Each model is a separate command:

# on rag1
ollama pull bge-m3
# on rag1
ollama pull nomic-embed-text
# on rag1
ollama pull qwen3:1.7b

Each command ends with success. :1.7b selects the variant with 1.7 billion parameters; without it, Ollama takes the latest variant.

Step 10 – list the models.

# on rag1
ollama list

Expected:

NAME                       ID              SIZE      MODIFIED
qwen3:1.7b                 8f68893c685c    1.4 GB    Less than a second ago
nomic-embed-text:latest    0a109f422b47    274 MB    2 minutes ago
bge-m3:latest              790764642607    1.2 GB    2 minutes ago

Remember: Ollama is a workshop whose tools have to be fetched first. What ollama list does not show, the API cannot use.

Save your progress? Sign up for free

Drill 6: The baseline

Where you are: on rag1.

What you have afterwards: two measurements against which you measure everything from now on: the duration of an embedding and the duration of an answer – each cold and warm.

Step 1 – create a working folder. Every day gets its own folder; that is where the API responses are stored as files.

# on rag1
mkdir -p ~/kurs/00
# on rag1
cd ~/kurs/00

Step 2 – request an embedding. The text is a German question (“How do I restart the print service?”); bge-m3 is multilingual.

# on rag1
curl -s http://127.0.0.1:11434/api/embed -d '{"model":"bge-m3","input":"Wie starte ich den Druckdienst neu?"}' -o embed.json
  • /api/embed is the endpoint for embeddings.
  • -d '{…}' sends a JSON body via POST. model selects the model, input is the text.
  • -o embed.json saves the response to a file instead of writing it to the terminal – it is over 20,000 characters long.

Step 3 – the length of the vector.

# on rag1
jq '.embeddings[0] | length' embed.json

.embeddings[0] accesses the first (and only) vector, | length counts its entries.

Expected:

1024

What you see: a sentence of six words becomes 1024 numbers. Every question and every index card gets a vector of exactly this length – otherwise they cannot be compared.

Step 4 – the first four numbers.

# on rag1
jq '.embeddings[0][0:4]' embed.json

[0:4] slices out entries 0 to 3.

Expected:

[
  -0.07397491,
  0.0012907916,
  -0.034456816,
  -0.029466601
]

What you see: small numbers around zero. A single number means nothing on its own. Only the whole vector describes the place on the shelf – you go deeper into this on Day 2.

Step 5 – where the time went.

# on rag1
jq '{model, total_duration, load_duration, prompt_eval_count}' embed.json

{model, total_duration, …} builds a new object from just these fields.

Expected:

{
  "model": "bge-m3",
  "total_duration": 9775951433,
  "load_duration": 9592671079,
  "prompt_eval_count": 10
}
Field Value Meaning
total_duration 9,775,951,433 total duration in nanoseconds: 9.8 s
load_duration 9,592,671,079 9.6 s of it to load the model into memory
prompt_eval_count 10 the sentence was split into 10 tokens

What you see: almost all of the time went into loading. The actual computation took less than 0.2 s.

Step 6 – the same once more.

# on rag1
curl -s http://127.0.0.1:11434/api/embed -d '{"model":"bge-m3","input":"Wie starte ich den Druckdienst neu?"}' -o embed2.json
# on rag1
jq '{total_duration, load_duration, prompt_eval_count}' embed2.json

Expected:

{
  "total_duration": 173455815,
  "load_duration": 2238522,
  "prompt_eval_count": 10
}

What you see: 0.17 s instead of 9.8 s. The model was still loaded. Ollama keeps a model in memory for five minutes after the last request – after that, the next request is cold again.

Step 7 – request an answer. The prompt is German (“Answer in one sentence: what is a vector?”).

# on rag1
curl -s http://127.0.0.1:11434/api/generate -d '{"model":"qwen3:1.7b","prompt":"Antworte in einem Satz: Was ist ein Vektor?","stream":false,"think":false}' -o antwort.json
  • /api/generate makes the language model generate text.
  • "stream":false delivers the answer in one piece instead of word by word.
  • "think":false switches off qwen3’s thinking mode; otherwise the model first writes long deliberations before it answers.

Step 8 – read the answer.

# on rag1
jq -r .response antwort.json

-r prints the text without quotes.

Expected:

Ein Vektor ist eine geometrische Objekt, das sowohl eine Richtung als auch eine Strecke hat, und kann mit anderen Vektoren addiert oder multipliziert werden.

What you see: a usable answer (“A vector is a geometric object that has both a direction and a length, and can be added to or multiplied with other vectors”) – with a grammatical error (“eine geometrische Objekt” instead of “ein geometrisches Objekt”). Small models make mistakes like this. That is the price for the model running on the CPU.

Step 9 – where the time went here.

# on rag1
jq '{total_duration, load_duration, eval_count, eval_duration}' antwort.json

Expected:

{
  "total_duration": 16246550740,
  "load_duration": 11518852446,
  "eval_count": 43,
  "eval_duration": 3526138000
}
Field Value Meaning
total_duration 16.2 s total duration
load_duration 11.5 s loading the model
eval_count 43 generated tokens
eval_duration 3.5 s time spent generating: 43 / 3.5 ≈ 12 tokens per second

Step 10 – what is in memory.

# on rag1
ollama ps

Expected:

NAME             ID              SIZE      PROCESSOR    CONTEXT    RUNNER      UNTIL
qwen3:1.7b       8f68893c685c    1.9 GB    100% CPU     4096       llamacpp    4 minutes from now
bge-m3:latest    790764642607    1.2 GB    100% CPU     4096       llamacpp    4 minutes from now
Column Meaning
SIZE memory occupied by the loaded model – qwen3 needs more in memory than on disk
PROCESSOR 100% CPU: no graphics card involved
CONTEXT how many tokens question plus context may have at most
UNTIL when Ollama unloads the model again

Step 11 – the VM’s memory.

# on rag1
free -m

Expected (excerpt):

               total        used        free      shared  buff/cache   available
Mem:            7941        4315         179           3        3757        3625

What you see: with both models loaded, 3.6 GB of almost 8 GB are still available (available). Qdrant and PostgreSQL have to fit into this space from Day 4 on. Keep this number in mind.

Remember: Every request to a model has two costs: loading once, then computing. The baseline on this VM: embedding warm 0.17 s, answer about 12 tokens per second, loading 10 s and more.

Save your progress? Sign up for free

Diagnosis task

A colleague reports: “The first question in the morning takes forever, after that it is fast.” You have five minutes. What is the cause, and which command proves it?

Solution: The answer lies in load_duration. After a break of more than five minutes, request an embedding and, as in Drill 6, step 5, read load_duration from the response: if the value is in the range of seconds, the model was loaded again. ollama ps shows in the UNTIL column when a loaded model will be unloaded. A longer keep-alive time helps; how to set it and what it costs in memory is the topic of Day 3.

Challenge

Request the same embedding with nomic-embed-text and compare the length of the vector and the warm duration with bge-m3. Write down both values – you need them on Day 2.

Save your progress? Sign up for free

Checkpoint

# on rag1
kubectl get nodes

Expected: two lines, rag1 and rag2, both Ready.

# on rag1
systemctl is-active ollama

Expected:

active
# on rag1
ollama list

Expected: three models – bge-m3, nomic-embed-text, qwen3:1.7b.

Test yourself

  1. Why does RAG need two different models?
  2. What does it mean when load_duration is almost as large as total_duration?
  3. Why does the book not print the token from node-token?
  4. How do you recognise whether a downloaded archive is unchanged?
  5. How much memory remains free on rag1 when both models are loaded – and why does that matter?

Answers:

  1. The embedding model classifies text (turns text into a vector), the language model phrases an answer. One searches, the other writes.
  2. The model was not loaded; almost all of the time went into loading, not into computing.
  3. Whoever has the token can join their own nodes to your cluster and run pods there.
  4. With sha256sum -c against the checksum published by the project. Install only on OK.
  5. In the author’s lab 3.6 GB. The vector databases have to fit into it from Day 4 on.

Interview note

“How would you set up a RAG system on-prem?” – Start with the building blocks instead of the prompt: embedding service, vector store, answer service, ingestion. Name the baseline: how long does an embedding take, how many tokens per second does the model manage, how much memory does it need? If you know these numbers, you can talk about hardware and latency instead of wishful thinking.

Enterprise note

In companies, the embedding model and the language model rarely run on the same machine. The embedding model is small and needed for every delivery and every question; the language model is large and needed only for answers. Kept apart, they can be scaled separately. Models and archives come from an internal mirror there, and the checksums are on an approval list.

Summary

You made two VMs reachable with your own SSH key, built a k3s cluster with two nodes and set up Ollama with three models as a service. You verified every downloaded program by its checksum before installing it. The baseline: an embedding takes 0.17 s warm, an answer is produced at about 12 tokens per second, and loading a model costs 10 s and more. With both models in memory, 3.6 GB remain free.

Commands at a glance

Command What it does Parameters
ssh-keygen -t ed25519 -f ~/.ssh/rag -C rag-labor create a key pair -t type, -f file, -C comment
ssh-copy-id -i ~/.ssh/rag.pub ubuntu@<ip> copy the public key to the VM -i key file
sudo hostnamectl set-hostname rag1 set the host name –
getent hosts rag2 resolve a name through the system –
ARCH=$(dpkg --print-architecture) write the architecture into a variable –
sha256sum -c <file> compare a checksum --ignore-missing skip missing files
sudo INSTALL_K3S_VERSION=… sh install-k3s.sh install k3s INSTALL_K3S_EXEC=agent as an agent
kubectl get nodes -o wide show nodes with details -o wide more columns
kubectl get pods -A -o wide all pods in all namespaces -A all namespaces
sudo systemctl enable --now ollama enable and start a service --now start immediately
ollama pull <model> download a model :<variant> e.g. :1.7b
ollama list / ollama ps downloaded or running models –
curl -s …/api/embed -d '{…}' -o embed.json request an embedding -d JSON body, -o file
jq '.embeddings[0] \| length' embed.json length of the vector -r text without quotes
free -m memory in MB -m megabytes

Contents

More