Day 7: Upgrade to v1.36 – the kubelets
Goal: Upgrade kubelet and kubectl on all three nodes to v1.36.6, node by node, without losing a single request · Duration: approx. 45 min · Prerequisite: Day 6
Briefing
- Per node, always the same four steps: drain → packages →
restart kubelet → uncordon. Only when a node is
Readyagain do you move on to the next one. - For pure workers,
sudo kubeadm upgrade nodecomes before the packages; it updates the kubelet configuration. Your three nodes already did that as control plane nodes on Day 6. - A kubelet restart does not stop any running containers. The drain is still mandatory: it protects you in case the new kubelet does not start.
| Node | Drain command |
|---|---|
| cp2, cp3 | kubectl drain <node> --ignore-daemonsets --delete-emptydir-data |
| cp1 | additionally --pod-selector='app!=last' (Day 2) |
Drill 1: Measurement and starting point
mkdir -p ~/day2/tag07 && cd ~/day2/tag07
kubectl -n demo delete pod last
sed "s#http://web.demo#http://shop.demo#" ~/day2/tag00/last.yaml | kubectl apply -f -
kubectl -n demo wait --for=condition=Ready pod/last
kubectl get nodesExpected:
NAME STATUS ROLES AGE VERSION
cp1 Ready control-plane 97m v1.35.10
cp2 Ready control-plane 95m v1.35.10
cp3 Ready control-plane 94m v1.35.10
Save your progress? Sign up for free
Drill 2: cp2
kubectl drain cp2 --ignore-daemonsets --delete-emptydir-dataExpected (abridged):
node/cp2 cordoned
pod/coredns-589f44dc88-qqmpb evicted
pod/shop-56d7b69945-s99h5 evicted
node/cp2 drained
Since Day 6, the package repository points to v1.36:
# on cp2
sudo apt-mark unhold kubelet kubectl
sudo apt-get install -y kubelet=1.36.6-1.1 kubectl=1.36.6-1.1
sudo apt-mark hold kubelet kubectl
sudo systemctl daemon-reload
sudo systemctl restart kubelet
systemctl is-active kubelet
kubelet --versionExpected (abridged):
kubelet set on hold.
kubectl set on hold.
active
Kubernetes v1.36.6
Back on cp1:
kubectl uncordon cp2
kubectl get nodes
kubectl -n demo logs last | awk '$2 != 200' | wc -lExpected:
node/cp2 uncordoned
NAME STATUS ROLES AGE VERSION
cp1 Ready control-plane 98m v1.35.10
cp2 Ready control-plane 96m v1.36.6
cp3 Ready control-plane 95m v1.35.10
0
Three nodes, two versions. The API server is on v1.36, the kubelets are zero or one minor version behind. Up to three would be allowed.
Save your progress? Sign up for free
Drill 3: cp3
kubectl drain cp3 --ignore-daemonsets --delete-emptydir-dataExpected (abridged):
node/cp3 cordoned
pod/cilium-operator-5696c85df9-sw2qh evicted
pod/web-776b55fcfb-fq5cc evicted
pod/shop-56d7b69945-5kv66 evicted
pod/coredns-589f44dc88-9l7d9 evicted
node/cp3 drained
# on cp3
sudo apt-mark unhold kubelet kubectl
sudo apt-get install -y kubelet=1.36.6-1.1 kubectl=1.36.6-1.1
sudo apt-mark hold kubelet kubectl
sudo systemctl daemon-reload
sudo systemctl restart kubelet
kubelet --versionkubectl uncordon cp3
kubectl -n demo logs last | wc -l
kubectl -n demo logs last | awk '$2 != 200' | wc -lExpected:
node/cp3 uncordoned
513
0
Save your progress? Sign up for free
Drill 4: cp1, with the load generator on board
kubectl drain cp1 --ignore-daemonsets --delete-emptydir-data --pod-selector='app!=last'Expected (abridged):
node/cp1 cordoned
pod/web-776b55fcfb-p2zdn evicted
pod/web-776b55fcfb-9czjr evicted
pod/cilium-operator-5696c85df9-zr66x evicted
pod/metrics-server-5f54fb74d9-ts78j evicted
pod/coredns-589f44dc88-fsbms evicted
pod/shop-56d7b69945-xxpvb evicted
node/cp1 drained
last stays on cp1 while its kubelet
restarts:
sudo apt-mark unhold kubelet kubectl
sudo apt-get install -y kubelet=1.36.6-1.1 kubectl=1.36.6-1.1
sudo apt-mark hold kubelet kubectl
sudo systemctl daemon-reload
sudo systemctl restart kubelet
kubectl -n demo get pod last -o custom-columns=NAME:.metadata.name,\
STATUS:.status.phase,RESTARTS:.status.containerStatuses[0].restartCountExpected:
NAME STATUS RESTARTS
last Running 0
No restart: the kubelet is only the manager; the containers belong to containerd. A new kubelet simply takes over the running containers.
kubectl uncordon cp1
kubectl get nodes
kubectl versionExpected:
node/cp1 uncordoned
NAME STATUS ROLES AGE VERSION
cp1 Ready control-plane 100m v1.36.6
cp2 Ready control-plane 98m v1.36.6
cp3 Ready control-plane 97m v1.36.6
Client Version: v1.36.6
Kustomize Version: v5.8.1
Server Version: v1.36.6
Save your progress? Sign up for free
Drill 5: The results
kubectl -n demo logs last | wc -l
kubectl -n demo logs last | awk '$2 != 200' | wc -lExpected:
723
0
0 errors in 723 requests, three drains, three kubelet restarts. That is the payoff of Day 3: without a readiness probe and a PDB, each of these drains would have cost as much as on Day 2.
And the fix for preStop hooks from the changelog (Day 5)? It does not change this number: it was already 0 under v1.35. You would only have noticed it if hooks had hung too long on shutdown, that is, in longer drains.
Look again at the drain of cp1 in Drill 4:
two web Pods were evicted at once.
web has neither a PDB nor a topology spread, so two of
three replicas were on the same node. web starts in
milliseconds, which is why nobody noticed. With the startup time of
shop, it would have been half an outage.
Save your progress? Sign up for free
Exercise: Speed Drills
- Show all nodes with their kubelet version and the time since which
they have been
Ready. Target time: 2 min - Check on all three nodes that kubelet and kubectl are on
hold. Target time: 2 min - Find out which configuration file the kubelet reads. Target time: 1 min
Solution
kubectl get nodes -o custom-columns=NAME:.metadata.name,\
KUBELET:.status.nodeInfo.kubeletVersion,\
READY_SEIT:'.status.conditions[?(@.type=="Ready")].lastTransitionTime'apt-mark showhold
for n in 172.16.0.228 172.16.0.83; do ssh ubuntu@$n apt-mark showhold; doneExpected: kubeadm,
kubectl, kubelet three times.
systemctl cat kubelet | grep -o '\-\-config=[^ ]*'Expected:
--config=/var/lib/kubelet/config.yaml". The option is in
the kubeadm drop-in file; the quotation mark belongs to the line
there.
Save your progress? Sign up for free
Checkpoint
kubectl get nodesExpected: all three Ready,
v1.36.6, none SchedulingDisabled.
kubectl -n demo get pods -l app=shop -o custom-columns=POD:.metadata.name,NODE:.spec.nodeNameExpected: two Pods on different nodes.
Challenge
Protect web the way you protected shop on
Day 3, so that two replicas are never gone at the same time during the
next upgrade.
Hint: web has three replicas. Which
maxUnavailable makes sense?
Solution
cd ~/day2/tag07
cat > web-pdb.yaml <<'EOF'
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: {name: web, namespace: demo}
spec:
maxUnavailable: 1
selector: {matchLabels: {app: web}}
EOF
kubectl apply -f web-pdb.yaml
kubectl -n demo patch deploy web --type=merge -p '{"spec":{"template":{"spec":
{"topologySpreadConstraints":[{"maxSkew":1,"topologyKey":"kubernetes.io/hostname",
"whenUnsatisfiable":"DoNotSchedule","labelSelector":{"matchLabels":{"app":"web"}}}]}}}}'
kubectl -n demo rollout status deploy/web
kubectl -n demo get pods -l app=web -o custom-columns=POD:.metadata.name,NODE:.spec.nodeNameExpected (after the rollout, in the lab):
POD NODE
web-6b447988f-27qs7 cp1
web-6b447988f-85swm cp1
web-6b447988f-c24l7 cp3
Two on cp1, despite the spread. During the rollout an
old Pod was still running on cp2, and the spread counts all
Pods with app=web, old and new alike. To the scheduler,
cp2 therefore looked occupied. A spread only takes effect
at scheduling time; nothing is corrected afterwards. The solution: count
only Pods of the same revision.
kubectl -n demo patch deploy web --type=json -p '[{"op":"add",
"path":"/spec/template/spec/topologySpreadConstraints/0/matchLabelKeys",
"value":["pod-template-hash"]}]'
kubectl -n demo rollout status deploy/web
kubectl -n demo get pods -l app=web -o custom-columns=POD:.metadata.name,NODE:.spec.nodeNameExpected:
POD NODE
web-75d549d885-bmcxf cp3
web-75d549d885-nwljh cp1
web-75d549d885-q85xs cp2
Three nodes, three Pods. shop from Day 3 already has the
matchLabelKeys line in its manifest.
Save your progress? Sign up for free
Cleanup
kubectl uncordon cp1 cp2 cp3Interview Note
- Why drain if a kubelet restart does not stop any
containers? Because the new kubelet might not start, for
example because of a removed option. Then the Pods sit without a manager
on a node that becomes
NotReady. - In which order do you upgrade the control plane and the workers? First all API servers, then controller manager and scheduler, then the kubelets.
- How long may a cluster run mixed kubelet versions? As long as the skew policy allows: up to three minor versions behind the API server.
Enterprise Note
- With many nodes, kubelet upgrades run in waves, for example one rack or one zone after another, controlled through labels and automation (Ansible, Cluster API).
- Instead of replacing packages in the running system, many teams replace nodes entirely: add a new node with a new image, drain and remove the old one (Day 12).
- A monitoring alert on “node
SchedulingDisabledfor longer than N minutes” catches a forgottenuncordon.