Longhorn stale mounts after a nuc-a reboot
Recovers the cluster after a node reboot breaks DNS and Longhorn leaves pods with stale or corrupted volume mounts, then fixes the APISIX etcd growth and hardens the cluster so it does not repeat.
First used on 2026-09-28 (nuc-a reboot → only CoreDNS replica down → Longhorn auto-salvage/remount → postgres-0, vernemq-0, etcd-1, streamer stuck; coreapi and zitadel failed on postgres).
| Step | What | Downtime |
|---|---|---|
| 0 | Setup | none |
| 1 | Triage: find broken pods and why | none |
| 2 | Recover postgres (everything depends on it) | postgres restart |
| 3 | Recover other pods with stale mounts | per-pod restart |
| 4 | Fix a volume that fails fsck (vernemq) |
vernemq down until done |
| 5 | Restart pods waiting on postgres | per-pod restart |
| 6 | Restart an unhealthy etcd member | none (quorum kept) |
| 7 | Shrink APISIX etcd (compact + defrag) | none (one member at a time) |
| 8 | Enable etcd auto-compaction | rolling restart |
| 9 | Lower ingress controller sync rate | controller restart |
| 10 | Run 2 CoreDNS replicas | none |
| 11 | Move the APISIX admin key out of git | brief controller restart |
| 12 | Final verification | none |
Status on 2026-09-28¶
| Step | Status | Result |
|---|---|---|
| 1 Triage | Done | 6 broken pods on nuc-b; root cause: nuc-a reboot took down the only CoreDNS pod, Longhorn salvaged volumes and left stale mounts |
| 2 postgres | Done | Recreated; crash recovery finished 02:35:31 UTC, reachable via postgres-internal |
| 3 Stale mounts | Done | streamer, etcd-1 recreated and running |
| 4 fsck (vernemq) | Done | vernemq-0 volume corrupted; recovered, vernemq-0/1/2 all 1/1 Running |
| 5 Dependents | Done | staging coreapi and zitadel restarted, connected to postgres |
| 6 etcd member | Done | etcd-0 restarted; all 3 members healthy, etcd-2 is leader |
| 7 Compact + defrag | Done | Compacted at revision 1959285, then defragged: 257 / 398 / 755 MB → 0.4 MB on all 3 members, all healthy |
| 8 Auto-compaction | Done | Helm revision 10: periodic / 1h on all 3 members, 2Gi memory kept |
| 9 Sync rate | Done | sync_period 1m → 10m by ConfigMap edit; etcd writes ~99/min → 0 at steady state, 0 errors, 34 routes |
| 10 CoreDNS | Not done | Still 1 replica on nuc-a |
| 11 Admin key | Not done | Key still in apisix/initialSetup/gatewayproxy.yaml |
| 12 Verification | Passes | No broken pods, no unhealthy attached volumes, etcd 0.4 MB and healthy |
Changes that exist only in the cluster (not in git): the ingress controller ConfigMap (step 9), and the hand-applied APISIX endpoint and admin key in that ConfigMap.
0. Setup¶
kubectl on the nodes is the k3s binary and reads /etc/rancher/k3s/k3s.yaml (root only) unless KUBECONFIG is set.
All nodes should be Ready. If a node is NotReady, fix that first; nothing below will stick.
1. Triage¶
1.1 List pods that are not healthy¶
kubectl get pods -A -o wide --no-headers \
| awk '$4!="Completed" && ($4!="Running" || $3 ~ /^0\//) {print $1, $2, $3, $4, $5, $8}'
1.2 Read why each one fails¶
NS=database; POD=postgres-0 # change per pod
kubectl -n $NS logs $POD --previous --tail=30
kubectl -n $NS get events --field-selector involvedObject.name=$POD --sort-by=.lastTimestamp | tail -8
Match what you see:
| Symptom in logs / events | Meaning | Go to |
|---|---|---|
I/O error on a data path, could not open ... I/O error |
Stale Longhorn mount | Step 2 / 3 |
App aborts or crashes right at start, volume listed in a Remount event |
Probably stale mount | Step 3 |
'fsck' found errors ... RUN fsck MANUALLY |
Filesystem corrupted | Step 4 |
connection refused to postgres-internal |
Waiting on postgres | Step 5 |
etcd failed liveness probe, leader ... slow disk, failed to create new OS thread |
Overloaded etcd member | Step 6, 7 |
lookup longhorn-backend ... no such host |
DNS was down | Step 10 |
1.3 Check Longhorn volumes and the remount events¶
# Attached volumes that are not healthy
kubectl -n longhorn-system get volumes.longhorn.io \
-o custom-columns=NAME:.metadata.name,STATE:.status.state,ROBUST:.status.robustness,NODE:.status.currentNodeID,NS:.status.kubernetesStatus.namespace,PVC:.status.kubernetesStatus.pvcName \
| awk 'NR==1 || ($2=="attached" && $3!="healthy")'
# Volumes Longhorn salvaged and asked to remount
kubectl get events -n longhorn-system --sort-by=.lastTimestamp | grep -iE 'Remount|salvag' | tail -20
A healthy volume with an I/O error in the pod = the pod still holds the old mount. Recreating the pod fixes it.
1.4 Check DNS¶
2. Recover postgres first¶
coreapi, zitadel and others depend on it, so fix it before anything else.
kubectl -n database delete pod postgres-0
kubectl -n database wait --for=condition=Ready pod/postgres-0 --timeout=300s
Verify it recovered and is reachable through its Service:
kubectl -n database logs postgres-0 --tail=10 # expect: "database system is ready to accept connections"
kubectl -n database exec postgres-0 -- pg_isready -h postgres-internal.database.svc.cluster.local
database system was not properly shut down; automatic recovery in progress is normal after a crash.
If it still logs I/O error after the restart, check the volume is healthy (1.3) and its replicas are running:
VOL=$(kubectl -n database get pvc postgres-pvc -o jsonpath='{.spec.volumeName}')
kubectl -n longhorn-system get replicas.longhorn.io -l longhornvolume=$VOL \
-o custom-columns=NAME:.metadata.name,NODE:.spec.nodeID,STATE:.status.currentState
3. Recover other pods with stale mounts¶
Recreate each pod so kubelet mounts the volume again. Controllers (Deployment/StatefulSet) create the replacement.
kubectl -n cdn delete pod -l app=streamer
kubectl -n vernemq delete pod vernemq-0
kubectl -n apisix delete pod etcd-1 # only if etcd quorum is healthy, see 6.1
kubectl -n cdn get pods -l app=streamer -w # Ctrl+C once 1/1 Running
If a pod then hangs in ContainerCreating, read its events. fsck errors → Step 4. Multi-Attach error usually clears within 1–2 minutes once the old attachment is released.
4. Fix a volume that fails fsck (vernemq example)¶
Event looks like:
MountVolume.MountDevice failed ... 'fsck' found errors on device /dev/longhorn/pvc-...
UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
Kubernetes will never mount it on its own. Pick one option.
Option A: new empty volume (fast, loses vernemq session and queue data)¶
The longhorn-retain storage class keeps the old Longhorn volume, so it can still be repaired later.
NS=vernemq; POD=vernemq-0; PVC=vernemq-data-vernemq-0
OLD_VOL=$(kubectl -n $NS get pvc $PVC -o jsonpath='{.spec.volumeName}')
echo "Old volume kept in Longhorn: $OLD_VOL"
kubectl -n $NS delete pvc $PVC --wait=false # stays Terminating until the pod is gone
kubectl -n $NS delete pod $POD # StatefulSet recreates the pod with a new PVC
kubectl -n $NS get pods -w
vernemq pods start in order (0, then 1, then 2). If vernemq-1 or -2 show the same fsck error, repeat with their PVC.
Option B: repair the existing volume (keeps data)¶
- Stop the pod using it:
kubectl -n vernemq scale sts vernemq --replicas=0
kubectl -n vernemq get pods -w # wait until vernemq-0 is gone
- Longhorn UI → Volume → the volume (
kubectl -n vernemq get pvc vernemq-data-vernemq-0 -o jsonpath='{.spec.volumeName}') → Attach → pick a node → tick Maintenance. - SSH to that node and repair:
Anything fsck could not reconnect ends up in lost+found.
4. Longhorn UI → Detach the volume.
5. Start vernemq again:
5. Restart pods waiting on postgres¶
They give up after about 10 retries, then wait in CrashLoopBackOff (up to 5 min). Once Step 2 is done, restart them to skip the wait.
kubectl -n staging delete pod -l app=coreapi
kubectl -n zitadel delete pod -l app=zitadel
kubectl -n staging get pods; kubectl -n zitadel get pods
Do the same for production coreapi if it is also failing.
After vernemq is up, coreapi should stop logging failed to connect to broker ... websocket: bad handshake:
6. Restart an unhealthy etcd member (APISIX)¶
6.1 Check quorum first¶
Only continue if at least two members are healthy and all show the same RAFT INDEX.
ETCD="kubectl -n apisix exec etcd-1 -c etcd -- etcdctl" # run from a healthy member
$ETCD endpoint health --cluster
$ETCD endpoint status --cluster -w table
6.2 If the bad member is the leader, move leadership first¶
# Member IDs are in the table above. Move leadership to a healthy member.
NEW_LEADER_ID=5355ca4c835fd788 # etcd-2 on 2026-09-28; check yours
$ETCD --endpoints=http://etcd-0.etcd-headless.apisix.svc.cluster.local:2379 move-leader $NEW_LEADER_ID
6.3 Restart it¶
kubectl -n apisix delete pod etcd-0
kubectl -n apisix wait --for=condition=Ready pod/etcd-0 --timeout=600s
$ETCD endpoint health --cluster
A large database makes the new member catch up slowly (72 s for 925 MB on 2026-09-28). Do Step 7 to make this fast.
7. Shrink APISIX etcd (compact + defrag)¶
7.1 Confirm it is history, not data¶
ETCD="kubectl -n apisix exec etcd-1 -c etcd -- etcdctl"
# DB size per member
$ETCD endpoint status --cluster -w table
# Size of live data (bytes)
$ETCD get "" --prefix | wc -c
# Keys rewritten most often (version = number of writes)
$ETCD get "" --prefix -w json | python3 -c '
import json, sys, base64
kvs = json.load(sys.stdin).get("kvs", [])
for k in sorted(kvs, key=lambda k: -k.get("version", 0))[:10]:
print(k["version"], base64.b64decode(k["key"]).decode())'
On 2026-09-28: 925 MB on disk, 39 KB of live data, each upstream written ~60,700 times.
7.2 Compact (drops old revisions, cluster-wide)¶
REV=$($ETCD endpoint status -w json | grep -o '"revision":[0-9]*' | head -1 | cut -d: -f2)
echo "Compacting up to revision $REV"
$ETCD compact $REV
7.3 Defrag (returns disk space, one member at a time, leader last)¶
Defrag blocks the member while it runs. Find the leader in the IS LEADER column of 7.1 and put it last.
for m in etcd-1 etcd-0 etcd-2; do # leader last
echo "== defrag $m"
$ETCD --endpoints=http://$m.etcd-headless.apisix.svc.cluster.local:2379 --command-timeout=120s defrag
$ETCD endpoint health --cluster
done
7.4 Verify¶
$ETCD endpoint status --cluster -w table # DB SIZE should drop to a few MB
$ETCD alarm list # should print nothing
8. Enable etcd auto-compaction¶
Values live in apisix/helm-values/etcd-values.yaml in the playtelly-iac repo. It also keeps the hand-tuned memory (2Gi / 512Mi) and probe thresholds (10), so an upgrade does not revert them.
Together these tell etcd: about once an hour, delete old key versions older than 1 hour.
| Setting | Meaning |
|---|---|
autoCompactionMode: periodic |
Compact on a time schedule (the other mode, revision, keeps the last N changes) |
autoCompactionRetention: "1h" |
Keep 1 hour of history; older versions are deleted. Also sets how often it runs (about hourly) |
Set both. If autoCompactionRetention is empty or 0, auto-compaction is off whatever the mode says. That was the chart default here ("" / ""), so etcd never compacted and grew to 925 MB.
1 hour is safe for APISIX. It only needs the current config; history is used only to resume a watch after a short disconnect. A pod gone longer than 1 hour reloads the full config (~400 kB).
Compaction frees space inside the database file for reuse. It does not shrink the file on disk; that is the defrag in 7.3.
Three pieces keep etcd small, and each covers a different part:
| Piece | Role | Without it |
|---|---|---|
Step 9: sync_period: 10m |
Fewer writes going in | History builds up ~10× faster |
Step 8: auto-compaction 1h |
Old history gets deleted | History grows forever (the cause of the 925 MB) |
| Step 7.3: defrag (occasional, by hand) | Freed space goes back to the disk | File stays large after a spike, but stops growing |
Step 8 must never be missing. Step 9 reduces its work, and step 7.3 is occasional cleanup.
8.1 Check what the upgrade would change¶
helm -n apisix template etcd bitnami/etcd --version 12.0.18 -f apisix/helm-values/etcd-values.yaml \
| python3 -c '
import sys, yaml
docs = [d for d in yaml.safe_load_all(sys.stdin) if d and d.get("kind") == "StatefulSet"]
print(yaml.safe_dump(docs[0]))' > /tmp/etcd-sts-new.yaml
kubectl diff -f /tmp/etcd-sts-new.yaml || true
Expected diff: ETCD_AUTO_COMPACTION_MODE and ETCD_AUTO_COMPACTION_RETENTION added, plus Helm label and checksum changes. If memory or probe values show up in the diff, fix the values file before upgrading.
8.2 Apply (rolling restart, etcd-2 → etcd-1 → etcd-0)¶
All three members must be 1/1 Ready first.
kubectl -n apisix get pods -l app.kubernetes.io/name=etcd
helm -n apisix upgrade etcd bitnami/etcd --version 12.0.18 -f apisix/helm-values/etcd-values.yaml
kubectl -n apisix rollout status sts/etcd --timeout=900s
8.3 Verify¶
for p in etcd-0 etcd-1 etcd-2; do
echo -n "$p: "
kubectl -n apisix get pod $p -o jsonpath='{range .spec.containers[0].env[?(@.name=="ETCD_AUTO_COMPACTION_MODE")]}{.value}{end} {range .spec.containers[0].env[?(@.name=="ETCD_AUTO_COMPACTION_RETENTION")]}{.value}{end} mem={.spec.containers[0].resources.limits.memory}'
echo
done
# expect: periodic 1h mem=2Gi on all three
# After ~1h, etcd logs a compaction
kubectl -n apisix logs etcd-0 --since=2h | grep -i 'compact' | tail -3
Auto-compaction removes old revisions but does not return disk space. Run the defrag in 7.3 by hand only when needed:
PERCENTAGE NOT IN USEinetcdctl endpoint status --cluster -w tableis above about 50%, orDB SIZEclimbs into the tens of MB.
On 2026-09-28 after compact + defrag: DB SIZE 410 kB, IN USE 401 kB, 2% not in use, all members at the same raft index. It should stay under about 1 MB. If it grows back to hundreds of MB, check that sync_period (step 9) was not reset to 1m and that ETCD_AUTO_COMPACTION_* is still set:
kubectl -n apisix get sts etcd -o jsonpath='{range .spec.template.spec.containers[0].env[?(@.name=="ETCD_AUTO_COMPACTION_MODE")]}{.value}{end} {range .spec.template.spec.containers[0].env[?(@.name=="ETCD_AUTO_COMPACTION_RETENTION")]}{.value}{end}{"\n"}'
# expect: periodic 1h
9. Lower the ingress controller sync rate¶
apisix-ingress-controller 2.0.1 re-pushes every route, service and upstream each sync_period (currently 1m), even when nothing changed. That is ~100 etcd writes per minute.
9.1 Measure the write rate¶
ETCD="kubectl -n apisix exec etcd-1 -c etcd -- etcdctl"
rev() { $ETCD endpoint status -w json | grep -o '"revision":[0-9]*' | head -1 | cut -d: -f2; }
R1=$(rev); sleep 60; R2=$(rev); echo "writes/min: $((R2 - R1))"
9.2 Change it (edit the ConfigMap, do not helm upgrade)¶
The chart has a value for it (config.provider.syncPeriod), but do not change it with helm upgrade. The live ConfigMap was applied by hand on top of Helm. It adds provider.apisix.endpoints and provider.apisix.auth.adminKey, which the chart does not generate, and sets init_sync_delay: 0s (the chart says 20m). A helm upgrade would drop those and the controller could lose its connection to APISIX.
Check for that drift first:
diff \
<(helm -n apisix get manifest apisix-ingress-controller | grep -A40 'config.yaml:' | grep -E 'sync|endpoints|adminKey') \
<(kubectl -n apisix get cm apisix-ingress-controller-ingress-config -o jsonpath='{.data.config\.yaml}' | grep -E 'sync|endpoints|adminKey')
Edit only sync_period, keeping a backup:
kubectl -n apisix get cm apisix-ingress-controller-ingress-config -o json > ~/ic-cm-backup.json
sed 's/sync_period: 1m/sync_period: 10m/g' ~/ic-cm-backup.json > ~/ic-cm-new.json
# must show only the sync_period line
diff <(python3 -c "import json;print(json.load(open('$HOME/ic-cm-backup.json'))['data']['config.yaml'])") \
<(python3 -c "import json;print(json.load(open('$HOME/ic-cm-new.json'))['data']['config.yaml'])")
kubectl replace -f ~/ic-cm-new.json
kubectl -n apisix rollout restart deploy/apisix-ingress-controller
kubectl -n apisix rollout status deploy/apisix-ingress-controller --timeout=180s
Roll back if needed: kubectl replace -f ~/ic-cm-backup.json then restart the deployment again.
9.3 Verify¶
# No errors from the controller
kubectl -n apisix logs deploy/apisix-ingress-controller -c manager --since=5m | grep -cE '\sERROR\s' # expect 0
# Routes still in etcd
kubectl -n apisix exec etcd-1 -c etcd -- etcdctl get /apisix/routes --prefix --keys-only | grep -c routes/
Run 9.1 again a few minutes after the restart; the first minutes include the startup full sync. On 2026-09-28: ~99 writes/min before, 0 at steady state after (0 ERROR lines, 34 routes).
Note: this change lives only in the cluster. Re-check it after any helm upgrade of the ingress controller.
10. Run 2 CoreDNS replicas¶
One CoreDNS pod on one node means one reboot takes down DNS for the whole cluster, including Longhorn.
Why this matters: this is what started the 2026-09-28 outage. nuc-a rebooted, the only CoreDNS pod went with it, and Longhorn could not reach its own backend (lookup longhorn-backend ... no such host). Volumes could not remount, and postgres, vernemq and etcd broke. With two replicas on different nodes, that reboot would not have taken DNS down.
CoreDNS is a k3s packaged component (objectset.rio.cattle.io annotations). k3s re-applies its manifest when a server restarts, so kubectl scale alone is reset.
10.1 Quick fix (reset on the next k3s server restart)¶
kubectl -n kube-system scale deploy coredns --replicas=2
kubectl -n kube-system get pods -l k8s-app=kube-dns -o wide # should land on different nodes
10.2 Permanent fix¶
Pick one and apply on all server nodes (castis-desktop, nuc-a, nuc-b):
- Start k3s with
--disable=corednsand deploy CoreDNS yourself (for example thecoredns/corednsHelm chart withreplicaCount: 2and pod anti-affinity), keeping the Service IP<COREDNS_SERVICE_IP>. - Or keep the k3s CoreDNS and re-run 10.1 from a startup hook after each k3s restart.
Test on one node first. A mistake here takes down DNS for the whole cluster.
11. Move the APISIX admin key out of git¶
The admin key is in plain text in apisix/initialSetup/gatewayproxy.yaml (line 15) in the playtelly-iac repo, and in the controller ConfigMap.
- Generate a new key and store it as a Secret:
NEW_KEY=$(openssl rand -hex 16)
kubectl -n apisix create secret generic apisix-admin-key --from-literal=key=$NEW_KEY
- Set the new key on APISIX (
deployment.admin.admin_keyin the APISIX config) and restart APISIX. - Point the GatewayProxy at the Secret instead of the literal
value:(adminKey.valueFrom.secretKeyRef:name: apisix-admin-key,key: key) and apply it. - Update the ingress controller config with the new key and restart it.
- Remove the key from the repo and commit. It stays in git history, so the key must be rotated (steps 1–4), not just deleted.
12. Final verification¶
# No broken pods
kubectl get pods -A --no-headers | awk '$4!="Completed" && ($4!="Running" || $3 ~ /^0\//)'
# No attached volume unhealthy
kubectl -n longhorn-system get volumes.longhorn.io \
-o custom-columns=NAME:.metadata.name,STATE:.status.state,ROBUST:.status.robustness \
| awk '$2=="attached" && $3!="healthy"'
# etcd healthy and small
kubectl -n apisix exec etcd-1 -c etcd -- etcdctl endpoint status --cluster -w table
# postgres reachable
kubectl -n database exec postgres-0 -- pg_isready -h postgres-internal.database.svc.cluster.local
# DNS has more than one replica
kubectl -n kube-system get pods -l k8s-app=kube-dns -o wide
A degraded volume (for example nexus-data-longhorn) is still usable. Longhorn rebuilds the missing replica by itself; if it stays degraded, check it in the Longhorn UI.
Still to investigate¶
- Why castis-desktop and nuc-a restart often (node-exporter on castis-desktop: 430 restarts).
- What makes
etcd-0on mac-mini hitfailed to create new OS thread (errno=11).