Appendix A: Cheat Sheet
The most important procedures, commands and traps from Day 0 to Day
16. The days are in brackets. You replace placeholders in angle
brackets; they keep their names from the labs:
<knoten> node, <ziel> target
version, <alt>/<neu> old/new,
<alt.yaml> old manifest,
<gruppe/version> group/version. Commands without a
location run on cp1, node commands on the node in
question.
Measuring (Days 0, 3, 6)
kubectl -n demo logs last | wc -l
kubectl -n demo logs last | awk '$2 != 200' | wc -lAPI probe as a file, so that kill hits only the probe
(pkill -f can end your own SSH session):
cat > probe.sh <<'EOF'
while true; do
echo "$(date +%T) $(curl -sk -m 2 -o /dev/null -w %{http_code} https://172.16.0.100:6443/readyz)"
sleep 1
done
EOF
nohup sh probe.sh > api.log 2>&1 < /dev/null & echo $! > probe.pid
kill $(cat probe.pid); awk '$2 != 200' api.log | wc -lWorkloads that survive maintenance (Days 2, 3, 7)
| Building block | Purpose |
|---|---|
readinessProbe |
the Pod only gets traffic once it is ready |
preStop: sleep |
the endpoint disappears before the process ends |
PDB maxUnavailable: 1 or
minAvailable: 1 |
a drain never evicts all Pods |
topologySpreadConstraints with
matchLabelKeys: [pod-template-hash] |
Pods spread out, even after a rollout |
| more than one replica | without it, none of the above helps |
kubectl get pdb -A # ALLOWED DISRUPTIONS 0 = drain hangs
kubectl drain <knoten> --ignore-daemonsets --delete-emptydir-data --timeout=180s
kubectl uncordon <knoten>Before the upgrade (Days 1, 4, 5, 8)
kubectl version
kubectl get nodes -o custom-columns=NODE:.metadata.name,\
VERSION:.status.nodeInfo.kubeletVersion,RUNTIME:.status.nodeInfo.containerRuntimeVersion
pluto detect-files -d <repo> --target-versions k8s=<ziel> # exit 4 = finding
kubectl get --raw /metrics | grep apiserver_requested_deprecated_apis
kubectl convert -f <alt.yaml> --output-version <gruppe/version>
helm show chart <chart> --version <v> | grep -i kubeVersion
sudo kubeadm upgrade plan- Check add-ons against their matrix before Kubernetes moves up: Cilium 1.19 tested up to v1.35, 1.20 up to v1.36 (Day 8).
- Way back, prepared in advance: back up the etcd snapshot
and
/etc/kubernetes, copy them to a second node (Day 5).
sudo 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 \
snapshot save /var/backups/k8s/etcd-<version>.db
sudo etcdutl snapshot status /var/backups/k8s/etcd-<version>.db -w table
sudo tar czf /var/backups/k8s/etc-kubernetes-<version>.tgz -C /etc kubernetesUpgrading one minor version (Days 6, 7, 9)
Order: package repository → kubeadm → control plane node by node → kubelets node by node → check add-ons. Never skip a minor version.
# on every node: package repository to the new minor version
sudo sed -i "s#/v<alt>/#/v<neu>/#g" /etc/apt/sources.list.d/kubernetes.list
curl -fsSL https://pkgs.k8s.io/core:/stable:/v<neu>/deb/Release.key \
| sudo gpg --batch --yes --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
sudo apt-get update
sudo apt-mark unhold kubeadm && sudo apt-get install -y kubeadm=<version>-1.1 \
&& sudo apt-mark hold kubeadmsudo kubeadm upgrade apply v<version> --yes # first control plane node
sudo kubeadm upgrade node # all other nodes# per node: drain, kubelet, uncordon
kubectl drain <knoten> --ignore-daemonsets --delete-emptydir-data
sudo apt-mark unhold kubelet kubectl
sudo apt-get install -y kubelet=<version>-1.1 kubectl=<version>-1.1
sudo apt-mark hold kubelet kubectl
sudo systemctl daemon-reload && sudo systemctl restart kubelet
kubectl uncordon <knoten>- Relieve the VIP holder first: move the kube-vip manifest to
/etc/kubernetes/kube-vip.yaml.pausiert, wait 25 s, check the holder, put it back after the intervention (Day 6).
kubectl -n kube-system get lease plndr-cp-lock -o jsonpath='{.spec.holderIdentity}{"\n"}'Restore from the snapshot (Day 9)
On all control plane nodes: stop the static Pods
(move the manifests out of /etc/kubernetes/manifests), back
up the old data directory, bring the packages and
/etc/kubernetes back to the old version, then per node:
IC=cp1=https://172.16.0.126:2380,cp2=https://172.16.0.228:2380,cp3=https://172.16.0.83:2380
sudo etcdutl snapshot restore <snapshot.db> --name <knoten> \
--initial-cluster $IC --initial-cluster-token day2-restore \
--initial-advertise-peer-urls https://<ip>:2380 --data-dir /var/lib/etcdThen put the manifests back, etcd first. Pods that were created after the snapshot no longer exist afterwards.
Certificates (Day 10)
sudo kubeadm certs check-expiration
sudo kubeadm certs renew all # per control plane node
kubectl get csr | grep Pending # serverTLSBootstrap: kubelet serving certificates
kubectl get csr <csr> -o jsonpath='{.spec.request}' | base64 -d | openssl req -noout -text \
| grep DNS:
kubectl certificate approve <csr>- After
renew all, the API server and etcd reload their serving certificates on their own, but not their client certificates. That is why you restart all static Pods of the control plane anyway. - Renew
admin.confand~/.kube/configas well.
etcd (Days 11, 12)
export ETCDCTL_ENDPOINTS=https://172.16.0.126:2379,https://172.16.0.228:2379,https://172.16.0.83:2379
export ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt
export ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt
export ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key
sudo -E etcdctl endpoint health -w table
sudo -E etcdctl endpoint status -w table
sudo -E etcdctl member list -w table
sudo -E etcdctl alarm list
sudo -E ETCDCTL_ENDPOINTS=https://<ip>:2379 etcdctl defrag # one member
sudo -E ETCDCTL_ENDPOINTS=https://<leader-ip>:2379 etcdctl move-leader <id>- A set
ETCDCTL_ENDPOINTSplus--endpointsaborts. Override the variable per call instead. - The API server compacts every 5 minutes; deleted data is only freed after two cycles. Defragmenting makes the file smaller: followers first, leader last.
- Quota 2 GiB, above that the
NOSPACEalarm. - Snapshot timer:
etcd-snapshot.serviceand.timer, every 6 h, 7 days, on every control plane node. Check withsystemctl is-failed etcd-snapshot.service, not only with the timer.
Replacing a node (Day 12)
kubectl drain <knoten> --ignore-daemonsets --delete-emptydir-data
sudo kubeadm reset -f # on the node, removes the etcd member
sudo -E etcdctl member remove <id> # only if reset did not run
kubectl delete node <knoten>
sudo kubeadm init phase upload-certs --upload-certs | tail -1 > certkey.txt
kubeadm token create --print-join-command > join.txt
sudo $(cat join.txt) --control-plane --certificate-key $(cat certkey.txt) \
--apiserver-advertise-address <ip> # on the nodeFollow-up work: put the kube-vip manifest back, remove the taint
node-role.kubernetes.io/control-plane, review and approve
the kubelet CSR, spread the workloads again.
Capacity and cleanup (Day 13)
kubectl top nodes
kubectl describe node <knoten> | grep -E '^ (cpu|memory) '
kubectl get node <knoten> -o jsonpath='{.status.allocatable}'
sudo crictl rmi --prune
sudo crictl imagefsinfo
journalctl --disk-usage- The scheduler plans by requests, not by consumption. The tightest
limit can be
maxPods(110). revisionHistoryLimit: 3instead of 10. A LimitRange sets defaults and bounds at creation time.- The kubelet cleans up images from 85 % disk usage and evicts Pods from 90 %.
Automatic upgrades with k3s (Day 14)
apiVersion: upgrade.cattle.io/v1
kind: Plan
metadata: {name: server, namespace: system-upgrade}
spec:
concurrency: 1
cordon: true
nodeSelector:
matchExpressions:
- {key: node-role.kubernetes.io/control-plane, operator: In, values: ["true"]}
serviceAccountName: system-upgrade
upgrade: {image: rancher/k3s-upgrade}
version: v1.37.2+k3s1 # or channel: https://update.k3s.io/v1-release/channels/v1.37Patching the operating system (Day 15)
sudo apt-get full-upgrade # not upgrade: a new kernel is a new package
cat /var/run/reboot-required.pkgs
apt-mark showhold # cri-tools and kubernetes-cni are NOT on hold
swapon --show; grep -c swap /etc/fstab
sudo systemctl rebootOrder: nodes without a role first, VIP holder and etcd leader last,
move the measuring points off the node beforehand. After
Ready, wait until all Pods are running, then uncordon.
From the message to the cause
| Message (excerpt) | Cause (day) |
|---|---|
Cannot evict pod as it would violate the pod's disruption budget |
PDB allows 0 (2, 16) |
| Drain aborts on a bare Pod | --force needed, the Pod is lost (2) |
didn't match pod topology spread constraints during the
drain |
spread with DoNotSchedule (15) |
remote error: tls: internal error on
kubectl logs |
kubelet without serving certificate, CSR pending (10, 16) |
x509: cannot validate certificate in
metrics-server |
kubelet certificate without IP SAN (8, 10) |
conflicting environment variable is shadowed |
ETCDCTL_* and flag at the same time (11) |
required revision has been compacted |
old revision compacted (11) |
etcdserver: member not found |
member already removed (12) |
tls: private key does not match public key |
wrong key in the unit (16) |
running with swap on is not supported |
swap active, failSwapOn: true (16) |
maximum memory usage per Container is 512Mi |
LimitRange max (13, 16) |
exceeded quota during the rollout |
no room for the extra Pod (Appendix B) |
inotify_init: too many open files |
inotify limit, often due to a second cluster (14) |
kept back for the kernel |
upgrade instead of full-upgrade (15) |
services have not yet been read at least once |
kubelet right after a restart, wait (15) |