Day 0: The Training Ground
Goal: Set up Colima and the Kubernetes tools, build the kind cluster
labwith three nodes, load the app’s images into it and take one look at the cluster from the inside. · Duration: approx. 45 min · Prerequisite: none
Briefing
- kind (“Kubernetes in Docker”) starts every node as a Docker container. A cluster is built in a few minutes and gone again with one command.
- The lab cluster
labhas one control plane node (API server, etcd, scheduler, controllers) and two workers on which your Pods run. kubectlonly talks to the API server. Which cluster is meant is stored in the context in~/.kube/config, herekind-lab.- You build the app’s images locally and load them into the nodes with
kind load. You don’t need a registry in Part 1.
Mac Colima VM (Linux, arm64)
┌────────────────────────┐ ┌────────────────────────────────────────────┐
│ ~/k8s-lab/ │ │ Docker │
│ setup/ code/ notes/ │ │ ┌──────────────────┐ ┌────────┐ ┌────────┐│
│ tagNN/ │ :6443 │ │lab-control-plane │ │lab- │ │lab- ││
│ kubectl ───────────────┼──────►│ │ API server, etcd │ │worker │ │worker2 ││
│ kind, helm, docker │ │ │ scheduler, … │ │ Pods │ │ Pods ││
│ curl localhost:30080 ──┼──────►│ └──────────────────┘ └────────┘ └────────┘│
└────────────────────────┘ └────────────────────────────────────────────┘
Drill 1: Start Colima
Kubernetes needs more room than a Compose stack. Start Colima with 4
CPUs, 8 GB RAM and a 60 GB disk (if Colima is already running with less:
run colima stop first; the new values apply on the next
start):
colima start --cpu 4 --memory 8 --disk 60
colima status
docker info --format 'Arch {{.Architecture}} · CPUs {{.NCPU}}'Expected (abridged, values will differ on your machine):
INFO[0000] colima is running using macOS Virtualization.Framework
INFO[0000] arch: aarch64
INFO[0000] runtime: docker
Arch aarch64 · CPUs 4
Save your progress? Sign up for free
Drill 2: Tools
brew install kind kubectl helm jq
kind version
kubectl version --client
helm version --short
jq --versionExpected (abridged, may differ depending on the version):
kind v0.33.0 go1.26.7 darwin/arm64
Client Version: v1.37.2
Kustomize Version: v5.8.1
v4.3.1+gc0d08d0
jq-1.8.2
The book was tested with kind v0.33.0 (node image
kindest/node:v1.37.0), kubectl v1.37.2 and Helm v4.3.1.
kubectl may be one minor version newer or older than the cluster; a
larger gap is reported by kubectl version as a warning.
Save your progress? Sign up for free
Drill 3: Working Directory and Companion Code
You fetch the companion code once from GitHub into
~/k8s-lab/code. The setup files and the demo application
get their own copies:
mkdir -p ~/k8s-lab && cd ~/k8s-lab
git clone https://github.com/thomaszachmann/kubernetes-zum-anfassen.git ~/k8s-lab/code
cp -R ~/k8s-lab/code/setup ~/k8s-lab/setup
cp -R ~/k8s-lab/code/notes ~/k8s-lab/notes
ls ~/k8s-lab ~/k8s-lab/setup
grep -v '^#' ~/k8s-lab/setup/env.shExpected:
Cloning into '/Users/du/k8s-lab/code'...
/Users/du/k8s-lab:
code notes setup
/Users/du/k8s-lab/setup:
env.sh kind.yaml
export LAB="${LAB:-$HOME/k8s-lab}"
export NOTES="$LAB/notes"
export CLUSTER="${CLUSTER:-lab}" # kind-Cluster, Kontext kind-$CLUSTER
export NODEPORT_HOST="${NODEPORT_HOST:-30080}" # Port auf dem Mac für NodePort/Gateway
export NS=notes
env.sh only sets variables. From now on, every day
starts with the same line:
source ~/k8s-lab/setup/env.shSave your progress? Sign up for free
Drill 4: Build the Cluster
cat ~/k8s-lab/setup/kind.yamlExpected:
# kind.yaml – Cluster des Trainingslagers: 1 Control-Plane, 2 Worker
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.37.0
extraPortMappings:
- containerPort: 30080
hostPort: 30080
listenAddress: "127.0.0.1"
- role: worker
image: kindest/node:v1.37.0
- role: worker
image: kindest/node:v1.37.0
extraPortMappings publishes port 30080 of the control
plane container on 127.0.0.1:30080. That is where the web
frontend arrives from Day 3 on. --wait waits until the
control plane node is ready:
kind create cluster --name lab --config ~/k8s-lab/setup/kind.yaml --wait 120s
kubectl get nodesExpected (abridged, takes a few minutes):
Creating cluster "lab" ...
✓ Ensuring node image (kindest/node:v1.37.0)
✓ Preparing nodes
✓ Writing configuration
✓ Starting control-plane
✓ Installing CNI
✓ Installing StorageClass
✓ Joining worker nodes
✓ Waiting ≤ 2m0s for control-plane = Ready
Set kubectl context to "kind-lab"
…
NAME STATUS ROLES AGE VERSION
lab-control-plane Ready control-plane 31s v1.37.0
lab-worker NotReady <none> 16s v1.37.0
lab-worker2 NotReady <none> 17s v1.37.0
kind only waits for the control plane node. If a worker is still
NotReady shortly afterwards, give it a few seconds and
check again with kubectl get nodes.
Warning: If a worker stays away permanently and
docker exec lab-worker journalctl -u kubelet | tailshows the messagetoo many open files, the VM’s inotify limits are too low. The fix according to the kind docs:colima ssh -- sudo sysctl -w fs.inotify.max_user_instances=512(applies until the next restart of the VM).
Save your progress? Sign up for free
Drill 5: Cluster and Context
kubectl config get-contexts
kubectl cluster-info
kubectl get nodesExpected (abridged, ports, IPs and times will differ on your machine):
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* kind-lab kind-lab kind-lab
Kubernetes control plane is running at https://127.0.0.1:44025
CoreDNS is running at https://127.0.0.1:44025/api/v1/namespaces/kube-system/…
NAME STATUS ROLES AGE VERSION
lab-control-plane Ready control-plane 2m3s v1.37.0
lab-worker Ready <none> 103s v1.37.0
lab-worker2 Ready <none> 103s v1.37.0
kind created and activated the context kind-lab. If you
have several clusters, you choose with
kubectl config use-context kind-lab – or every command gets
--context kind-lab.
kubectl get nodes -o wide
kubectl get nodes \
-o custom-columns='NAME:.metadata.name,ARCH:.status.nodeInfo.architecture'Expected (abridged, columns thinned out):
NAME STATUS … VERSION INTERNAL-IP … OS-IMAGE …
lab-control-plane Ready … v1.37.0 172.18.0.5 … Debian GNU/Linux 13 (trixie) …
lab-worker Ready … v1.37.0 172.18.0.7 … Debian GNU/Linux 13 (trixie) …
lab-worker2 Ready … v1.37.0 172.18.0.6 … Debian GNU/Linux 13 (trixie) …
NAME ARCH
lab-control-plane arm64
lab-worker arm64
lab-worker2 arm64
Every node is a Debian container with its own containerd (column
CONTAINER-RUNTIME, here containerd://2.3.4).
The INTERNAL-IP comes from the Docker network
kind. custom-columns fetches arbitrary fields
from the object; the quotes protect [*] and the like from
zsh.
Save your progress? Sign up for free
Drill 6: Nodes Are Containers
docker ps --filter label=io.x-k8s.kind.cluster=lab \
--format 'table {{.Names}}\t{{.Image}}\t{{.Ports}}'Expected (abridged, ports differ):
NAMES IMAGE PORTS
lab-worker kindest/node:v1.37.0
lab-control-plane kindest/node:v1.37.0 127.0.0.1:44025->6443/tcp, 127.0.0.1:30080…
lab-worker2 kindest/node:v1.37.0
Port 6443 is the API server that kubectl reaches through
the kubeconfig. Colima forwards both ports of the VM to
localhost on the Mac.
What runs on which node?
kubectl -n kube-system get pods \
-o custom-columns='NAME:.metadata.name,NODE:.spec.nodeName'
kubectl get nodes -o custom-columns='NAME:.metadata.name,TAINTS:.spec.taints[*].key'Expected (abridged):
NAME NODE
coredns-559f6c778d-jqljk lab-control-plane
coredns-559f6c778d-m27p9 lab-control-plane
etcd-lab-control-plane lab-control-plane
kindnet-55z8n lab-worker2
kindnet-l9b28 lab-control-plane
kindnet-sfjrf lab-worker
kube-apiserver-lab-control-plane lab-control-plane
kube-controller-manager-lab-control-plane lab-control-plane
kube-proxy-r7txb lab-worker
kube-proxy-x5vxq lab-control-plane
kube-proxy-z298x lab-worker2
kube-scheduler-lab-control-plane lab-control-plane
NAME TAINTS
lab-control-plane node-role.kubernetes.io/control-plane
lab-worker <none>
lab-worker2 <none>
| Component | Runs on | Job |
|---|---|---|
| kube-apiserver, etcd | control plane | API and database of the cluster |
| kube-scheduler | control plane | picks a node for every new Pod |
| kube-controller-manager | control plane | reconciles desired and actual state (Day 2) |
| kube-proxy, kindnet | every node | Service rules (Day 3) and Pod network |
The taint on the control plane node keeps your Pods away; they land on the workers. The control plane components themselves are Pods that the kubelet starts directly:
docker exec lab-control-plane crictl ps --name 'kube-apiserver|etcd'Expected (abridged, IDs differ):
CONTAINER IMAGE CREATED STATE NAME …
663d30a4b0d69 bec5f0e1e2eeb 2 minutes ago Running kube-apiserver …
f7fb24e5203c7 270fbeb697171 2 minutes ago Running etcd …
Save your progress? Sign up for free
Drill 7: Load Images into the Cluster
The nodes have their own containerd storage and don’t see the images
in your Docker. So you build the app’s three images and copy them into
every node with kind load:
cd ~/k8s-lab/notes
for app in api worker web; do
docker build -q --build-arg VERSION=0.1.0 -t "notes-$app:0.1.0" "notes-$app"
kind load docker-image "notes-$app:0.1.0" --name lab
done
docker exec lab-worker crictl images | grep -E 'IMAGE|notes'Expected (abridged, IDs differ):
sha256:9fe8638a26c7…
Image: "notes-api:0.1.0" with ID "sha256:9fe8638a26c7…" not yet present on node
"lab-control-plane", loading...
…
sha256:f5bbc3206d5b…
…
IMAGE TAG IMAGE ID SIZE
docker.io/library/notes-api 0.1.0 c5e677d5139c6 4.5MB
docker.io/library/notes-web 0.1.0 dd87288dc99da 64.2MB
docker.io/library/notes-worker 0.1.0 2d70b014e28b1 45.5MB
--build-arg VERSION ends up in the app’s
GET /version. kind copies into all three nodes. In the test
it reported not yet present on every call and loaded again
– harmless, it only costs time. What matters is the fixed tag
0.1.0: with latest, Kubernetes would always
want to pull from the internet (Day 1).
Save your progress? Sign up for free
Checkpoint
kubectl config current-contextExpected: the context of the kind cluster.
kind-lab
kubectl get nodesExpected: one control plane node and two workers, all
Ready.
NAME STATUS ROLES AGE VERSION
lab-control-plane Ready control-plane 110s v1.37.0
lab-worker Ready <none> 98s v1.37.0
lab-worker2 Ready <none> 98s v1.37.0
kubectl get pods -n kube-systemExpected: all system Pods Running and
1/1.
NAME READY STATUS RESTARTS AGE
coredns-559f6c778d-7jm7k 1/1 Running 0 101s
coredns-559f6c778d-j7t9l 1/1 Running 0 101s
etcd-lab-control-plane 1/1 Running 0 107s
kindnet-9r68x 1/1 Running 0 101s
…
kube-scheduler-lab-control-plane 1/1 Running 0 110s
docker exec lab-worker crictl images | grep notesExpected: the app’s three images in version 0.1.0 in the node (the
same in lab-worker2 and
lab-control-plane).
docker.io/library/notes-api 0.1.0 a4c97999bb14c …
docker.io/library/notes-web 0.1.0 c7d26a572b58f …
docker.io/library/notes-worker 0.1.0 6552249803404 …
ls ~/k8s-lab/codeExpected: the companion code with notes,
setup and one folder per day.
anhb
notes
setup
tag01
tag02
…
Challenge
Throw the cluster away and build it again. Measure how long it takes, and then check that all three nodes have the images again.
Hint: kind delete cluster only deletes
the node containers; the images stay in your Docker and only need to be
distributed again.
Solution
kind delete cluster --name lab
SECONDS=0
kind create cluster --name lab --config ~/k8s-lab/setup/kind.yaml --wait 120s
for app in api worker web; do
kind load docker-image "notes-$app:0.1.0" --name lab
done
echo "Dauer: ${SECONDS}s"
kubectl get nodes
docker exec lab-worker2 crictl images | grep -c notesExpected (abridged, times differ):
Deleting cluster "lab" ...
Deleted nodes: ["lab-control-plane" "lab-worker" "lab-worker2"]
Creating cluster "lab" ...
…
Image: "notes-api:0.1.0" with ID "sha256:9fe8638a26c7…" not yet present on node
"lab-worker2", loading...
…
Dauer: 121s
NAME STATUS ROLES AGE VERSION
lab-control-plane Ready control-plane 92s v1.37.0
lab-worker Ready <none> 78s v1.37.0
lab-worker2 Ready <none> 78s v1.37.0
3
kind load alone is also the way to go when you have
rebuilt an app version. A fresh cluster is empty: everything you create
from Day 1 on is stored in files under ~/k8s-lab/tagNN and
quickly back with kubectl apply. The images stay in the
VM’s Docker and are only distributed again.
Save your progress? Sign up for free
Enterprise Note
- kind is meant for labs and CI. Production clusters run on VMs or bare metal (RKE2 in Part 2) or as a managed service (EKS, AKS, GKE).
- There, images come from a registry with a pull secret, fixed tags or digests and signature verification (“Secure supply chains hands-on”).
- Several clusters means several contexts: a
kubectl deletein the wrong context is a classic. The context belongs in the shell prompt or in tools likek9s. - kind’s kubeconfig contains an admin certificate. For real clusters, every person gets their own credentials via OIDC and RBAC, never the admin file.