Recover a Bare-Metal Kubernetes Cluster After a Power Outage
Goal
Bring a homelab cluster back after an unclean power loss, in an order that avoids dependency deadlocks, then fix the usual leftovers: stale ARP entries, a crash-looping storage provisioner, nodes stuck NotReady, orphaned local volumes and stale database locks.
Prerequisites
- Physical access to the machines, or out-of-band power control.
kubectlaccess from the admin workstation, and Ansible inventory for the nodes.
Steps
Power On in Dependency Order
- Network first: router, DHCP and switch up and serving addresses.
- Storage next: power on the NAS, wait until it has finished booting, then check in its UI that the pool is healthy and the NFS exports are up.
- Control plane: power it on and check it answers
ping. - Workers last: power them on and check each answers
ping.
Reach the API Again
- If
kubectlfails withdial tcp <vip>:6443: connect: no route to host, the workstation still holds the virtual IP's old MAC address. Flush it and ping again:sudo arp -d <vip> # macOS sudo ip neigh flush to <vip> # Linux ping -c 2 <vip> - Check that every node rejoined:
kubectl get nodesshows all of themReady.
Bring Storage and Workloads Back
- Restart the NFS provisioner if the control plane came up before the NAS:
kubectl get pods -n kube-system -l app=nfs-subdir-external-provisioner kubectl rollout restart deployment nfs-subdir-external-provisioner -n kube-system - Check the applications:
kubectl get pods -A -o wide, and work through the cases below for anything notRunning.
Fix What's Left
-
A node stays
NotReady: its root filesystem is read-only, swap came back on, orip_forwardreset to 0. Triage first, read-only:findmnt -no OPTIONS /; grep -v '^#' /etc/fstab; cat /proc/swaps /proc/sys/net/ipv4/ip_forward/read-only on every boot with no active/line in fstab: restore the line (see With No Active Root Entry in fstab, systemd Leaves the Root Filesystem Read-Only on Every Boot); nofsckneeded./read-only after disk errors: follow Recover a Read-Only Root Filesystem with fsck.- Swap on:
sudo swapoff -a, comment out the swap line, andsudo systemctl mask swap.target. ip_forward0: the sysctl lives in a file Debian 13 ignores; move it to/etc/sysctl.d/(see Runtime Kernel Changes Last Until Reboot Unless Written to Their Configuration Directory).
Then
sudo systemctl restart containerd kubelet. -
A pod is
Pendingwithvolume node affinity conflict: itslocal-pathvolume lives on a node that isn't coming back. Delete the claim (that data is lost) and the pod, so it is recreated on a healthy node:kubectl delete pvc <claim> -n <namespace> kubectl delete pod <pod> -n <namespace> -
An app logs
database is locked: stale locks on its SQLite file. Scale it to zero, wait for the volume to be released, and scale it back:kubectl scale deploy <app> -n <namespace> --replicas=0 kubectl scale deploy <app> -n <namespace> --replicas=1If it happens again, move that database off NFS (see SQLite Needs Reliable File Locks, So Its Database Belongs on Local Disk, Not on NFS).
Optional: Script Step 9 Across Nodes
Running the same fixes over SSH node by node is slow. Ansible ad-hoc commands can do it in one go:
NODE=<node>
ansible "$NODE" -b -K -m shell -a "grep -v '^#' /etc/fstab" # an active "/" line must be there
ansible "$NODE" -b -K -m shell -a "swapoff -a; sed -i '/ swap / s/^/#/' /etc/fstab; systemctl mask swap.target"
ansible "$NODE" -b -K -m shell -a 'fsck -y "$(findmnt -n -o SOURCE /)" || true' # see the warning below
ansible "$NODE" -b -K -m reboot # reboot rather than remount after fsck
Verify
-
kubectl get nodes: every nodeReady. -
kubectl get pods -A: no pod inCrashLoopBackOff,PendingorContainerCreating. - Each app answers on its usual address, and a test claim on the NFS storage class binds.
Troubleshooting
- Pods hang in
ContainerCreatingwith mount errors: the NAS isn't serving yet, or the node lacksnfs-common. See Kubernetes Storage Failures Usually Start on the Host or the NAS. - The control plane's API answers, but the VIP doesn't move after a failure: see A Highly Available Control Plane Needs a Virtual IP That No Single Node Owns.
References
- After a Power Cut, Nodes Must Boot After the Storage They Mount - why the boot order matters.
- ext4 Remounts Root Read-Only When It Cannot Trust the Disk, and the kubelet Falls with It - why nodes come back
NotReady. - Drain and Shut Down a Bare-Metal Kubernetes Node - the clean shutdown that avoids most of this.
- Kubernetes MOC - hub for Kubernetes notes.
- Kubernetes documentation: Node status - what
ReadyandNotReadymean. - Ansible documentation: Introduction to ad hoc commands -
-b,-Kand the shell module.