Skip to content

castis-desktop node instability

Date: 2026-07-14 Node affected: castis-desktop (control-plane, etcd, master) Cluster: k3s, 4 nodes (castis-desktop, nuc-a, nuc-b, mac-mini)


Summary

castis-desktop is a 4-node k3s cluster's smallest member (3.7GB RAM) but carries a disproportionate load: k3s control-plane + etcd member, Longhorn manager/CSI/engine processes, Docker, and (until today) a full GNOME desktop session and GitLab Runner. Sustained memory pressure caused the node to intermittently flap NotReady, which cascaded into an etcd raft log corruption and a stuck Longhorn VolumeAttachment, taking down one of three apisix etcd members and blocking a vernemq pod from starting.

Root cause and contributing factors were identified and resolved. Memory limits were added to the two components directly involved in the incident.


Timeline / Root Cause Chain

  1. Structural issue: castis-desktop runs a full desktop GUI + CI runner + k3s control-plane + Longhorn storage node, all on 3.7GB RAM — far less headroom than the other 3 nodes (6–16GB each).
  2. No memory limits were set on most pods across apisix, longhorn-system, argocd, monitoring namespaces — nothing bounded how much RAM any single component could consume.
  3. Under load, the node began swapping (confirmed via free -h: swap usage climbing from 0 → 500Mi → 727Mi over the session).
  4. Swapping slowed the node enough that kubelet missed heartbeats, causing the node to flap Ready ↔ NotReady repeatedly (8 times over 3 days per kubectl describe node).
  5. During one NotReady window / reboot, several containerd-shim processes became orphaned (zombie shims from previous crash cycles never got reaped) — these alone were later found consuming a large share of the node's memory.
  6. Amid this instability, etcd-1's raft log became corrupted (tocommit(6027616) is out of range [lastIndex(6027386)] — a raft panic caused by an interrupted/incomplete write, likely from a mid-operation kill).
  7. Separately, a Longhorn CSI VolumeAttachment object got stuck mid-deletion (finalizer external-attacher/driver-longhorn-io never cleared, likely because a csi-attacher sidecar restarted mid-operation — that sidecar has a historical restart count of 310). This blocked etcd-2 (and earlier, vernemq-2) from attaching their volumes on reschedule.

Remediation Steps Taken

1. Cleared zombie containerd-shim processes

Identified via ps -p <pids> that 9 shim processes from prior crash cycles were still running and never reaped.

sudo kill -9 3909 3915 3952 4014 4134 4162 5425 8701 9303
Impact: freed the single largest chunk of memory in the session (used memory dropped from 2.3Gi → 524Mi).

2. Disabled the desktop GUI session

Since this node is accessed via SSH only, the GNOME desktop environment was pure overhead.

sudo systemctl set-default multi-user.target
sudo systemctl isolate multi-user.target

3. Stopped unnecessary services

sudo systemctl stop gitlab-runner
sudo systemctl disable gitlab-runner

sudo systemctl stop mysql.service   # was unused; confirmed no active connections first

systemctl --user stop pulseaudio.service pulseaudio.socket
systemctl --user disable pulseaudio.service pulseaudio.socket

4. Cleaned up stale Docker containers

Removed ~15-month-old exited containers from an old standalone monitoring stack (Grafana, InfluxDB, Loki, Promtail, k6) and stale GitLab Runner build artifacts.

sudo docker rm -f <container_ids...>
sudo docker image prune -a

5. Rebuilt corrupted etcd-1

Confirmed via logs that the raft log was corrupted beyond auto-recovery. Since etcd-0 and etcd-2 held healthy quorum, wiped etcd-1's PVC and let it resync fresh from peers.

kubectl delete pod etcd-1 -n apisix
kubectl delete pvc data-etcd-1 -n apisix
# StatefulSet recreated both automatically; etcd-1 rejoined and resynced

6. Cleared the stuck VolumeAttachment finalizer

kubectl get volumeattachment | grep <volume-id>
kubectl patch volumeattachment <name> -p '{"metadata":{"finalizers":null}}' --type=merge
Safe because the underlying Longhorn volume was independently confirmed attached/healthy — the finalizer was stale bookkeeping, not an in-progress operation.

7. Set memory limits — etcd (Helm-managed, Bitnami chart v12.0.14)

# /tmp/etcd-values.yaml (appended to existing values)
resources:
  requests:
    memory: "256Mi"
    cpu: "100m"
  limits:
    memory: "768Mi"
    cpu: "500m"
preUpgradeJob:
  enabled: false   # disabled — chart's default pre-upgrade hook image tag (bitnami/etcd:3.6.4-debian-12-r3) no longer exists on Docker Hub
helm repo add bitnami https://charts.bitnami.com/bitnami
helm upgrade etcd bitnami/etcd -n apisix -f /tmp/etcd-values.yaml --version 12.0.14

8. Set memory limits — longhorn-manager (plain manifest DaemonSet)

Checked Longhorn's own guaranteed-instance-manager-cpu setting first — confirmed instance-manager resources are managed internally by Longhorn and should not be patched directly. longhorn-manager itself had no resources set ({}), so it was patched directly.

kubectl patch ds longhorn-manager -n longhorn-system --type='json' -p='[
  {"op":"add","path":"/spec/template/spec/containers/0/resources","value":{"requests":{"memory":"256Mi","cpu":"100m"},"limits":{"memory":"1Gi","cpu":"1000m"}}}
]'


Deployment Method Reference (for future changes)

Component Namespace Managed by How to change config
etcd apisix Helm (bitnami/etcd v12.0.14) helm upgrade with values file
apisix-ingress-controller apisix Helm helm upgrade with values file
cnpg (CloudNative-PG operator) cnpg-system Helm helm upgrade with values file
vm-stack (Grafana, VictoriaMetrics, etc.) monitoring Helm (victoria-metrics-k8s-stack) helm upgrade with values file
apisix-dashboard apisix Plain manifest kubectl apply / kubectl patch directly
longhorn-manager longhorn-system Plain manifest (DaemonSet) kubectl patch directly
longhorn instance-manager longhorn-system Longhorn-internal controller Do not patch directly — use settings.longhorn.io CRD
kube-system core addons (coredns, metrics-server, etc.) kube-system k3s built-in HelmChart CRD HelmChartConfig override, not direct edit
authapi, coreapi, tellyboard, tellyid, spatio, orgconsole, playout, ticketcms production/staging ArgoCD (Kustomize overlays) Edit services/*/overlays/* in playtelly-iac git repo, push to main
argocd itself argocd (not investigated this session) —
cdn (cproxy, streamer) cdn (not investigated this session) —

Current State (End of Session)

  • castis-desktop node: Ready, stable
  • Memory: ~1.7Gi available, swap usage back near-zero
  • etcd-0, etcd-1, etcd-2: all 1/1 Running, memory limits applied (768Mi/256Mi)
  • vernemq-0/1/2: all 1/1 Running, 0 restarts
  • longhorn-manager (4 pods): all 2/2 Running, memory limits applied (1Gi/256Mi)
  • GUI, gitlab-runner, mysql, pulseaudio stopped/disabled
  • Zombie containerd-shims cleared
  • Old Docker containers/images cleaned up

Item Priority Notes
Memory limits for cnpg operator Low Helm-managed, same pattern as etcd
Memory limits for vm-stack components Low Helm-managed; larger chart, multiple sub-components each may need their own resources key
Memory limits for Longhorn CSI sidecars (csi-attacher, csi-provisioner, csi-resizer, csi-snapshotter) Low–Medium High historical restart counts (up to 814); not currently crash-looping, but unprotected
Memory limits across argocd, apisix-dashboard, kube-system add-ons Low Hygiene; none caused this incident
Remove unused snap packages (Firefox, GNOME runtimes, etc.) Low Frees disk (~1-2GB), negligible memory impact since GUI is already disabled
Review systemd-oomd configuration Low Ubuntu's userspace OOM daemon; worth confirming it's tuned sensibly given tight RAM budget
Decide on mysql.service Open Currently stopped but still enabled; will restart on next reboot unless explicitly disabled
Structural: consider whether castis-desktop should remain an etcd/control-plane member long-term Medium It's the weakest node in the cluster yet holds a role sensitive to latency and memory pressure

Key Lessons

  1. No memory limits + a resource-constrained node = unpredictable cascading failures. The OOM killer, when forced to act without limits in place, can kill critical processes (like etcd) mid-write, causing actual data corruption rather than a clean, contained restart.
  2. Zombie containerd-shims can silently consume significant memory after repeated crash/restart cycles and are easy to miss unless specifically checked via ps aux --sort=-%mem.
  3. Stuck CSI VolumeAttachment finalizers can block future pod scheduling long after the original disruption — worth checking kubectl get volumeattachment when pods are stuck in FailedAttachVolume, even if the underlying storage is otherwise healthy.
  4. Bitnami charts' preUpgradeJob hooks can break if Bitnami prunes the specific image tag the chart references — since Bitnami began restricting free image availability, pinned tags in older chart versions may disappear. Disabling the hook (preUpgradeJob.enabled: false) is a reasonable workaround when only non-version-affecting values (like resources) are being changed.
  5. Set generous, not tight, memory limits on storage/consensus-critical components (etcd, Longhorn manager) — too tight risks self-inflicted crash loops; the goal is a safety ceiling, not fine-tuned efficiency.