Preparation: The building – two VMs, one cluster and the first building badge
Goal: set up access to two VMs, install the course tools, build a Kubernetes cluster with two nodes and look at the identity every pod already brings along · Duration: about 90 min · Prerequisite: two fresh VMs with Ubuntu 24.04, a machine with SSH
Where we start
You need two VMs with Ubuntu 24.04 that you can log in to over SSH with a username and password, and your own machine with a terminal. The first VM needs at least 4 vCPU and 8 GB of memory, because Keycloak and a language model will run on it later; the second one gets by with 2 vCPU and 4 GB. Both must be able to reach each other on the network and be allowed out to the internet. That’s all – you set up everything else today.
Introduction
This course is about a single question: Who are you, and how do I know? A service that queries a database, a pod that fetches a key from a vault, an AI agent that creates a ticket on behalf of a human – every time, the other side has to decide whether to trust the request. In many companies this still happens with a password that sits somewhere in a file, an environment variable or a Git repository. This course shows, step by step, how to do it without a single static password.
Today you build the grounds for that: two VMs, the tools you use to read and verify badges, and a small Kubernetes cluster with two nodes. Even here you meet the topic of the course twice: once as a password you need for the setup, and once as a badge that Kubernetes hands every pod without being asked. Today you only look at both. What is dangerous about them and how to do better is the material for the coming days.
Today you will learn:
- to create your own SSH key for the lab and set up short names for the VMs,
- to verify a downloaded program against its checksum before you install it,
- to install k3s as a Kubernetes server and join a second node,
- to store the access file for
kubectlso that only you can read it, - to find the document in which a cluster introduces itself as an issuer of badges,
- to open a pod’s badge with
stepand read its fields.
Every chapter is built the same way: first, in words, what you do and why, then 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 in one sentence, and before the interview note you test yourself with a few questions.
Background
The picture for today: an office building with a reception desk
Picture the whole course as an office building. Staff and machines work inside – those are your workloads. Visitors come in from outside – those are humans who log in. And there are assistants who run errands in the building on behalf of a human – those will later be the AI agents. Anyone who wants to open a door has to show who they are.
Today the building goes up:
- id1 is the main building. Reception and administration sit here: the Kubernetes server, which decides who may do what, and later the badge offices.
- id2 is the annex. It belongs to the same company but has no administration of its own. Workloads work here, and later this is where the other end stands when two services show each other their badges.
- The join token is the master key for the builders. Whoever has it may connect a new annex to the company. It is a classic static password – you need it today, and on Day 1 you see all the places where it lies around.
- The building badge is the token Kubernetes hands every pod. Every new member of staff gets it automatically, whether they need it or not.
- The notice at reception is the cluster’s discovery document. It says who issues the badges and where the specimens of the seals hang that you can use to verify them.
The terms
| Term | Meaning | in the picture |
|---|---|---|
| id1 | VM with the k3s server, later Keycloak, SPIRE server and language model | main building with reception |
| id2 | VM with the k3s agent, second node | annex |
| k3s | lean Kubernetes distribution in a single file | building management |
| join token | shared secret a node uses to register with the server | master key of the builders |
| kubeconfig | file with address and credentials for kubectl |
the caretaker’s key ring |
| ServiceAccount token | signed JSON Web Token (JWT) that a pod receives | building badge |
| Issuer | issuer of a token, stored in the iss field |
badge office |
| Discovery document | JSON at /.well-known/openid-configuration |
notice at reception |
Remember: Every request in the building needs a badge. Today you see that Kubernetes issues one to every pod – and that you still use a master key for the construction itself.
Why two VMs
You type almost everything in this course on id1. For three things, though, you need a second machine: a pod on another node shows that a badge can be bound to the node it was issued on. The SPIRE agent on Day 5 verifies workloads on their node, and that is only convincing when there are two nodes. And for mutual TLS on Day 7, two services should really talk to each other over the network, not just inside one machine.
Why k3s
k3s is a complete, certified Kubernetes that comes as a single file and is installed with a script. What matters for this course: the k3s API server is the same as in any other Kubernetes. ServiceAccount tokens, the OIDC issuer and the TokenRequest API, which Day 2 and 3 are about, behave just as they do in a large production cluster. k3s only saves you the work of setting up certificates, etcd and networking yourself.
You switch off the bundled Traefik ingress controller. The course does not need it and it would only use memory.
The tools
| Tool | Package | What for in the course |
|---|---|---|
kubectl |
comes with k3s | operate the cluster, request tokens |
jq |
jq |
read JSON and pull out fields |
step |
step-cli from Smallstep |
open and verify JWTs, read certificates, create keys |
python3 -m venv |
python3-venv |
separate environment for the Python agents from Day 10 |
curl |
curl (preinstalled) |
HTTP requests to issuers, Keycloak and services |
openssl |
openssl (preinstalled) |
look at certificates and TLS connections |
step is the most important new tool. It shows the
contents of a token in readable form, verifies its signature against a
public key and displays certificates in a way you can understand even
without OpenSSL experience.
The grounds
| VM | IP in the lab | Role | Size |
|---|---|---|---|
| id1 | 172.16.0.126 | k3s server, later Keycloak, SPIRE server, Ollama | 4 vCPU, 11 GB, 80 GB |
| id2 | 172.16.0.228 | k3s agent, second node | 2 vCPU, 7.8 GB, 30 GB |
Your addresses are different. Wherever the course says
172.16.0.…, put in your own. If a command block starts with
# on id1, you run it on id1; # on your machine
means the machine you are sitting at. The author’s VMs have a little
more memory than required; where that changes an output, the text says
so.
Drill 1: Access to the two VMs
Where you are: on your own machine, in a terminal.
What you have afterwards: your own SSH key and short names that make
ssh id1work without a password, and VMs called id1 and id2 that know each other by name.
You work on the VMs over 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. By the way, an SSH key is already the better kind of identity this course is about: the VM only knows your public key, and the secret never leaves your machine.
Step 1 – Create the key.
# on your machine
ssh-keygen -t ed25519 -f ~/.ssh/id -C id-laborssh-keygen creates a key pair made of a private and a
public key.
-t ed25519selects the key type Ed25519 – short, fast and the standard today.-f ~/.ssh/idsets the file name: the private key ends up in~/.ssh/id, the public one in~/.ssh/id.pub.-C id-laboris a comment. It later appears in theauthorized_keysfile on the VMs so that you recognize the key there.
The program asks for a passphrase. For a lab, you may leave it empty by pressing Enter.
Expected (excerpt):
Generating public/private ed25519 key pair.
Your identification has been saved in ~/.ssh/id
Your public key has been saved in ~/.ssh/id.pub
The key fingerprint is:
SHA256:AakhVVoPxG7pIsnVikUh3a0eoAIe5JWZfjZA2IC420g id-labor
What you see: two files and a fingerprint. The fingerprint is a short checksum of the public key – yours looks different.
Step 2 – Copy the public key to id1.
# on your machine
ssh-copy-id -i ~/.ssh/id.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/id.pubsays which public key to transfer.[email protected]is the user and address of the VM. If your user has a different name, replaceubuntu.
Expected (excerpt, after the password prompt):
Number of key(s) added: 1
Step 3 – The same for id2.
# on your machine
ssh-copy-id -i ~/.ssh/id.pub [email protected]Here too, Number of key(s) added: 1 appears after the
password.
Step 4 – Set up short names. So that you don’t have to type key, user and address every time, you add the VMs to the SSH configuration. Open the file in the nano editor:
# on your machine
nano ~/.ssh/confignano <datei> opens the file in the terminal. If it
doesn’t 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 in the terminal with a right-click, on the Mac with Cmd+V, on Linux with Ctrl+Shift+V.
- Ctrl+O saves, Enter confirms the file name. Ctrl+X exits nano.
- Files under
/etcbelong to root. You open them withsudo nano <datei>.
Go to the end of the file and add these lines. If the file already contains something, it stays unchanged; what you add is highlighted in green:
Host id1
HostName 172.16.0.126
Host id2
HostName 172.16.0.228
Host id1 id2
User ubuntu
IdentityFile ~/.ssh/idEach 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 machine
ssh id1 hostnamessh id1 <befehl> logs in, runs the command and
logs out again. hostname prints the name of the VM.
Expected:
id1
What you see: the login went through without a
password prompt. If you still see a different name, such as
ubuntu, you give the VM its course name in the next
step.
Step 6 – Give the VMs their names. Many outputs in the course contain the node name – Kubernetes uses it as the node’s name, and it ends up in every pod’s badge. So that your outputs match the ones in the book, the VMs are called id1 and id2. Log in to id1:
# on your machine
ssh id1# on id1
sudo hostnamectl set-hostname id1hostnamectl set-hostname id1 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 value from the hypervisor configuration. A small file for cloud-init, the program that sets up these images at boot, prevents that:
# on id1
sudo nano /etc/cloud/cloud.cfg.d/99-hostname.cfgpreserve_hostname: truepreserve_hostname: true tells cloud-init: leave the name
the system already has alone.
Step 7 – Know the neighbours by name. id1 and id2
should reach each other by name. Your lab has no DNS server for this, so
you add the names to the hosts file. On cloud images, cloud-init
rewrites /etc/hosts from a template at every boot – that is
why you change the template, not the file:
# on id1
sudo nano /etc/cloud/templates/hosts.debian.tmplGo to the end of the template and add two lines (your addresses):
172.16.0.126 id1
172.16.0.228 id2So that the template takes effect right away and not only at the next
boot, you also append the same two lines to /etc/hosts:
# on id1
sudo nano /etc/hosts172.16.0.126 id1
172.16.0.228 id2Log out with exit and do steps 6 and 7 the same way on
id2 – there with sudo hostnamectl set-hostname id2 and the
same two lines.
Step 8 – Check the names.
# on id1
getent hosts id2getent hosts <name> asks the system’s name
resolution – exactly what k3s and every other program use, not just
DNS.
Expected:
172.16.0.228 id2
From id2 you check the other way round:
# on id2
getent hosts id1Expected:
172.16.0.126 id1
Remember: An SSH key is an identity whose secret never leaves the house: the VM only knows the lock (the public key), and you keep the key.
If it doesn’t work
If ssh id1 still asks for a password, usually the path
after IdentityFile doesn’t match the key from step 1, or
ssh-copy-id ran against a different address.
ssh -v id1 shows which keys ssh offers and which one is
rejected.
Save your progress? Sign up for free
Drill 2: Install the tools
Where you are: on id1.
What you have afterwards:
jq,python3-venvand thesteptool, which you verified against its checksum before installing it.
Most tools come from the Ubuntu package sources. step,
on the other hand, you download directly from the vendor. That is a good
occasion for a habit that suits this course: before you install a
downloaded program, you check that it really is what the vendor
published.
Step 1 – Update the package lists.
# on id1
sudo apt-get updateapt-get update downloads the current package lists from
the sources. Without this step, the system only knows the versions from
the time the image was built.
Expected (last line):
Reading package lists...
Step 2 – Install jq and python3-venv.
# on id1
sudo apt-get install -y jq python3-venvinstallinstalls the listed packages including their dependencies.-yanswers the prompt “Do you want to continue?” with yes.jqreads JSON,python3-venvallows separate Python environments from Day 10.
Expected (excerpt, end):
No services need to be restarted.
No containers need to be restarted.
If jq is already installed, apt just says so and carries
on.
Step 3 – Determine the architecture. The vendor of
step offers a separate package for each processor
architecture. dpkg tells you which one your VM has:
# on id1
dpkg --print-architectureExpected:
amd64
What you see: amd64 stands for 64-bit
x86 (Intel, AMD). On an ARM machine, such as a VM on a Mac with Apple
silicon, it says arm64 here. In that case replace
amd64 with arm64 in the next commands.
Step 4 – Download the package.
# on id1
curl -fsSLO https://github.com/smallstep/cli/releases/download/v0.31.0/step-cli_0.31.0-1_amd64.deb| Option | Value | Meaning |
|---|---|---|
-f |
fail | abort on an HTTP error instead of saving an error page |
-s |
silent | don’t print a progress bar |
-S |
show-error | show errors despite -s |
-L |
location | follow redirects – GitHub redirects downloads to a storage server |
-O |
remote-name | save under the file name from the URL |
The command prints nothing if everything works.
Step 5 – Download the checksum list. Alongside each
release, Smallstep publishes a checksums.txt file with the
SHA-256 checksum of every file:
# on id1
curl -fsSLO https://github.com/smallstep/cli/releases/download/v0.31.0/checksums.txtThis prints nothing either. ls shows whether both files
are there:
# on id1
ls -l step-cli_0.31.0-1_amd64.deb checksums.txtExpected:
-rw-rw-r-- 1 ubuntu ubuntu 6022 Dec 1 08:04 checksums.txt
-rw-rw-r-- 1 ubuntu ubuntu 14922896 Dec 1 08:04 step-cli_0.31.0-1_amd64.deb
Step 6 – Verify the checksum.
# on id1
sha256sum --check --ignore-missing checksums.txt--checkreads the list and recomputes the checksum for each file it names.--ignore-missingskips files from the list that you haven’t downloaded – the list names packages for all architectures.
Expected:
step-cli_0.31.0-1_amd64.deb: OK
What you see: the file on your disk has exactly the
checksum the vendor published. If it said FAILED here, the
file would be damaged or altered – then don’t install it. To be honest,
this only protects against transfer errors and a tampered storage
server, not against an attacker who swaps both files in the release. How
to check that too is the subject of another course (signatures with
Sigstore).
Step 7 – Install step.
# on id1
sudo apt-get install -y ./step-cli_0.31.0-1_amd64.debThe ./ in front of the file name matters: it tells apt
to install a local file rather than look for a package of that name in
the sources.
Step 8 – Check the versions.
# on id1
step versionExpected:
Smallstep CLI/0.31.0 (linux/amd64)
Release Date: 2026-09-25T19:53:51Z
# on id1
jq --versionExpected:
jq-1.7
# on id1
python3 --versionExpected:
Python 3.12.3
Remember: Checksum first, then installation. Whoever installs something from the network trusts the sender – the checksum shows that nobody swapped the package along the way.
If it doesn’t work
If curl reports error 404, the version in the path is
wrong. You can find the current version on the release page of
smallstep/cli on GitHub; the package name and path then
change in both places.
Save your progress? Sign up for free
Drill 3: Install the k3s server on id1
Where you are: on id1.
What you have afterwards: a running Kubernetes server and
kubectlworking with an access file only you can read.
k3s is installed with a shell script. Many guides pipe it straight
from curl into a shell. You do it in two steps: first
download and look at it, then run it. A script that runs with root
privileges deserves at least one look.
Step 1 – Download the installation script.
# on id1
curl -fsSL https://get.k3s.io -o k3s-install.sh-o k3s-install.sh saves under this name; you know the
other options from Drill 2.
Step 2 – Look at the script.
# on id1
head -5 k3s-install.shExpected:
#!/bin/sh
set -e
set -o noglob
# Usage:
# on id1
wc -l k3s-install.shExpected:
1218 k3s-install.sh
What you see: a POSIX shell script with a good 1,200
lines. set -e aborts at the first error. If you like, read
the whole thing with less k3s-install.sh – the top lists
all the environment variables that control it.
Step 3 – Install k3s.
# on id1
INSTALL_K3S_VERSION=v1.37.2+k3s1 sh k3s-install.sh --disable traefik| Option | Value | Meaning |
|---|---|---|
INSTALL_K3S_VERSION= |
v1.37.2+k3s1 |
install exactly this version instead of the latest – so your outputs match the book |
sh k3s-install.sh |
runs the script; it calls sudo itself where it needs
root privileges |
|
--disable traefik |
don’t start this component; everything after the script name goes to
k3s server |
Without further options, the script installs a server, that is, a node with API server, scheduler and built-in database.
Expected:
[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] Skipping installation of SELinux RPM
[INFO] Creating /usr/local/bin/kubectl symlink to k3s
[INFO] Creating /usr/local/bin/crictl symlink to k3s
[INFO] Creating /usr/local/bin/ctr symlink to k3s
[INFO] Creating killall script /usr/local/bin/k3s-killall.sh
[INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO] env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO] systemd: Creating service file /etc/systemd/system/k3s.service
[INFO] systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
[INFO] systemd: Starting k3s
What you see: the script itself checks the
downloaded file against a checksum
(Verifying binary download) – exactly as you did by hand in
Drill 2. kubectl, crictl and ctr
are not separate programs but links to the single k3s file.
Finally, the script sets up a systemd service and starts it.
Step 4 – Check the service.
# on id1
systemctl status k3s --no-pager--no-pager prints the output directly instead of opening
it in less.
Expected (excerpt, first lines):
● k3s.service - Lightweight Kubernetes
Loaded: loaded (/etc/systemd/system/k3s.service; enabled; preset: enabled)
Active: active (running) since Tue 2026-12-01 08:05:44 UTC; 5s ago
Docs: https://k3s.io
What you see: active (running) – the
server is running. enabled means it also starts after a
reboot of the VM.
Step 5 – Who may read the access file? k3s writes the administrator’s credentials to a file. Look at its permissions:
# on id1
sudo ls -l /etc/rancher/k3s/k3s.yamlExpected:
-rw------- 1 root root 2941 Dec 1 08:05 /etc/rancher/k3s/k3s.yaml
What you see: only root may read and write the file
(rw-------). That is how it should be: whoever has this
file is administrator of the whole cluster. Many guides suggest starting
k3s with --write-kubeconfig-mode 644 so that every user can
read it. You don’t do that – you create your own copy that belongs only
to you.
Step 6 – Create a folder for your own copy.
# on id1
mkdir -p ~/.kube-p only creates the folder if it doesn’t exist yet and
otherwise reports no error.
Step 7 – Copy the access file.
# on id1
sudo install -m 600 -o ubuntu -g ubuntu /etc/rancher/k3s/k3s.yaml ~/.kube/configinstall copies a file and sets permissions and owner at
the same time – in one step, without the copy being readable by others
even for a moment.
| Option | Value | Meaning |
|---|---|---|
-m |
600 |
permissions: only the owner may read and write |
-o |
ubuntu |
owner of the copy |
-g |
ubuntu |
group of the copy |
| Source | /etc/rancher/k3s/k3s.yaml |
the file from k3s |
| Target | ~/.kube/config |
the place where kubectl usually looks |
Check the result:
# on id1
ls -l ~/.kube/configExpected:
-rw------- 1 ubuntu ubuntu 2941 Dec 1 08:05 /home/ubuntu/.kube/config
Step 8 – Point kubectl at the file. The
kubectl from k3s first looks for its access file in
/etc/rancher/k3s/k3s.yaml – which you aren’t allowed to
read. The environment variable KUBECONFIG tells it which
file to use. So that it is set in every session, you add it to
~/.bashrc, which is read at every login:
# on id1
nano ~/.bashrcGo to the end of the file and add:
# Workload-Identity-Kurs
export KUBECONFIG=~/.kube/configSo that the change applies in the current session, you read the file in again:
# on id1
source ~/.bashrcStep 9 – Ask the cluster.
# on id1
kubectl get nodes -o wide-o wide shows extra columns such as IP address,
operating system and container runtime.
Expected (truncated on the right):
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE
id1 Ready control-plane 16s v1.37.2+k3s1 172.16.0.126 <none> Ubuntu 24.04.5 LTS
| Column | Value | Meaning |
|---|---|---|
STATUS |
Ready |
the node reports in and can start pods |
ROLES |
control-plane |
the API server runs on this node |
VERSION |
v1.37.2+k3s1 |
Kubernetes 1.37.2 in the first k3s build |
INTERNAL-IP |
172.16.0.126 |
address at which the other nodes reach it |
Remember: The administrator’s access file is the master key to the whole cluster. You copy it with
install -m 600to a place that belongs only to you – you never make it readable for everyone.
Save your progress? Sign up for free
Drill 4: Join id2 as the second node
Where you are: first on id1, then on id2.
What you have afterwards: a cluster with two nodes – and an idea of what a static join token looks like and where it ends up afterwards.
A new node has to prove to the server that it is allowed to belong. By default, k3s does this with a shared secret: the join token. Whoever knows it may join a node – and a joined node sees the secrets of all pods running on it. In the picture: the token is the builders’ master key. Today you use it; on Day 1 you ask yourself everywhere it has been left lying around.
Step 1 – Find the token.
# on id1
sudo ls -l /var/lib/rancher/k3s/server/node-tokenExpected:
lrwxrwxrwx 1 root root 33 Dec 1 08:05 /var/lib/rancher/k3s/server/node-token -> /var/lib/rancher/k3s/server/token
What you see: node-token is a link
(l at the very front) to the file token. Both
are in a folder that only root may read.
Step 2 – Show the token.
# on id1
sudo cat /var/lib/rancher/k3s/server/node-tokenExpected (shortened – the author doesn’t show his token):
K10318690…::server:…
What you see: the token starts with
K10, followed by a checksum of the server certificate, then
::server: and the actual secret. The front part has a
purpose: the new node can use it to check that it really is talking to
your server. Copy the whole line – you need it on id2 in a
moment.
Step 3 – Download the installation script on id2.
Log in to id2 (ssh id2):
# on id2
curl -fsSL https://get.k3s.io -o k3s-install.shStep 4 – Install k3s as an agent. Put the copied
line in place of <token>:
# on id2
K3S_URL=https://172.16.0.126:6443 K3S_TOKEN=<token> INSTALL_K3S_VERSION=v1.37.2+k3s1 sh k3s-install.sh| Option | Value | Meaning |
|---|---|---|
K3S_URL= |
https://172.16.0.126:6443 |
address of the server; if it is set, the script installs an agent instead of a server |
K3S_TOKEN= |
the token from step 2 | proof that this node is allowed to belong |
INSTALL_K3S_VERSION= |
v1.37.2+k3s1 |
the same version as the server |
sh k3s-install.sh |
the script, without further arguments |
Expected (excerpt – watch for the lines with
agent):
[INFO] Using v1.37.2+k3s1 as release
[INFO] Verifying binary download
[INFO] Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh
[INFO] env: Creating environment file /etc/systemd/system/k3s-agent.service.env
[INFO] systemd: Creating service file /etc/systemd/system/k3s-agent.service
[INFO] systemd: Enabling k3s-agent unit
[INFO] systemd: Starting k3s-agent
What you see: this time the service is called
k3s-agent. An agent has no API server of its own; it starts
pods and registers with the server on id1. Make a note of the line with
environment file – it is the solution to the challenge at
the end of the chapter.
Step 5 – Wait until id2 is ready. Back on id1:
# on id1
kubectl wait --for=condition=Ready node/id2 --timeout=120s--for=condition=Readywaits until the node reports theReadycondition.node/id2is the object being waited for.--timeout=120saborts with an error after two minutes instead of waiting forever.
Expected:
node/id2 condition met
Step 6 – Look at both nodes.
# on id1
kubectl get nodes -o wideExpected (truncated on the right):
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE
id1 Ready control-plane 96s v1.37.2+k3s1 172.16.0.126 <none> Ubuntu 24.04.5 LTS
id2 Ready <none> 28s v1.37.2+k3s1 172.16.0.228 <none> Ubuntu 24.04.5 LTS
What you see: id2 has no role
(<none>) – it is a pure worker node.
Step 7 – What is running in the cluster?
# on id1
kubectl get pods -A -o wide-A shows pods from all namespaces, not just from
default.
Expected (truncated on the right):
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
kube-system coredns-577d995dff-gnxw6 1/1 Running 0 96s 10.42.0.3 id1
kube-system helm-install-gateway-api-crd-qwmvc 0/1 Completed 0 97s 10.42.0.5 id1
kube-system local-path-provisioner-56c6584955-np49s 1/1 Running 0 96s 10.42.0.4 id1
kube-system metrics-server-778c4649b4-plxft 1/1 Running 0 96s 10.42.0.2 id1
What you see: the basic equipment of k3s: DNS in the
cluster (coredns), a simple storage service
(local-path-provisioner), metrics for
kubectl top (metrics-server) and a one-off job
that installed the Gateway API definitions (Completed).
Traefik is missing, as intended.
Remember: Here, joining a node depends on a shared, long-lived secret. Whoever has the token can join their own node at any time – a master key, not a badge.
Save your progress? Sign up for free
Drill 5: The first building badge
Where you are: on id1.
What you have afterwards: your cluster’s discovery document, a pod on id2 and its token, which you opened and read with
step.
Before you go looking for problems on Day 1, you look at what Kubernetes does on its own. Every pod gets a building badge. Who issues it, what is on it, and how long is it valid?
Step 1 – Read the notice at reception. Every Kubernetes cluster describes itself as an issuer of tokens at a fixed address, as the OpenID Connect standard provides:
# on id1
kubectl get --raw /.well-known/openid-configuration > oidc.jsonget --raw <pfad>sends a GET request to exactly this path of the API server and prints the response unchanged.> oidc.jsonredirects the response into a file so that you can display it readably in a moment.
Step 2 – Display the document readably.
# on id1
jq . oidc.jsonjq . prints the JSON unchanged but indented. The dot is
the simplest jq expression: “the whole document”.
Expected:
{
"issuer": "https://kubernetes.default.svc.cluster.local",
"jwks_uri": "https://172.16.0.126:6443/openid/v1/jwks",
"response_types_supported": [
"id_token"
],
"subject_types_supported": [
"public"
],
"id_token_signing_alg_values_supported": [
"RS256"
]
}
| Field | Value | Meaning |
|---|---|---|
issuer |
https://kubernetes.default.svc.cluster.local |
what the issuer calls itself; this value appears in every token in
the iss field |
jwks_uri |
https://172.16.0.126:6443/openid/v1/jwks |
this is where the public keys used to verify the signature hang |
id_token_signing_alg_values_supported |
RS256 |
tokens are signed with RSA and SHA-256 |
What you see: the issuer’s name is an address that exists only inside the cluster. A service outside – Keycloak, for example – couldn’t find anything there. That’s enough for now; on Day 3 you change the issuer so that outsiders can verify it too.
Step 3 – Start a pod on id2. You create a manifest
file. The pod is called besucher and is meant to run
explicitly on id2:
# on id1
mkdir -p ~/kurs/00# on id1
nano ~/kurs/00/besucher.yamlapiVersion: v1
kind: Pod
metadata:
name: besucher
spec:
nodeName: id2
containers:
- name: shell
image: busybox:1.37
command: ["sleep", "3600"]| Field | Value | Meaning |
|---|---|---|
kind |
Pod |
the smallest startable object in Kubernetes |
nodeName |
id2 |
fixes the node and bypasses the scheduler |
image |
busybox:1.37 |
tiny image with a shell and basic tools |
command |
sleep 3600 |
the container does nothing for an hour – you just want to look inside |
No ServiceAccount appears anywhere in the file. Keep that in mind for step 6.
# on id1
kubectl apply -f ~/kurs/00/besucher.yamlExpected:
pod/besucher created
# on id1
kubectl wait --for=condition=Ready pod/besucher --timeout=120sExpected:
pod/besucher condition met
# on id1
kubectl get pod besucher -o wideExpected (truncated on the right):
NAME READY STATUS RESTARTS AGE IP NODE
besucher 1/1 Running 0 8s 10.42.1.2 id2
What you see: the pod runs on id2 and has an address
from the 10.42.1.x range – every node gets its own
sub-range.
Step 4 – What did the pod get?
# on id1
kubectl exec besucher -- ls -l /var/run/secrets/kubernetes.io/serviceaccount/kubectl exec <pod> -- <befehl> runs a
command in the container. Everything after -- belongs to
the command in the container, not to kubectl.
Expected:
total 0
lrwxrwxrwx 1 root root 13 Dec 1 08:08 ca.crt -> ..data/ca.crt
lrwxrwxrwx 1 root root 16 Dec 1 08:08 namespace -> ..data/namespace
lrwxrwxrwx 1 root root 12 Dec 1 08:08 token -> ..data/token
| File | Meaning |
|---|---|
ca.crt |
certificate of the cluster CA, so that the pod can trust the API server |
namespace |
the pod’s namespace as text |
token |
the building badge: a signed JWT |
What you see: three files you never asked for. They
are links to a hidden folder ..data – this way Kubernetes
can swap the token without the pod noticing.
Step 5 – Take out the badge.
# on id1
kubectl exec besucher -- cat /var/run/secrets/kubernetes.io/serviceaccount/token > besucher.jwtThe token ends up in the file besucher.jwt on id1. It is
a long string made of three parts, separated by dots: header, payload,
signature.
Step 6 – Open the badge.
# on id1
step crypto jwt inspect --insecure < besucher.jwtstep crypto jwt inspecttakes a JWT apart and shows header and payload as JSON.--insecureis mandatory and meant honestly: the command shows the contents without verifying the signature. Anyone who has the token may read it – you may only trust it after verification. You do that on Day 3.< besucher.jwtfeeds the file as input.
Expected (signature shortened):
{
"header": {
"alg": "RS256",
"kid": "IgxVgJZWT78AbhR-GQDTcPv2lHU2X_x6hHv1u_4m7zM"
},
"payload": {
"aud": [
"https://kubernetes.default.svc.cluster.local",
"k3s"
],
"exp": 1827648481,
"iat": 1796112481,
"iss": "https://kubernetes.default.svc.cluster.local",
"jti": "a6f5ecaf-eee6-40ff-a843-b9971b0a0cd2",
"kubernetes.io": {
"namespace": "default",
"node": {
"name": "id2",
"uid": "52aba4e0-1660-4c14-a9a5-209b4671bd08"
},
"pod": {
"name": "besucher",
"uid": "4e160b0a-7f85-46d5-bf2b-fd5199ef586b"
},
"serviceaccount": {
"name": "default",
"uid": "07a01063-a3d3-4cee-b050-a72d2b9ddab4"
},
"warnafter": 1796116088
},
"nbf": 1796112481,
"sub": "system:serviceaccount:default:default"
},
"signature": "kLcEKLYqyXejyuKqv5DwsHSuuRzeoRme2R2IV7etMVh5T9oE…"
}
| Field | Value | Meaning | in the picture |
|---|---|---|---|
iss |
https://kubernetes.default.svc.cluster.local |
who issued the badge – the same value as in the discovery document | badge office |
sub |
system:serviceaccount:default:default |
whom it belongs to: ServiceAccount default in namespace
default |
name on the badge |
aud |
two entries | whom it is meant for – here the API server | which door it is valid for |
iat, nbf |
1796112481 |
issued at, valid from (seconds since 1 Jan 1970) | date of issue |
exp |
1827648481 |
valid until | expiry date |
kubernetes.io.pod |
besucher |
bound to exactly this pod | photo on the badge |
kubernetes.io.node |
id2 |
issued on this node | building |
warnafter |
1796116088 |
from here on the API server warns if the token is still used | “please renew” |
kid (in the header) |
IgxV… |
ID of the key used to sign | which seal |
What you see: the pod got a ServiceAccount even
though none was in the manifest – default. The badge names
the pod and the node, so it is bound to exactly this pod. You work out
how long it is valid in the next step.
Step 7 – Translate the timestamps. JWTs store times
as seconds since 1 January 1970. date translates them:
# on id1
date -u -d @1796112481-uprints the time in UTC, as it is meant in the token.-d @<zahl>takes the number as seconds since 1970.
Expected:
Tue Dec 1 08:08:01 UTC 2026
# on id1
date -u -d @1796116088Expected:
Tue Dec 1 09:08:08 UTC 2026
# on id1
date -u -d @1827648481Expected:
Wed Dec 1 08:08:01 UTC 2027
What you see: issued at 08:08,
warnafter an hour later – but valid until 1
December 2027, a whole year. That is not a fault of your lab.
By default, Kubernetes issues tokens with a lifetime of one hour to
pods, but out of consideration for old programs that never re-read their
token, it extends them to one year and records the real limit in
warnafter. Exactly how that works and how you switch it off
is the material for Day 2.
Step 8 – Without a badge you don’t get in. The pod asks the API server for its version, this time without sending the token:
# on id1
kubectl exec besucher -- wget -qO- --no-check-certificate https://kubernetes.default.svc/version| Option | Meaning |
|---|---|
wget -q |
without status messages |
-O- |
response to standard output instead of a file |
--no-check-certificate |
don’t verify the server’s certificate – only for this test, because busybox doesn’t know the cluster CA |
https://kubernetes.default.svc/version |
the API server, as every pod in the cluster reaches it |
Expected:
wget: server returned error: HTTP/1.1 401 Unauthorized
command terminated with exit code 1
What you see: 401 Unauthorized means:
“I don’t know who you are.” k3s doesn’t allow anonymous requests, not
even for the version number. So the badge in the pod isn’t decoration –
without it, no door opens. With it, on the other hand, possibly more
opens than you’d like. You check that on Day 1.
Step 9 – Clean up.
# on id1
kubectl delete pod besucherExpected:
pod "besucher" deleted from default namespace
The file besucher.jwt stays where it is. It is a real
badge, still valid for a year – on Day 2 you check whether it is still
good for anything after the pod has been deleted.
Remember: Every pod gets a building badge without asking: issued by the cluster, made out to a ServiceAccount and a pod, meant for the API server – and, by default, valid for one year.
Save your progress? Sign up for free
Diagnosis task
A colleague installed k3s exactly like you, but stopped Drill 3 after
step 4. They run kubectl get nodes and get:
time="2026-12-01T08:05:55Z" level=warning msg="Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode or --write-kubeconfig-group to modify kube config permissions"
error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied
They want to follow the advice in the message and restart k3s with
--write-kubeconfig-mode 644. What is the cause, and why is
their plan not a good idea?
Solution path:
The message names the file:
kubectllooks for/etc/rancher/k3s/k3s.yaml. Check its permissions:# on id1 sudo ls -l /etc/rancher/k3s/k3s.yamlResult as in Drill 3, step 5:
-rw------- 1 root root. Only root may read it.The colleague works as
ubuntu, not as root. Cause: the personal copy is missing, andKUBECONFIGis not set.With mode
644, every user and every process on id1 could read the file – and so become administrator of the cluster. The message solves the convenience problem by creating a security problem.The right way is Drill 3, steps 6 to 8: a copy with
install -m 600for your own user andKUBECONFIGin~/.bashrc.
Challenge
You entered the join token from Drill 4 on the command line of id2. Find out whether and where it is stored permanently on id2 afterwards – and who can read it there. Write down the command before you read the solution.
Solution: the installation script gave it away in
Drill 4, step 4 (environment file):
# on id2
sudo cat /etc/systemd/system/k3s-agent.service.envExpected (token shortened):
K3S_TOKEN='K10318690…(gekürzt)
K3S_URL='https://172.16.0.126:6443'
The token sits in plain text in a file under
/etc/systemd/system/ so that the agent can register again
after every restart. It is also in your user’s shell history on id2,
because you typed it on the command line. On Day 1 you search for
exactly such places systematically.
Save your progress? Sign up for free
Checkpoint
Check at the end of the chapter:
# on id1
kubectl get nodesExpected (age differs):
NAME STATUS ROLES AGE VERSION
id1 Ready control-plane … v1.37.2+k3s1
id2 Ready <none> … v1.37.2+k3s1
# on id1
kubectl versionExpected:
Client Version: v1.37.2+k3s1
Kustomize Version: v5.8.1
Server Version: v1.37.2+k3s1
# on id1
step versionExpected:
Smallstep CLI/0.31.0 (linux/amd64) in the first line.
# on id1
ls -l ~/.kube/configExpected: permissions -rw-------, owner
ubuntu.
If everything matches, the building is ready.
Test yourself
- Why don’t you install
stepstraight from the network, but checkchecksums.txtfirst? What does that protect against, and what not? - What distinguishes the k3s join token from an SSH key when you think about the question of where the secret lives?
- How can you tell from a pod’s token on which node and for which pod it was issued?
- Why does the
expfield contain a date one year away, even though Kubernetes supposedly issues tokens with a lifetime of one hour? - The command
step crypto jwt inspectneeds--insecure. What exactly is insecure about it? - Why is
--write-kubeconfig-mode 644a bad solution for “kubectl is not allowed to read the file”?
Answers:
- The checksum shows that the file on your disk is exactly the one the vendor published in its release – it protects against transfer errors and an altered storage server. It doesn’t help against an attacker who swaps the package and the checksum list together; for that you need a signature.
- With the SSH key, the secret stays on your machine and the VM only knows the public part. The join token is a shared secret: it lives on the server, in a file on every agent and in every shell history where it was typed.
- In the payload under
kubernetes.io:node.namenames the node (id2),pod.nameandpod.uidthe pod (besucher). - Internally, Kubernetes issues one hour, but extends the token to one
year for old programs and records the real limit in
warnafter. From then on, the API server warns if it is still used. - The command shows the contents without verifying the signature. Anyone can build a JWT with arbitrary contents – you may only trust it once the signature has been verified with the issuer’s public key.
- Then every user and every process on id1 may read the file and is
therefore administrator of the cluster. The right way is a personal copy
with mode 600 and
KUBECONFIG.
Interview note
“What identity does a pod get in Kubernetes out of the box?” – Good
answer: a ServiceAccount (default if none is specified) and
a projected, signed token at
/var/run/secrets/kubernetes.io/serviceaccount/token. The
token is bound to pod and node and meant for the API server. If they dig
deeper: the lifetime is one hour by default, but is stretched to one
year for compatibility reasons; with
automountServiceAccountToken: false a pod gets none at
all.
Enterprise note
In production you don’t join k3s or RKE2 nodes with a token from the
command line. Common choices are bootstrap tokens with a short lifetime
(24 hours with kubeadm), node certificates from your own PKI, or a
provisioning tool that fetches the token from a vault and discards it
afterwards. Where the token does end up on disk, access to
/etc/systemd/system/ and /var/lib/rancher/
belongs in hardening and monitoring. The admin kubeconfig never leaves
the server; humans log in through an identity provider (Day 9).
Summary
- You have your own SSH key and short names for id1 and id2 – an identity whose secret never leaves your machine.
stepis installed after you verified the checksum against the vendor’s list.- k3s runs as a server on id1 and as an agent on id2. You copied the admin access file for yourself with mode 600.
- Joining id2 depended on a static token that now lies in plain text on id2.
- The cluster introduces itself as an issuer at
/.well-known/openid-configuration. - Every pod gets a token without asking: issued by the cluster, for a ServiceAccount, bound to pod and node, meant for the API server and valid for one year.
Commands at a glance
| Command | What for |
|---|---|
ssh-keygen -t ed25519 -f ~/.ssh/id -C id-labor |
create a key pair for the lab |
ssh-copy-id -i ~/.ssh/id.pub ubuntu@<ip> |
put the public key on the VM |
sudo hostnamectl set-hostname <name> |
set the hostname permanently |
getent hosts <name> |
check name resolution |
dpkg --print-architecture |
processor architecture for packages |
sha256sum --check --ignore-missing checksums.txt |
verify a download against the checksum list |
sudo apt-get install -y ./<paket>.deb |
install a local package |
INSTALL_K3S_VERSION=… sh k3s-install.sh --disable traefik |
install the k3s server |
K3S_URL=… K3S_TOKEN=… sh k3s-install.sh |
install the k3s agent |
sudo install -m 600 -o <user> -g <user> <quelle> <ziel> |
copy a file with permissions |
kubectl wait --for=condition=Ready node/<name> --timeout=120s |
wait for a condition |
kubectl get --raw /.well-known/openid-configuration |
the cluster’s discovery document |
kubectl exec <pod> -- <befehl> |
run a command in the container |
step crypto jwt inspect --insecure < <datei> |
read a JWT without verifying |
date -u -d @<sekunden> |
translate a timestamp from a token |