Skip to content
Vector database engineering on Kubernetes · Chapter 1 of 20 Preparation: The library – four VMs, one cluster, storage and an embedding model

Preparation: The library – four VMs, one cluster, storage and an embedding model

Goal: set up access to four VMs, build a Kubernetes cluster with one server and three worker nodes from them, provide distributed block storage with Longhorn, run an embedding model in the cluster and create a Python workbench for measurements · Duration: about 120 min · Prerequisite: four fresh VMs with Ubuntu 24.04, a computer with SSH

State before this chapter

You need four VMs with Ubuntu 24.04 on a shared network that you can log in to via SSH with a username and password, and your own computer with a terminal. All four may access the internet.

VM Minimum size Why
vdb1 4 vCPU, 8 GB, 60 GB Kubernetes server, embedding model, load generator
vdb2 4 vCPU, 8 GB, 60 GB data node; additionally carries Milvus on Day 14
vdb3 2 vCPU, 6 GB, 30 GB data node
vdb4 2 vCPU, 6 GB, 30 GB data node

You set up everything else today.

Introduction

A vector database answers a single question, but it answers it very quickly: Which stored entries are most similar to this one? It sits behind search functions that find meaning instead of words, behind recommendations and behind almost every application that feeds a language model with its own knowledge. There is a lot of material about building such applications. There is hardly any about operating the database underneath – and that is exactly where the problems arise that wake you up at night: a full volume, a node that drops out, a replica that silently goes stale, a search that suddenly takes 800 ms, a backup that cannot be restored.

This course is for the people who operate the database: platform, DevOps and SRE engineers. You build Qdrant as the main system, distributed on Kubernetes, make it fault-tolerant, measure it, secure it, observe it, back it up and restore it, and at the end compare it with pgvector and Milvus. Every failure in the course is real, and every number comes from a measurement.

Today you build the library: four VMs, a Kubernetes cluster, distributed storage and the “librarian” who translates texts into vectors.

Today you will learn:

  • to generate your own SSH key for the lab and give four VMs names,
  • to install a k3s server and join three worker nodes,
  • to verify downloaded programs by their checksum,
  • to check with longhornctl whether the nodes are ready for Longhorn, and to close the gaps,
  • to install Longhorn with Helm and prove that a volume is stored three times,
  • to run an embedding model with Ollama in the cluster and query the first vector.

This is how every chapter is structured: first it says 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 each drill, a Remember sums up the core, and before the interview note you test yourself with a few questions.

Background

The picture of the day: a city library with branches

Imagine the whole course as a city library. In a normal library, books are arranged by shelf mark – alphabetically or by subject. In our library, every book stands where similar books stand: a book about Kubernetes storage stands next to one about Ceph, far away from a cookbook. The place is decided by a librarian who reads every book and gives it a position in the room. This position is the vector.

The library has several branches. So that nothing is lost when a branch has to close, second copies of important books are kept in another branch, and a library council decides by majority which branch keeps which holdings. You will build that from Day 5 on.

Today the building is created:

  • vdb1 is the headquarters. This is where the administration sits (the Kubernetes server), where the librarian works (the embedding model), and where your workbench stands, from which you operate and measure everything.
  • vdb2, vdb3 and vdb4 are the branches. From Day 2 on, the database will stand in them.
  • Longhorn is the closed stacks. It stores each branch’s data on disks and keeps copies of every storage area on other nodes.
  • Ollama with nomic-embed-text is the librarian. It receives a text and answers with 768 numbers – the position of this text in the space of meanings.

The terms

Term Meaning In the picture
vdb1 VM with k3s server, Ollama and workbench headquarters with administration
vdb2–vdb4 VMs with the k3s agent, worker nodes branches
k3s lean, complete Kubernetes distribution in a single file administration of the library
Longhorn distributed block storage for Kubernetes closed stacks with copies in several buildings
StorageClass template from which Kubernetes creates volumes order form for the closed stacks
PVC request for a volume by an application completed order
Embedding vector that describes the meaning of a text position of a book in the room
Ollama runtime for language and embedding models the librarian’s workplace
nomic-embed-text open embedding model with 768 dimensions the librarian

Remember: A vector database is a library in which books are arranged by similarity. Today you build the building, the closed stacks and the librarian – the shelves come from Day 2 on.

Why four nodes

For Kubernetes alone, one would be enough. But the course wants to show real failures: in distributed mode, Qdrant keeps its state with the consensus protocol Raft, and that needs a majority. With three data nodes, one may fail, and the other two still form the majority. With two data nodes, every failure would immediately mean a standstill. The fourth node, vdb1, remains the stable headquarters: from there you observe what happens while something breaks in the branches.

Why Longhorn

A database in Kubernetes needs volumes that survive a pod restart. For this, k3s ships with local-path: a directory on exactly one node. That is simple, but it can neither grow nor survive a node failure. Longhorn creates every volume as a block device and by default keeps three copies on different nodes. It can expand volumes and create snapshots. This lets you play through the storage topics of the course for real – full volume, expanding a volume, volume after a node failure. From Day 3 on, you will also see why double redundancy (Longhorn and Qdrant copying) costs storage and when to switch it off.

The site

VM IP in the lab Role Size at the author’s
vdb1 172.16.0.182 k3s server, Ollama, workbench 12 vCPU, 12 GB, 80 GB
vdb2 172.16.0.126 data node 8 vCPU, 16 GB, 80 GB
vdb3 172.16.0.83 data node 2 vCPU, 8 GB, 30 GB
vdb4 172.16.0.228 data node 2 vCPU, 8 GB, 30 GB

Your addresses are different. Wherever the course says 172.16.0.…, use your own. If a command block is headed # on vdb1, you run it on vdb1; # on your computer means the computer you are sitting at. The author’s VMs are larger than required; times and load will therefore differ somewhat for you.

Drill 1: Access to the four 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 vdb1 works without a password, and four VMs called vdb1 to vdb4 that know each other by name.

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

Step 1 – generate a key.

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

ssh-keygen generates a key pair consisting of a private and a public key.

  • -t ed25519 selects the key type Ed25519 – short, fast and the standard today.
  • -f ~/.ssh/vdb sets the file name: private ~/.ssh/vdb, public ~/.ssh/vdb.pub.
  • -C vdb-labor is a comment by which you will later recognize the key on the VMs.

For a lab, you may leave the passphrase prompt empty by pressing Enter.

Expected (excerpt):

Generating public/private ed25519 key pair.
The key fingerprint is:
SHA256:NMJhFwZDQE+tRbj6XwpUGpCOAQd/ZbZAT2gmbyibEig vdb-labor

What you see: The pair has been created. The fingerprint is a short checksum of the public key – yours looks different.

Step 2 – copy the public key to vdb1.

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

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

  • -i ~/.ssh/vdb.pub says which public key is transferred.
  • [email protected] is the user and address. 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 vdb2, vdb3 and vdb4. One command each, each with a password prompt:

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

Each call ends with Number of key(s) added: 1.

Step 4 – create short names. So that you don’t have to type the key, user and address every time, you add the VMs to the SSH configuration:

# on your computer
nano ~/.ssh/config

nano <datei> opens the file in the terminal editor; if it doesn’t exist yet, nano creates it when saving. nano is the editor throughout the course:

  • The arrow keys move the cursor; you simply type text.
  • Paste from the clipboard: right-click, Cmd+V on the Mac, Ctrl+Shift+V on Linux.
  • Ctrl+O saves (Enter confirms the name), Ctrl+X exits nano.
  • Files under /etc belong to root; you open them with sudo nano <datei>.

Go to the end of the file and append the lines marked in green; whatever is already there stays:

~/.ssh/config changes in green
Host vdb1
    HostName 172.16.0.182
Host vdb2
    HostName 172.16.0.126
Host vdb3
    HostName 172.16.0.83
Host vdb4
    HostName 172.16.0.228
Host vdb1 vdb2 vdb3 vdb4
    User ubuntu
    IdentityFile ~/.ssh/vdb

Each Host section applies to the short names given: HostName is the real address, User the user, IdentityFile the private key. The last section names all four names so that you write the user and key only once.

Step 5 – give the VMs their names. Kubernetes takes the hostname as the node name, and the outputs in the book contain it everywhere. Log in to vdb1:

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

hostnamectl set-hostname vdb1 sets the hostname 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 hypervisor’s value. A small file for cloud-init, the program that sets up these images at boot, prevents this:

# on vdb1
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: don’t touch the existing name.

Step 6 – know the neighbors by name. The four VMs should reach each other by their names; the k3s agent, for example, will register with vdb1. Without your own DNS server, you add the names to the hosts file:

# on vdb1
sudo nano /etc/hosts

Two changes: the line with 127.0.1.1 still contains the old hostname – replace it with vdb1. And the four addresses are added at the end. The whole file at the author’s afterwards:

/etc/hosts changes in green
# 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
#
127.0.1.1 vdb1 vdb1
127.0.0.1 localhost

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

172.16.0.182 vdb1
172.16.0.126 vdb2
172.16.0.83 vdb3
172.16.0.228 vdb4

The comment at the top says: cloud-init may rewrite the file from a template at every boot. Check whether the template exists:

# on vdb1
ls /etc/cloud/templates/hosts.debian.tmpl

If it exists, open it with sudo nano /etc/cloud/templates/hosts.debian.tmpl and append the same four address lines at the end. If ls prints No such file or directory, there is nothing to do. At the author’s, the template existed on vdb1 and vdb3, but not on vdb2 and vdb4.

Log out with exit and do steps 5 and 6 on vdb2, vdb3 and vdb4 – each with its own name in hostnamectl and in the 127.0.1.1 line, and with the same four address lines.

Step 7 – check the names.

# on vdb1
getent hosts vdb4

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

Expected:

172.16.0.228    vdb4

And the other way round from the last branch:

# on vdb4
getent hosts vdb1

Expected:

172.16.0.182    vdb1

Remember: Names first, then the cluster: from now on, the nodes are called vdb1 to vdb4 in every file, not by IP addresses, which can change.

If it doesn’t work

If ssh vdb1 still asks for a password, usually the path after IdentityFile is wrong, or ssh-copy-id ran against a different address. ssh -v vdb1 shows which keys are offered and which are rejected.

Save your progress? Sign up for free

Drill 2: Preparing the nodes for Longhorn

Where you are: on all four VMs, one after another.

What you have afterwards: the packages and kernel modules Longhorn needs on every node – and on vdb1 additionally jq and Python environments.

Longhorn provides volumes via iSCSI: every node on which a pod uses a volume connects via iSCSI to Longhorn’s storage process. For this, every node needs the package open-iscsi. For volumes that several pods read at the same time, Longhorn uses NFS (nfs-common), and for encrypted volumes the kernel module dm_crypt. You set this up now on all four nodes – including vdb1, because pods with volumes run there too.

Step 1 – update the package lists.

# on vdb1
sudo apt-get update

apt-get update downloads the current package lists. Only then does apt install the latest versions.

Expected (last lines):

Fetched 3366 kB in 2s (1631 kB/s)
Reading package lists...

Step 2 – install packages.

# on vdb1
sudo apt-get install -y jq python3-venv open-iscsi nfs-common
  • jq reads JSON responses and extracts fields – Qdrant always answers with JSON.
  • python3-venv allows separate Python environments; in Drill 8 this becomes the workbench.
  • open-iscsi is the iSCSI client through which Longhorn attaches volumes to the node.
  • nfs-common is the NFS client for volumes that several pods share.
  • -y answers the confirmation prompt with yes.

Expected (last line at the author’s):

0 upgraded, 0 newly installed, 0 to remove and 38 not upgraded.

What you see: On the author’s VMs, the packages were already present. On a fresh VM, apt lists the new packages here and ends with … newly installed.

On vdb2, vdb3 and vdb4 you only need the two storage packages:

# on vdb2, vdb3 und vdb4
sudo apt-get update
# on vdb2, vdb3 und vdb4
sudo apt-get install -y open-iscsi nfs-common

Step 3 – load kernel modules at boot. Whether a kernel module is loaded is decided at system boot via files in /etc/modules-load.d/. You create a file for Longhorn:

# on vdb1
sudo nano /etc/modules-load.d/longhorn.conf
/etc/modules-load.d/longhorn.conf new file
nfs
dm_crypt
iscsi_tcp

Each line names a module: nfs for the NFS client, dm_crypt for encryption, iscsi_tcp for iSCSI over the network.

Step 4 – load the modules immediately. So that you don’t have to reboot, you run the service that reads these files at boot:

# on vdb1
sudo systemctl restart systemd-modules-load

No output means success. Check:

# on vdb1
lsmod

lsmod lists all loaded kernel modules.

Expected (excerpt – look for the three lines):

iscsi_tcp              24576  0
dm_crypt               65536  0
nfs                   577536  0

What you see: All three modules are loaded. The second column is the size in memory, the third counts how many other modules or devices are currently using them – none yet.

Step 5 – start the iSCSI service permanently.

# on vdb1
sudo systemctl enable --now iscsid
  • enable starts the service at every future system boot.
  • --now additionally starts it immediately.

Expected:

Created symlink /etc/systemd/system/sysinit.target.wants/iscsid.service → /usr/lib/systemd/system/iscsid.service.

Step 6 – keep multipathd away from the Longhorn devices. Ubuntu installs multipathd, a service that bundles several paths to the same storage device. It also grabs the block devices that Longhorn creates and then blocks them – the volume cannot be mounted. The Longhorn documentation recommends blacklisting the devices /dev/sd… for multipathd:

# on vdb1
sudo nano /etc/multipath.conf
/etc/multipath.conf changes in green
defaults {
    user_friendly_names yes
}
blacklist {
    devnode "^sd[a-z0-9]+"
}

blacklist names devices that multipathd ignores; devnode "^sd[a-z0-9]+" is a regular expression for all device names that start with sd – that is what the Longhorn devices are called on the node. Then reload:

# on vdb1
sudo systemctl restart multipathd

Do steps 3 to 6 on vdb2, vdb3 and vdb4 as well.

Remember: Longhorn needs iSCSI and a quiet multipathd on every node. If that is missing on one node, no pod with a volume will start there later – and the error only shows up then.

Save your progress? Sign up for free

Drill 3: The Kubernetes server

Where you are: on vdb1.

What you have afterwards: a running k3s server and kubectl that works without sudo.

Step 1 – write the configuration. At startup, k3s reads /etc/rancher/k3s/config.yaml. In it you specify what the server should do differently from the default. First create the directory:

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

-p also creates missing parent directories and reports no error if they already exist.

# on vdb1
sudo nano /etc/rancher/k3s/config.yaml
/etc/rancher/k3s/config.yaml new file
node-ip: 172.16.0.182
tls-san:
  - vdb1
disable:
  - traefik
  - local-storage
Setting Value Meaning
node-ip 172.16.0.182 address under which the node appears in the cluster – important if the VM has several networks
tls-san vdb1 additional name in the API server’s certificate so that the agents may address it as vdb1
disable traefik leave out the bundled ingress controller – the course doesn’t need it
disable local-storage leave out the local-path storage so that Longhorn becomes the only StorageClass

Step 2 – download the installation script.

# on vdb1
curl -sfL https://get.k3s.io -o install-k3s.sh
  • -s suppresses the progress display, -f makes curl fail on an HTTP error instead of saving an error page, -L follows redirects.
  • -o install-k3s.sh saves the script to a file instead of executing it directly. That way you can read it beforehand with less install-k3s.sh.

Step 3 – install k3s.

# on vdb1
INSTALL_K3S_VERSION=v1.37.3+k3s1 sh install-k3s.sh

INSTALL_K3S_VERSION=… before the command sets an environment variable for this call only. It pins the version so that your cluster matches the one in the book exactly. sh install-k3s.sh runs the script.

Expected (excerpt):

[INFO]  Using v1.37.3+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.37.3%2Bk3s1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.37.3%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 downloads the checksum list and the k3s file, verifies the file against it (Verifying binary download), creates kubectl as a link to k3s and starts the k3s service.

Step 4 – kubectl without sudo. k3s writes the credentials to /etc/rancher/k3s/k3s.yaml, readable only by root. Without further steps, kubectl therefore fails:

# on vdb1
kubectl get nodes

Expected:

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

You copy the file to your home directory and make it yours:

# on vdb1
mkdir -p ~/.kube
# on vdb1
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
# on vdb1
sudo chown ubuntu:ubuntu ~/.kube/config
# on vdb1
chmod 600 ~/.kube/config
  • chown ubuntu:ubuntu makes the user ubuntu the owner (user and group).
  • chmod 600 allows only the owner to read and write – the file is admin access.

The kubectl built into k3s looks for /etc/rancher/k3s/k3s.yaml first. So that it uses your copy, you set the variable KUBECONFIG – permanently in your shell configuration:

# on vdb1
nano ~/.bashrc

One line goes at the end of the file:

~/.bashrc (Auszug: letzte Zeile) changes in green
export KUBECONFIG=~/.kube/config

Reload the file so that the line applies in this session:

# on vdb1
source ~/.bashrc

Step 5 – check the server.

# on vdb1
kubectl get nodes -o wide

-o wide shows additional columns such as address, operating system and container runtime.

Expected:

NAME   STATUS   ROLES           AGE   VERSION        INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION              CONTAINER-RUNTIME
vdb1   Ready    control-plane   19s   v1.37.3+k3s1   172.16.0.182   <none>        Ubuntu 24.04.5 LTS   6.8.0-151-generic (amd64)   containerd://2.3.7-k3s1

What you see:

Column Value Meaning
STATUS Ready the node reports healthy and accepts pods
ROLES control-plane the API server, scheduler and the cluster’s database run here
INTERNAL-IP 172.16.0.182 the address from node-ip – if a different one appeared here, the configuration would not have been read
CONTAINER-RUNTIME containerd://2.3.7-k3s1 k3s brings its own containerd

Remember: The headquarters is up. Everything you do in the cluster from now on goes through the API server on vdb1 – and for that, kubectl needs a credentials file that only you may read.

Save your progress? Sign up for free

Drill 4: Joining the three branches

Where you are: on vdb1, then on vdb2, vdb3 and vdb4.

What you have afterwards: a cluster with four nodes.

An agent may only join the cluster if it knows a secret: the server’s token.

Step 1 – read the token.

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

Expected (form, shortened – your token is different):

K10…::server:…

What you see: The token begins with K10, followed by a checksum of the cluster CA and, after ::server:, the actual secret. Whoever has it can bring nodes into your cluster – treat it like a password.

Step 2 – the agent configuration on vdb2.

# on vdb2
sudo mkdir -p /etc/rancher/k3s
# on vdb2
sudo nano /etc/rancher/k3s/config.yaml
/etc/rancher/k3s/config.yaml new file
server: https://vdb1:6443
token: K10…::server:…
node-ip: 172.16.0.126
Setting Value Meaning
server https://vdb1:6443 address of the API server; 6443 is the default Kubernetes port
token your token from step 1 insert it in full, not shortened
node-ip 172.16.0.126 this node’s own address

Because the token is in it, only root may read the file:

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

Step 3 – download the script and install the agent.

# on vdb2
curl -sfL https://get.k3s.io -o install-k3s.sh
# on vdb2
INSTALL_K3S_VERSION=v1.37.3+k3s1 sh install-k3s.sh agent

The word agent at the end tells the script: set up this node as an agent, not as a server. The agent reads the server address and token from its config.yaml.

Expected (last lines):

[INFO]  systemd: Enabling k3s-agent unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s-agent.service → /etc/systemd/system/k3s-agent.service.
[INFO]  systemd: Starting k3s-agent

Step 4 – the same on vdb3 and vdb4. The config.yaml file is the same except for node-ip: 172.16.0.83 on vdb3, 172.16.0.228 on vdb4.

Step 5 – check the cluster.

# on vdb1
kubectl get nodes

Expected:

NAME   STATUS   ROLES           AGE    VERSION
vdb1   Ready    control-plane   2m3s   v1.37.3+k3s1
vdb2   Ready    <none>          67s    v1.37.3+k3s1
vdb3   Ready    <none>          34s    v1.37.3+k3s1
vdb4   Ready    <none>          5s     v1.37.3+k3s1

What you see: Four nodes, all Ready, all with the same version. The agents have no role (<none>) – they are pure worker nodes. The age shows the order in which you joined them.

Remember: A node joins with the token, not with a password. Whoever has the token can open branches – hence chmod 600 on every file that contains it.

Save your progress? Sign up for free

Drill 5: Installing Helm

Where you are: on vdb1.

What you have afterwards: Helm 4.3.2, verified by its checksum.

Longhorn, Qdrant and later Milvus, monitoring and Argo CD come as Helm charts: packages of templates and default settings.

Step 1 – download the archive and checksum.

# on vdb1
curl -sfLO https://get.helm.sh/helm-v4.3.2-linux-amd64.tar.gz
# on vdb1
curl -sfLO https://get.helm.sh/helm-v4.3.2-linux-amd64.tar.gz.sha256sum

-O (capital O) saves under the name from the address. If your VM runs on ARM, replace amd64 in both addresses with arm64; uname -m shows you the architecture (x86_64 = amd64, aarch64 = arm64).

Step 2 – verify.

# on vdb1
sha256sum -c helm-v4.3.2-linux-amd64.tar.gz.sha256sum

sha256sum -c <liste> recomputes the checksum of every file in the list and compares.

Expected:

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

Step 3 – unpack and install.

# on vdb1
tar -xzf helm-v4.3.2-linux-amd64.tar.gz

-x extracts, -z decompresses gzip, -f names the file. The result is a directory linux-amd64.

# on vdb1
sudo install -m 0755 linux-amd64/helm /usr/local/bin/helm

install copies the file and sets the permissions with -m 0755: executable for everyone, writable only for root.

# on vdb1
helm version

Expected:

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

Remember: Checksum first, then install. OK means: the file is exactly the one the project published.

Save your progress? Sign up for free

Drill 6: The closed stacks – Longhorn

Where you are: on vdb1.

What you have afterwards: Longhorn as the default StorageClass and proof that a volume has three copies on three nodes.

Step 1 – download the check tool. With longhornctl, Longhorn ships a program that checks all nodes for the prerequisites before you install.

# on vdb1
curl -sfLO https://github.com/longhorn/cli/releases/download/v1.13.0/longhornctl-linux-amd64
# on vdb1
curl -sfLO https://github.com/longhorn/cli/releases/download/v1.13.0/longhornctl-linux-amd64.sha256
# on vdb1
sha256sum -c longhornctl-linux-amd64.sha256

Expected:

longhornctl-linux-amd64: OK
# on vdb1
sudo install -m 0755 longhornctl-linux-amd64 /usr/local/bin/longhornctl
# on vdb1
longhornctl version

Expected:

v1.13.0

Step 2 – the preflight check.

# on vdb1
longhornctl check preflight

check preflight starts a short check pod on every node and collects the result.

Expected (excerpt):

level=error msg="Failed to run preflight checker: namespaces \"longhorn-system\" not found"

What you see: The tool wants to start its check pods in the namespace longhorn-system, which doesn’t exist yet. Create it – Helm will use it shortly anyway:

# on vdb1
kubectl create namespace longhorn-system

Expected:

namespace/longhorn-system created

Once more:

# on vdb1
longhornctl check preflight

The result comes as one long log line; for each node there is a block with info and warn, and with error if there are problems.

Expected (excerpt for vdb1, the other nodes look the same):

vdb1:
  - '[IscsidService] Service iscsid is running'
  - '[NFSv4] NFS4 is supported'
  - '[Packages] nfs-common is installed'
  - '[Packages] open-iscsi is installed'
  - '[KernelModules] nfs is loaded'
  - '[KernelModules] dm_crypt is loaded'
  warn:
  - '[KubeDNS] Kube DNS "coredns" is set with fewer than 2 replicas; consider increasing replica count for high availability'
  - '[MultipathService] multipathd.service is running. Please refer to https://longhorn.io/kb/troubleshooting-volume-with-multipath/ for more information.'

The author first ran the check before completing Drill 2 from step 3 onward. Back then the block looked like this – this is exactly what the check is for:

vdb1:
  error:
  - '[KernelModules] nfs is not loaded. (exit code: 1)'
  - '[KernelModules] dm_crypt is not loaded. (exit code: 1)'
  info:
  - '[IscsidService] Service iscsid is inactive, but it can still be activated by iscsid.socket'

The file in /etc/modules-load.d/ fixes the two errors; systemctl enable --now iscsid fixes the inactive iSCSI service.

What you see: No more errors. Two warnings remain, and both are known:

Warning Why it remains
coredns with fewer than 2 replicas k3s starts one DNS pod; that is enough in the lab. In production there should be two
multipathd is running the check only looks at whether the service is running – not whether it blacklists the devices. The blacklist from Drill 2 is sufficient

Step 3 – add the chart repository.

# on vdb1
helm repo add longhorn https://charts.longhorn.io
# on vdb1
helm repo update longhorn

repo add <name> <url> remembers the address under a short name; repo update downloads the current index of the charts.

# on vdb1
helm search repo longhorn/longhorn --versions

--versions shows all versions instead of only the latest.

Expected (the first lines):

NAME                CHART VERSION   APP VERSION DESCRIPTION                                       
longhorn/longhorn   1.13.0          v1.13.0     Longhorn is a distributed block storage system ...
longhorn/longhorn   1.12.2          v1.12.2     Longhorn is a distributed block storage system ...

Step 4 – install Longhorn.

# on vdb1
helm install longhorn longhorn/longhorn --namespace longhorn-system --version 1.13.0
Setting Value Meaning
first name longhorn name of the installation (release) under which Helm manages it
chart longhorn/longhorn repository short name and chart
--namespace longhorn-system where the objects go
--version 1.13.0 pinned chart version – without it, Helm takes the latest

Expected (excerpt):

I1204 15:50:45.553743  515427 warnings.go:107] "Warning: unrecognized format \"int64\""
NAME: longhorn
NAMESPACE: longhorn-system
STATUS: deployed
REVISION: 1
DESCRIPTION: Install complete

What you see: STATUS: deployed – Helm has created all objects. The lines unrecognized format "int64" are client notices while validating the Longhorn CRDs and are harmless. But the fact that the objects have been created does not yet mean that everything is running.

Step 5 – wait until everything is running.

# on vdb1
kubectl -n longhorn-system rollout status daemonset/longhorn-manager --timeout=300s

rollout status waits until all pods of a DaemonSet (one pod per node) are ready; --timeout=300s gives up after five minutes.

Expected (excerpt):

Waiting for daemon set "longhorn-manager" rollout to finish: 0 of 4 updated pods are available...
Waiting for daemon set "longhorn-manager" rollout to finish: 2 of 4 updated pods are available...
daemon set "longhorn-manager" successfully rolled out

After that, the remaining parts start (CSI driver, instance manager, UI). Wait for all of them:

# on vdb1
kubectl -n longhorn-system wait --for=condition=Ready pod --all --timeout=600s

wait --for=condition=Ready pod --all waits until every pod in the namespace meets the Ready condition. At the author’s, the whole installation took a good five minutes; the last lines read pod/… condition met.

Step 6 – check the StorageClass.

# on vdb1
kubectl get storageclass

Expected:

NAME                 PROVISIONER          RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
longhorn (default)   driver.longhorn.io   Delete          Immediate           true                   4m11s
longhorn-static      driver.longhorn.io   Delete          Immediate           true                   3m54s

What you see:

Column Value Meaning
NAME longhorn (default) default: every PVC without its own setting gets Longhorn
RECLAIMPOLICY Delete if you delete the PVC, the volume is gone too – for databases you will change this on Day 3
ALLOWVOLUMEEXPANSION true volumes may grow; you need that on Day 3

longhorn-static is intended for volumes that you create in Longhorn itself beforehand; you don’t use it in the course.

Step 7 – the nodes from Longhorn’s point of view.

# on vdb1
kubectl -n longhorn-system get nodes.longhorn.io

nodes.longhorn.io is a separate object type of Longhorn: its view of every node and its disks.

Expected:

NAME   READY   ALLOWSCHEDULING   SCHEDULABLE   AGE
vdb1   True    true              True          3m56s
vdb2   True    true              True          3m56s
vdb3   True    true              True          3m56s
vdb4   True    true              True          3m56s

What you see: All four nodes are ready and may accept copies (ALLOWSCHEDULING true).

Step 8 – try out a volume. Create a working directory that will hold all the files of the course:

# on vdb1
mkdir ~/labor
# on vdb1
nano ~/labor/probe.yaml
~/labor/probe.yaml new file
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: probe
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: probe
spec:
  containers:
    - name: probe
      image: docker.io/library/busybox:1.37
      command: ["sh", "-c", "date > /daten/stempel && sleep 3600"]
      volumeMounts:
        - name: daten
          mountPath: /daten
  volumes:
    - name: daten
      persistentVolumeClaim:
        claimName: probe

Two objects in one file, separated by ---:

  • The PVC probe orders 1 GiB; ReadWriteOnce means: writable by one node at a time. It names no StorageClass – so it gets the default class longhorn.
  • The pod probe mounts the volume under /daten, writes the time to the file stempel and then waits for an hour.
# on vdb1
kubectl apply -f ~/labor/probe.yaml

Expected:

persistentvolumeclaim/probe created
pod/probe created
# on vdb1
kubectl wait --for=condition=Ready pod/probe --timeout=180s

Expected:

pod/probe condition met
# on vdb1
kubectl exec probe -- cat /daten/stempel

kubectl exec <pod> -- <befehl> runs a command in the container; everything after -- belongs to the command.

Expected:

Fri Dec  4 15:56:57 UTC 2026

Step 9 – prove the copies. The fact that a volume exists does not yet mean that it is stored three times. Longhorn keeps each copy as a separate object of type replicas.longhorn.io:

# on vdb1
kubectl -n longhorn-system get replicas.longhorn.io

Expected (truncated on the right):

NAME                                                  DATA ENGINE   STATE     NODE   DISK
pvc-81bb0c71-3c16-432e-b730-411d61a20261-r-02d86448   v1            running   vdb1   f2a6322a-c50d-422d-b832-4d1ecd24c302
pvc-81bb0c71-3c16-432e-b730-411d61a20261-r-cc48f4a8   v1            running   vdb3   db0e63d0-d917-4442-ac0d-583bde2e35d0
pvc-81bb0c71-3c16-432e-b730-411d61a20261-r-d1c45e7f   v1            running   vdb2   f50403e4-74ed-4b34-ba39-f95107dd0c27
# on vdb1
kubectl get pod probe -o wide

Expected (excerpt):

NAME    READY   STATUS    RESTARTS   AGE   IP           NODE
probe   1/1     Running   0          27s   10.42.1.16   vdb2

What you see: Three copies of the same volume are on vdb1, vdb2 and vdb3, and all three are running. The pod itself runs on vdb2. If a node with a copy fails, the data is still there twice. Remember this number: from Day 5 on, Qdrant itself copies too – then the data quickly exists nine times in the cluster.

Step 10 – clean up.

# on vdb1
kubectl delete -f ~/labor/probe.yaml

Expected:

persistentvolumeclaim "probe" deleted from default namespace
pod "probe" deleted from default namespace

Remember: A PVC in status Bound only proves that a volume exists. How often and where it is stored is shown only by Longhorn’s replicas – prove instead of assume.

Save your progress? Sign up for free

Drill 7: The librarian – Ollama with nomic-embed-text

Where you are: on vdb1.

What you have afterwards: an embedding model in the cluster that returns a vector of 768 numbers for every text.

So that you can translate real texts into vectors from tomorrow on, the cluster needs an embedding service. Ollama runs models on the CPU; nomic-embed-text is an open model of 274 MB that returns 768 numbers for every text. It runs on vdb1 because that is where most of the cores are and the branches should stay free for the database.

Step 1 – the manifest.

# on vdb1
nano ~/labor/ollama.yaml
~/labor/ollama.yaml new file
apiVersion: v1
kind: Namespace
metadata:
  name: ollama
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: modelle
  namespace: ollama
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ollama
  namespace: ollama
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: ollama
  template:
    metadata:
      labels:
        app: ollama
    spec:
      nodeSelector:
        kubernetes.io/hostname: vdb1
      containers:
        - name: ollama
          image: docker.io/ollama/ollama:0.40.21
          ports:
            - containerPort: 11434
          resources:
            requests:
              cpu: "2"
              memory: 2Gi
            limits:
              memory: 4Gi
          volumeMounts:
            - name: modelle
              mountPath: /root/.ollama
      volumes:
        - name: modelle
          persistentVolumeClaim:
            claimName: modelle
---
apiVersion: v1
kind: Service
metadata:
  name: ollama
  namespace: ollama
spec:
  selector:
    app: ollama
  ports:
    - port: 11434
      targetPort: 11434
Setting Value Meaning
PVC modelle 5Gi this is where Ollama stores downloaded models – they survive a restart
strategy: Recreate on update, stop the old pod first; an RWO volume cannot be attached to two pods at once
nodeSelector kubernetes.io/hostname: vdb1 the pod runs only on vdb1; Kubernetes sets this label on every node itself
image ollama/ollama:0.40.21 pinned version
requests 2 CPU, 2Gi this much the scheduler reserves for the pod
limits.memory 4Gi the container may not take more memory than this, otherwise the kernel terminates it
mountPath /root/.ollama this is where Ollama looks for its models
Service port 11434 fixed address in the cluster for Ollama’s API

Step 2 – apply.

# on vdb1
kubectl apply -f ~/labor/ollama.yaml

Expected:

namespace/ollama created
persistentvolumeclaim/modelle created
deployment.apps/ollama created
service/ollama created

Step 3 – wait. The Ollama image is large. At the author’s, the download took 6 minutes 27 seconds for 3.47 GB – hence a generous timeout:

# on vdb1
kubectl -n ollama rollout status deployment/ollama --timeout=900s

Expected:

Waiting for deployment "ollama" rollout to finish: 0 of 1 updated replicas are available...
deployment "ollama" successfully rolled out

If the timeout expires, the download is usually not finished yet. kubectl -n ollama describe pod -l app=ollama then shows the event Pulling image "docker.io/ollama/ollama:0.40.21" at the very bottom; simply repeat the command.

Step 4 – load the model.

# on vdb1
kubectl -n ollama exec deploy/ollama -- ollama pull nomic-embed-text

exec deploy/ollama selects a pod of the deployment without you having to know its name. ollama pull downloads the model to the volume.

Expected (last lines):

writing manifest
success
# on vdb1
kubectl -n ollama exec deploy/ollama -- ollama list

Expected:

NAME                       ID              SIZE      MODIFIED      
nomic-embed-text:latest    0a109f422b47    274 MB    2 seconds ago    

What you see: The model is there. The ID 0a109f422b47 identifies exactly this version of the model; if yours shows a different one, the model has been republished since, and your vectors will differ minimally.

Step 5 – read the address of the service.

# on vdb1
kubectl -n ollama get service ollama

Expected:

NAME     TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)     AGE
ollama   ClusterIP   10.43.16.22   <none>        11434/TCP   5m6s

What you see: The cluster IP is reachable inside the cluster – and also from the nodes themselves, because k3s sets the rules for services on every node. However, names like ollama.ollama.svc are known only to the DNS in the cluster, not to the VM. On vdb1 you therefore use the IP. Yours is different; insert it in the next step.

Step 6 – the first vector.

# on vdb1
curl -s http://10.43.16.22:11434/api/embed -d '{"model": "nomic-embed-text", "input": "Wie sichere ich eine Vektordatenbank?"}' -o antwort.json
  • /api/embed is Ollama’s endpoint for embeddings.
  • -d '…' sends the JSON text as the body of a POST request: model names the model, input the text.
  • -o antwort.json saves the response to a file instead of writing 768 numbers to the terminal.
# on vdb1
jq '.embeddings[0] | length' antwort.json

jq reads the file: .embeddings[0] is the first (here the only) vector, | length counts its entries.

Expected:

768
# on vdb1
jq -c '.embeddings[0][0:4], .model, .total_duration' antwort.json

-c writes each result compactly on one line; [0:4] takes the first four numbers; .total_duration is the computation time in nanoseconds.

Expected:

[0.044823967,-0.039037786,-0.1731708,0.036394645]
"nomic-embed-text"
1495099473

What you see: The sentence is now a point in a space with 768 axes. The first request took just under 1.5 seconds because Ollama first had to load the model into memory; subsequent ones are much faster. What these numbers mean and how to search with them is the subject of Day 1.

Remember: The librarian translates every text into the same language: 768 numbers. Only vectors from the same model are comparable with each other – if the model changes, all holdings must be reclassified.

Save your progress? Sign up for free

Drill 8: The workbench

Where you are: on vdb1.

What you have afterwards: a Python environment with the Qdrant client and the libraries for the measurements of the coming days.

From Day 1 on, you write small Python programs: loading data, searching exactly, measuring recall, generating load. So that they don’t collide with the system’s Python packages, they get their own environment.

Step 1 – create the environment.

# on vdb1
python3 --version

Expected:

Python 3.12.3
# on vdb1
python3 -m venv ~/werkbank

-m venv <verzeichnis> creates a virtual environment: a directory with its own python and pip. Whatever you install there is visible only to this environment.

Step 2 – install packages, with fixed versions.

# on vdb1
~/werkbank/bin/pip install qdrant-client==1.20.0 numpy==2.5.5 requests==2.34.2
  • qdrant-client talks to Qdrant via HTTP and gRPC.
  • numpy computes with vectors – for exact search and recall.
  • requests sends HTTP requests to Ollama.
  • == pins the version so that your results match those in the book.

Step 3 – check.

# on vdb1
~/werkbank/bin/pip list

Expected (excerpt):

grpcio             1.86.0
httpx              0.29.0
numpy              2.5.5
qdrant-client      1.20.0
requests           2.34.2

What you see: The Qdrant client brings grpcio and httpx along – it can speak both protocols.

Remember: The workbench stands in the headquarters, not in a branch. When branches fail from Day 6 on, you keep measuring.

Save your progress? Sign up for free

Checkpoint

Run these commands and compare.

# on vdb1
kubectl get nodes

Expected: four nodes vdb1 to vdb4, all Ready, all v1.37.3+k3s1.

# on vdb1
kubectl get pods -A -o wide

Expected (excerpt without Longhorn, columns shortened):

NAMESPACE     NAME                                 READY   STATUS      NODE
kube-system   coredns-b665f9f77-dkq9h              1/1     Running     vdb1
kube-system   helm-install-gateway-api-crd-m28x9   0/1     Completed   vdb1
kube-system   metrics-server-7ff696777f-4s6r5      1/1     Running     vdb1
ollama        ollama-854f7d9b7f-9jsmp              1/1     Running     vdb1
# on vdb1
kubectl top nodes

Expected (your numbers will differ):

NAME   CPU(cores)   CPU(%)   MEMORY(bytes)   MEMORY(%)   
vdb1   1550m        12%      2372Mi          19%         
vdb2   322m         4%       781Mi           4%          
vdb3   207m         10%      612Mi           7%          
vdb4   231m         11%      763Mi           9%          

What you see: kubectl top uses the metrics-server that k3s ships with. The branches are almost empty – no database stands in them yet.

# on vdb1
kubectl get storageclass

Expected: longhorn (default).

# on vdb1
jq '.embeddings[0] | length' antwort.json

Expected: 768.

Test yourself

  1. Why does the course need three data nodes and not two?
  2. What happens if the open-iscsi package is missing on vdb3, and when do you notice it?
  3. How do you recognize that a Longhorn volume really is stored on three nodes?
  4. Why is the k3s server’s token only kept in files with chmod 600?
  5. Why can you reach Ollama on vdb1 via the cluster IP, but not via ollama.ollama.svc?
  6. What do you have to do if you swap the embedding model for another one?

Answers:

  1. Qdrant keeps its cluster state with Raft, and Raft needs a majority. With three members, two remain after a failure – the majority. With two members, one remains, and that is not a majority.
  2. Pods with a Longhorn volume cannot start on vdb3 because the node cannot attach the volume via iSCSI. You only notice it when the scheduler places such a pod on vdb3 – hence longhornctl check preflight beforehand.
  3. By the replicas.longhorn.io objects: three entries with STATE running and three different names in the NODE column. Bound on the PVC does not show that.
  4. Whoever knows the token can bring their own nodes into the cluster and thus run pods with access to data and secrets. It is a secret like a password.
  5. k3s sets the rules for cluster IPs on every node, but the names are resolved only by the cluster DNS (coredns), which the VM itself does not query.
  6. Re-embed all texts. Vectors from different models live in different spaces – comparing them is meaningless, even if the dimension happens to be the same.

Interview note

“Why run a vector database on Kubernetes and not simply as a managed service?” – Because the data often must not leave the company, because costs rise quickly with large holdings, and because you want to decide failure behavior, upgrades and backups yourself. The price: you need knowledge of storage, consensus and capacity – exactly what this course practices.

Enterprise note

In production, the Kubernetes server does not stand alone: three servers with embedded etcd, separate node groups for databases with local NVMe disks and taints so that nothing else runs there. Longhorn gets its own disks instead of the system disk. The embedding model often runs on GPU nodes or as a central service. The lab reproduces the roles, not the sizes.

Summary

  • Four VMs are called vdb1 to vdb4 and know each other by name; you reach them with your own key.
  • k3s runs as a server on vdb1 and as an agent on three branches; kubectl uses your own copy of the credentials file.
  • Longhorn is checked (longhornctl check preflight), installed and the default StorageClass; a volume is demonstrably stored three times.
  • Ollama with nomic-embed-text returns a vector of 768 numbers for every text.
  • The workbench in ~/werkbank has the Qdrant client and numpy.

Commands at a glance

Command Purpose
ssh-keygen -t ed25519 -f ~/.ssh/vdb -C vdb-labor generate the lab key
ssh-copy-id -i ~/.ssh/vdb.pub ubuntu@<ip> put the key on a VM
sudo hostnamectl set-hostname vdb1 set the hostname
getent hosts vdb4 check name resolution
sudo systemctl enable --now iscsid start the iSCSI service
INSTALL_K3S_VERSION=v1.37.3+k3s1 sh install-k3s.sh install the k3s server
… sh install-k3s.sh agent install the k3s agent
sha256sum -c <file>.sha256sum verify a download
longhornctl check preflight check nodes for Longhorn prerequisites
helm install longhorn longhorn/longhorn -n longhorn-system --version 1.13.0 install Longhorn
kubectl -n longhorn-system get replicas.longhorn.io prove the copies of a volume
kubectl -n ollama exec deploy/ollama -- ollama pull nomic-embed-text load the model
curl -s http://<ip>:11434/api/embed -d '…' -o antwort.json embed a text
jq '.embeddings[0] \| length' antwort.json count the vector’s dimension
python3 -m venv ~/werkbank create a Python environment

Contents

More