Day 0: The training ground
Goal: A cluster of three control plane nodes on Kubernetes v1.35, a virtual API address and a test application with a load generator · Duration: approx. 90 min · Prerequisite: three fresh VMs with Ubuntu 24.04
Briefing
- All three nodes are control plane nodes with their own etcd and run workloads. This way you can really practice drain, upgrade and node replacement without downtime.
- You reach the API via a virtual address that kube-vip sets on whichever node is currently the leader. If a node fails, the address moves.
- v1.35 on purpose: from Day 6 on, you upgrade the cluster twice, to v1.36 and v1.37.
- From today on, a load generator queries the test application every 0.2 seconds. On every upgrade day it measures whether requests get lost.
API: 172.16.0.100:6443 (kube-vip, ARP)
────┬──────────────────┬──────────────────┬──────── 172.16.0.0/24
cp1 .126 cp2 .228 cp3 .83
4 vCPU, 11 GiB 2 vCPU, 4 GiB 2 vCPU, 4 GiB
Control Plane Control Plane Control Plane
etcd + Workloads etcd + Workloads etcd + Workloads
= workstation
The IP addresses are those of the lab in this course. Use your own everywhere, and pick a free IP in your network for the virtual address.
Drill 1: Prepare the nodes
On all three nodes: kernel modules, IP forwarding and containerd with systemd cgroups.
# on cp1, cp2 and cp3
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/k8s.conf
sudo sysctl --system
sudo apt-get update
sudo apt-get install -y containerd apt-transport-https ca-certificates curl gpg
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml >/dev/null
sudo sed -i "s/SystemdCgroup = false/SystemdCgroup = true/" /etc/containerd/config.toml
sudo systemctl restart containerd# on cp1, cp2 and cp3
containerd --version
grep -c "SystemdCgroup = true" /etc/containerd/config.toml
sysctl net.ipv4.ip_forwardExpected:
containerd github.com/containerd/containerd/v2 2.2.1
1
net.ipv4.ip_forward = 1
Why systemd cgroups? Since v1.22, the kubelet manages cgroups via systemd by default. If the kubelet and containerd use different drivers, Pods run at first and are later terminated unpredictably under memory pressure.
Save your progress? Sign up for free
Drill 2: kubeadm, kubelet and kubectl v1.35
The packages come from the pkgs.k8s.io repository. There
is one repository per minor version, which matters for
the upgrades from Day 6 on.
# on cp1, cp2 and cp3
sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.35/deb/Release.key \
| sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] \
https://pkgs.k8s.io/core:/stable:/v1.35/deb/ /" \
| sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet=1.35.10-1.1 kubeadm=1.35.10-1.1 kubectl=1.35.10-1.1 \
cri-tools
sudo apt-mark hold kubelet kubeadm kubectl
sudo crictl config --set runtime-endpoint=unix:///run/containerd/containerd.sock \
--set image-endpoint=unix:///run/containerd/containerd.sock
kubeadm version -o shortExpected:
kubelet set on hold.
kubeadm set on hold.
kubectl set on hold.
v1.35.10
apt-mark hold prevents an apt upgrade from
upgrading the Kubernetes packages on the side. In this course, an upgrade
only happens on purpose and node by node.
Save your progress? Sign up for free
Drill 3: kube-vip as a static Pod
kube-vip runs as a static Pod next to the API server and sets the
virtual address via ARP on the node that wins the leader election. First
on cp1:
export VIP=172.16.0.100 INTERFACE=eth0 KVVERSION=v1.3.2
sudo ctr image pull ghcr.io/kube-vip/kube-vip:$KVVERSION
sudo mkdir -p /etc/kubernetes/manifests
sudo ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:$KVVERSION vip \
/kube-vip manifest pod --interface $INTERFACE --address $VIP \
--controlplane --arp --leaderElection \
| sudo tee /etc/kubernetes/manifests/kube-vip.yaml >/dev/null
sudo sed -i "s#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#" \
/etc/kubernetes/manifests/kube-vip.yaml
grep -n "image:\|super-admin" /etc/kubernetes/manifests/kube-vip.yamlExpected:
45: image: ghcr.io/kube-vip/kube-vip:v1.3.2
66: path: /etc/kubernetes/super-admin.conf
Why super-admin.conf? Since kubeadm v1.29,
admin.conf gets its permissions via an RBAC binding that is
only created after the API server has started.
kube-vip, however, needs access before that, otherwise there is no
virtual address and kubeadm init waits in vain. After the
init, you switch back to admin.conf (Drill 4).
Save your progress? Sign up for free
Drill 4: kubeadm init via the virtual address
sudo kubeadm init --control-plane-endpoint 172.16.0.100:6443 --upload-certs \
--pod-network-cidr 10.244.0.0/16 --kubernetes-version v1.35.10Expected (abridged, token and key replaced with
…):
You can now join any number of control-plane nodes running the following command on
each as root:
kubeadm join 172.16.0.100:6443 --token qiu594.… \
--discovery-token-ca-cert-hash sha256:1790… \
--control-plane --certificate-key 3daf…
Copy the whole join line with
--control-plane and --certificate-key into a
note; you need it in Drill 5. Then set up the kubeconfig and switch
kube-vip back:
mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
sudo sed -i "s#path: /etc/kubernetes/super-admin.conf#path: /etc/kubernetes/admin.conf#" \
/etc/kubernetes/manifests/kube-vip.yamlThe kubelet then restarts kube-vip, and the virtual address is gone
for a few seconds. A kubectl during this time reports:
Unable to connect to the server: dial tcp 172.16.0.100:6443: connect: no route to host
Wait briefly, then:
ip -br -4 addr show eth0
kubectl get nodesExpected:
eth0 UP 172.16.0.126/24 metric 100 172.16.0.100/32
NAME STATUS ROLES AGE VERSION
cp1 NotReady control-plane 50s v1.35.10
NotReady is correct: the Pod network is still missing
(Drill 6).
Warning: The
--certificate-keydecrypts the control plane certificates that kubeadm stores in the cluster. It is valid for two hours. Do not share it and do not store it permanently.
Save your progress? Sign up for free
Drill 5: cp2 and cp3 as control plane
# on cp2 and cp3, the line from your note
sudo kubeadm join 172.16.0.100:6443 --token qiu594.… \
--discovery-token-ca-cert-hash sha256:1790… \
--control-plane --certificate-key 3daf…Expected (abridged):
* Control plane label and taint were applied to the new node.
* The Kubernetes control plane instances scaled up.
* A new etcd member was added to the local/stacked etcd cluster.
Only after the join do cp2 and cp3 get their
kube-vip, this time directly with admin.conf. A manifest
placed earlier would disturb the preflight check of
kubeadm join, which expects an empty manifest
directory.
# on cp2 and cp3
export VIP=172.16.0.100 INTERFACE=eth0 KVVERSION=v1.3.2
sudo ctr image pull ghcr.io/kube-vip/kube-vip:$KVVERSION
sudo ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:$KVVERSION vip \
/kube-vip manifest pod --interface $INTERFACE --address $VIP \
--controlplane --arp --leaderElection \
| sudo tee /etc/kubernetes/manifests/kube-vip.yaml >/dev/null
mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/configBack on cp1: all three nodes should run workloads.
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
kubectl -n kube-system get pods -o wide | grep kube-vip | cut -c1-80Expected:
node/cp1 untainted
node/cp2 untainted
node/cp3 untainted
kube-vip-cp1 1/1 Running 0 4m4s 172.16.0.126 cp1
kube-vip-cp2 1/1 Running 0 23s 172.16.0.228 cp2
kube-vip-cp3 1/1 Running 0 22s 172.16.0.83 cp3
For the node days, you need SSH from cp1 to cp2 and
cp3:
ssh-keygen -t ed25519 -N "" -f ~/.ssh/id_ed25519
ssh-copy-id [email protected]
ssh-copy-id [email protected]Save your progress? Sign up for free
Drill 6: Helm and Cilium v1.19
Cilium is deliberately installed one minor version below the latest. On Day 8 you upgrade it as an add-on.
ARCH=$(dpkg --print-architecture)
curl -fsSLo /tmp/helm.tgz https://get.helm.sh/helm-v4.3.2-linux-$ARCH.tar.gz
tar -xzf /tmp/helm.tgz -C /tmp
sudo install /tmp/linux-$ARCH/helm /usr/local/bin/helm
helm repo add cilium https://helm.cilium.io
helm install cilium cilium/cilium --version 1.19.11 -n kube-system \
--set ipam.mode=kubernetes --set operator.replicas=2
kubectl -n kube-system rollout status ds/cilium --timeout=300s
kubectl get nodesExpected:
daemon set "cilium" successfully rolled out
NAME STATUS ROLES AGE VERSION
cp1 Ready control-plane 7m5s v1.35.10
cp2 Ready control-plane 4m49s v1.35.10
cp3 Ready control-plane 3m44s v1.35.10
Add metrics-server v0.8.1, also deliberately not the latest version:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/\
download/v0.8.1/components.yaml
kubectl -n kube-system patch deploy metrics-server --type=json -p \
'[{"op":"add","path":"/spec/template/spec/containers/0/args/-",
"value":"--kubelet-insecure-tls"}]'
kubectl -n kube-system rollout status deploy/metrics-server--kubelet-insecure-tls is a shortcut for the lab: the
kubelets still have self-signed certificates. On Day 10 you replace them
with signed ones and remove the shortcut again.
Save your progress? Sign up for free
Drill 7: Test application and load generator
mkdir -p ~/day2/tag00 && cd ~/day2/tag00
kubectl create namespace demo
cat > web.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: web, namespace: demo}
spec:
replicas: 3
selector: {matchLabels: {app: web}}
template:
metadata: {labels: {app: web}}
spec:
containers:
- name: whoami
image: traefik/whoami:v1.11
ports: [{containerPort: 80}]
---
apiVersion: v1
kind: Service
metadata: {name: web, namespace: demo}
spec:
selector: {app: web}
ports: [{port: 80}]
EOF
kubectl apply -f web.yaml
kubectl -n demo rollout status deploy/webThe load generator is a single Pod with curl. For each
request it writes the time and the HTTP status to its log. The status
000 means: no response, for example “Connection refused” or
a timeout.
cat > last.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
name: last
namespace: demo
labels: {app: last}
spec:
nodeName: cp1
containers:
- name: curl
image: curlimages/curl:8.17.0
env: [{name: ZIEL, value: http://web.demo}]
command: [sh, -c]
args:
- while true; do
echo "$(date +%T) $(curl -s -o /dev/null -w %{http_code} -m 2 $ZIEL)";
sleep 0.2;
done
EOF
kubectl apply -f last.yaml
kubectl -n demo wait --for=condition=Ready pod/last
kubectl -n demo logs last --tail=3
kubectl -n demo logs last | awk '$2 != 200' | wc -lExpected:
19:12:21 200
19:12:21 200
19:12:21 200
0
nodeName: cp1 pins the load generator to
cp1, so that its log survives every drain of cp2 and cp3.
The target is in ZIEL (German for “target”): for a
measurement run against another application, you delete
last and create it again with a changed
ZIEL.
You will need these last two commands often: the most recent
responses and the number of errors since the Pod started. A new
measurement run begins when you delete last and create it
again.
Save your progress? Sign up for free
Exercise: Speed Drills
- Show which node currently holds the virtual address. Target time: 1 min
- List the three etcd members as a table. Target time: 2 min
- Show the running containers of the API server, etcd and kube-vip on
cp1directly in containerd, without kubectl. Target time: 1 min
Solution
kubectl -n kube-system get lease plndr-cp-lock \
-o jsonpath='{.spec.holderIdentity}{"\n"}'cp1
kubectl -n kube-system exec etcd-cp1 -- etcdctl --endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key member list -w table+------------------+---------+------+---------------------------+---------------------
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS
+------------------+---------+------+---------------------------+---------------------
| 9dcda2f4c521f35 | started | cp2 | https://172.16.0.228:2380 | https://172.16.0.228
| 1ff2278c0fd14cc3 | started | cp1 | https://172.16.0.126:2380 | https://172.16.0.126
| f5adde1a510f30f1 | started | cp3 | https://172.16.0.83:2380 | https://172.16.0.83
+------------------+---------+------+---------------------------+---------------------
sudo crictl ps --name "kube-vip|etcd|kube-apiserver"CONTAINER IMAGE CREATED STATE NAME
b61b69db9b02e 5ba1a7f1d0427 32 minutes ago Running kube-vip
ffa65bc0c171c 2b6a34f9e844b 33 minutes ago Running kube-apiserver
69afe0298d2db 0a108f7189562 33 minutes ago Running etcd
Save your progress? Sign up for free
Checkpoint
kubectl get nodes -o custom-columns=NAME:.metadata.name,\
VERSION:.status.nodeInfo.kubeletVersion,RUNTIME:.status.nodeInfo.containerRuntimeVersionExpected:
NAME VERSION RUNTIME
cp1 v1.35.10 containerd://2.2.1
cp2 v1.35.10 containerd://2.2.1
cp3 v1.35.10 containerd://2.2.1
kubectl versionExpected:
Client Version: v1.35.10
Kustomize Version: v5.7.1
Server Version: v1.35.10
helm list -A -o table | cut -c1-10,70-Expected: one line cilium with
cilium-1.19.11.
kubectl -n demo get pods
kubectl -n demo logs last | awk '$2 != 200' | wc -lExpected: three web-… and
last in status Running, plus 0
errors.
Challenge
Prove that the virtual address really moves: restart the node that
currently holds it, and measure how long kubectl get nodes
gets no response.
Hint: Run a loop with
kubectl get --raw /readyz and date in a second
terminal.
Solution
kubectl -n kube-system get lease plndr-cp-lock -o jsonpath='{.spec.holderIdentity}'
while true; do echo "$(date +%T) $(kubectl get --raw /readyz 2>&1 | head -c 30)"; \
sleep 1; doneIn a second terminal, restart the holder (in the lab
cp1; in that case, run the command from cp2) and watch the
loop: after a few seconds of errors, ok comes back, now via
the new holder. The gap results from the duration of the kube-vip lease
and the ARP update in the network. On Day 12 you measure it
precisely.
Save your progress? Sign up for free
Cleanup
Nothing. demo with web and
last stays in place for the following days.
Tip: Take a snapshot of all three VMs now, if your virtualization supports it. From Day 6 on, you change the cluster permanently. With a snapshot, you can repeat the upgrades as often as you like.
Interview Note
- Why three control plane nodes and not two? etcd needs a majority. With three members, one may fail; with two, none may, otherwise the cluster stops.
- What does
--control-plane-endpointdo? It writes a stable address into all kubeconfigs and certificates. Without it, you cannot add another control plane later without reissuing the certificates. - Why
apt-mark hold? So that a routine update does not raise the kubelet or kubeadm beyond the allowed version skew.
Enterprise Note
- Instead of ARP, data centers often put a hardware or cloud load balancer in front of the API servers; kube-vip can alternatively speak BGP.
- Separate worker nodes are the norm in production. Workloads on the control plane save machines in the lab but cost isolation in production.
- Package sources are usually mirrored internally, so that upgrades work without internet access and with vetted packages.
- Many teams build node images in advance with Packer instead of installing packages live.