Rolling reboots for kernel patching without downtime
unattended-upgrades installs packages but never activates the new kernel. Role-aware, one-at-a-time reboots with Ansible and Semaphore that keep quorum intact.
On paper, every server looked up to date. unattended-upgrades was installing security packages regularly. But uname -r told a different story: most servers were still running the old kernel.
The problem
unattended-upgradesinstalls security packages, but it does not activate the new kernel. That takes a reboot.- It doesn't handle packages from third-party repos either.
- The result: servers that look patched but run on an old kernel.
Rebooting by hand gets forgotten, and it's risky. In clustered services, a reboot in the wrong order causes an outage.
Approach
A role-aware Ansible playbook, with Semaphore on top (a web UI that keeps job history).
- Environment order: test first, then secondary, primary last.
- Production jobs don't run without explicit confirmation.
- Database engines, the Kubernetes distribution and cluster software are excluded from auto-upgrade. They are upgraded separately, as planned work.
- One server at a time. A read-only report is produced every day: which server is waiting for a reboot, which package is out of date.
Role order and checks
Each role has its own checks before and after the reboot:
- Search cluster: shard allocation is set to
primaries. After the reboot it's re-enabled, and we wait until the cluster is green. - Redis: if the server is a master, it gets a Sentinel failover first.
- PostgreSQL + Patroni: if the server is the leader, it gets a switchover first.
- Galera: if the node isn't
Synced, the job stops. - Load balancer: check who holds the VIP. The VIP holder goes last.
- Kubernetes worker: cordon, move single-replica deployments to other nodes with
rollout restart, drain, reboot, uncordon once the node isReady. - Kubernetes control plane: last, one at a time, waiting for etcd to be healthy each time.
Servers in a leader role are skipped unless explicitly enabled.
Lesson A: losing quorum
In a database cluster, the next node was rebooted before the previous one had rejoined the consensus store (Consul/etcd). Quorum was lost. Patroni couldn't write to the DCS, so it demoted the leader. Writes stopped for about a minute.
The fix: before moving to the next server, check that all raft voters are back.
consul operator raft list-peers
# Expected: all nodes listed, Voter=true, State leader or follower
"The service is up" isn't enough. Verify that the node is back in the consensus layer too.
Lesson B: don't trust the reboot-required file
/var/run/reboot-required is written by unattended-upgrades. On a server without it, apt installs the new kernel but the file never appears. The report says "no reboot needed".
Also compare the running kernel with the newest installed kernel of the same flavor (amd64, cloud-amd64, pve):
running=$(uname -r)
case "$running" in
*-cloud-amd64) flavor=cloud-amd64 ;;
*-pve) flavor=pve ;;
*) flavor=amd64 ;;
esac
# same-flavor kernels only; an amd64 search must not match cloud-amd64
newest=$(ls /boot/vmlinuz-* 2>/dev/null | sed 's|/boot/vmlinuz-||' \
| grep -E "^[0-9.]+-[0-9]+-${flavor}\$" | sort -V | tail -n1)
if [ -n "$newest" ] && [ "$running" != "$newest" ]; then
echo "reboot required: $running -> $newest"
fi
If you leave the flavor out of the comparison, a kernel of a different flavor sitting on the same server produces a false alarm.
Lesson C: single-replica pods
A drain kills a single-replica pod with no PDB outright. The service is gone until the new pod comes up on another node. So before the drain, move these deployments to other nodes with rollout restart:
kubectl cordon <dugum>
kubectl -n <ns> rollout restart deployment/<ad>
kubectl -n <ns> rollout status deployment/<ad>
kubectl drain <dugum> --ignore-daemonsets --delete-emptydir-data
Because the cordon comes first, the new pod doesn't land back on the same node.
Result
Test and secondary environments are updated automatically every week at night. For the primary environment, a weekly approval report is produced. Once approved, the same job runs in the same order.
Checklist
- [ ] Is the running kernel the same as the newest installed one?
- [ ] Are databases and cluster software excluded from auto-upgrade?
- [ ] Is only one server rebooted at a time?
- [ ] Is quorum checked before moving to the next node?
- [ ] Are leaders and masters handed over first?
- [ ] Are single-replica pods moved before the drain?
- [ ] Do production jobs require explicit confirmation?