Recover a Bare-Metal Kubernetes Cluster After a Power Outage

In progress Kubernetes Linux Networking

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.
  • kubectl access from the admin workstation, and Ansible inventory for the nodes.

Steps

Power On in Dependency Order

  1. Network first: router, DHCP and switch up and serving addresses.
  2. 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.
  3. Control plane: power it on and check it answers ping.
  4. Workers last: power them on and check each answers ping.

Reach the API Again

  1. If kubectl fails with dial 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>
    
  2. Check that every node rejoined: kubectl get nodes shows all of them Ready.

Bring Storage and Workloads Back

  1. 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
    
  2. Check the applications: kubectl get pods -A -o wide, and work through the cases below for anything not Running.

Fix What's Left

  1. A node stays NotReady: its root filesystem is read-only, swap came back on, or ip_forward reset to 0. Triage first, read-only:

    findmnt -no OPTIONS /; grep -v '^#' /etc/fstab; cat /proc/swaps /proc/sys/net/ipv4/ip_forward
    

    Then sudo systemctl restart containerd kubelet.

  2. A pod is Pending with volume node affinity conflict: its local-path volume 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>
    
  3. 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=1
    

    If 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 node Ready.
  • kubectl get pods -A: no pod in CrashLoopBackOff, Pending or ContainerCreating.
  • Each app answers on its usual address, and a test claim on the NFS storage class binds.

Troubleshooting

References