Skip to content

APISIX 503 after etcd quorum loss

Date: 2026-05-14
Severity: High
Duration: ~3 hours
Affected Services: All domains behind APISIX (mashup.castis.io, iam.castis.io, argo.castis.io, monitor.castis.io, shaka.castis.io, nexus.castis.io, etc.)
Resolved By: etcd cluster recovery + APISIX re-sync on both clusters


Infrastructure Overview

This system runs two separate k3s clusters, each with their own APISIX installation:

Cluster Node APISIX Namespace Serves
Cloud (DigitalOcean SGP1) ubuntu-mashup-gitlab-haproxy ingress-apisix mashup.castis.io, iam.castis.io, argo.castis.io, monitor.castis.io, headscale.castis.io, etc.
Local (NUC homelab) castis-desktop, nuc-a, nuc-b apisix shaka.castis.io, nexus.castis.io, registry.nexus.castis.io

When APISIX goes down, both clusters must be checked and recovered independently.


Summary

etcd on the cloud cluster became severely overloaded due to disk I/O pressure on the worker node (ubuntu-mashup-gitlab-haproxy). The root disk was at 81% capacity (251GB/310GB used), primarily caused by 65GB of unreferenced Docker image blobs accumulating in the GitLab container registry over time with no cleanup policy configured. The slow disk caused etcd write latency to spike from the expected 100ms to over 4.5 seconds, triggering API server timeouts, leader election failures, and a full cascade failure across all APISIX-routed services.


Root Cause

Primary cause: Disk at 81% capacity caused etcd I/O latency spike on the cloud cluster.

Contributing cause: 65GB of orphaned Docker image blobs in GitLab container registry with no cleanup policy configured, accumulated over ~1 year of CI/CD builds.

Evidence from logs:

{"level":"warn","msg":"apply request took too long",
"took":"4.591600424s","expected-duration":"100ms",
"request":"key:\"/registry/leases/kube-system/kube-scheduler\""}


Why One Slow Disk Broke Everything

The cloud node runs two completely separate etcd instances on the same physical disk:

/dev/vda1 (same disk — 81% full)
    │
    ├── k3s built-in etcd  ← stores ALL Kubernetes state
    │     (pod scheduling, deployments, services, PVCs, leases...)
    │
    └── APISIX etcd  ← stores only APISIX routes and SSL config

When the disk slowed down, both etcd instances were affected simultaneously, causing two independent failure chains from one root cause:

Chain 1 — k3s etcd slow → zitadel-db cannot schedule:

Disk slow → k3s etcd writes take 4.5s
  └─► kube-scheduler cannot renew its leader lease in etcd
        └─► kube-scheduler loses leader election
              └─► No active scheduler → new pods cannot be assigned to nodes
                    └─► zitadel-db stuck in ContainerCreating
                          └─► Zitadel CrashLoopBackOff

Chain 2 — APISIX etcd slow → 503 on all domains:

Disk slow → APISIX etcd also overloaded
  └─► apisix-etcd-0 and etcd-2 pods restart under pressure
        └─► EmptyDir wiped → lost all cluster membership data
              └─► etcd quorum lost (only 1 of 3 members healthy)
                    └─► APISIX cannot read/write config from etcd
                          └─► ingress-controller cannot push routes or SSL
                                └─► 503 on all domains

Both failures happened simultaneously from the same underlying disk pressure, which is why the incident appeared to affect everything at once.


Cascade Chain (Combined)

Disk 81% full → etcd write latency 4.5s (expected 100ms)
  ├─► [k3s etcd] kube-scheduler loses leader election
  │       └─► zitadel-db cannot be scheduled → Zitadel CrashLoopBackOff
  │
  └─► [APISIX etcd] etcd-0 and etcd-2 restart → lose EmptyDir data
          └─► etcd quorum lost (1/3 members)
                └─► APISIX cannot reach etcd
                      └─► All routes/SSL fail to sync
                            └─► 503 on all domains

Detailed Timeline

Time (UTC) Event
~00:00 Disk I/O pressure — etcd latency spikes to 4.5s
~00:00 API server handler timeouts begin
~00:00 k3s leader election failures — kube-scheduler, kube-controller-manager lose leases
~00:09 vmstorage pod reports unmounted volumes — disk pressure spreading
~00:19 zitadel-db pod stuck in ContainerCreating — scheduler affected
~00:19 Zitadel enters CrashLoopBackOff (21 restarts) — cannot connect to DB
~01:42 APISIX etcd-0 and etcd-2 restarted, lost EmptyDir data
~01:42 APISIX etcd cluster loses quorum — etcd-1 alone, cannot elect leader
~01:51 APISIX reports has no healthy etcd endpoint available
~01:51 All ApisixRoute and ApisixTLS sync fails — 503 on all domains
~02:10 All 3 APISIX etcd pods deleted simultaneously — fresh cluster bootstrap
~02:12 APISIX etcd cluster healthy (3/3 members)
~02:12 APISIX and ingress-controller restarted
~02:15 SSL certs re-synced (16 total)
~02:22 All ApisixRoutes force-annotated for re-sync
~02:25 All 15 routes synced — services restored

Technical Details

Problem 1: etcd Lost Quorum

Symptom:

{"level":"fatal","msg":"discovery failed",
"error":"member e2571e968b89c849 has already been bootstrapped"}

APISIX etcd-0 and etcd-2 use EmptyDir storage — data is lost on every pod restart. When they restarted due to the overloaded node, they tried to re-bootstrap as new members but conflicted with etcd-1's existing cluster state. etcd-1 was left alone and could not elect a leader (needs 2/3 votes):

47324e080c98137d is starting a new election at term 194
waiting for ReadIndex response took too long, retrying

Fix — Cloud cluster (ingress-apisix namespace):

kubectl scale deployment apisix -n ingress-apisix --replicas=0
kubectl scale deployment apisix-ingress-controller -n ingress-apisix --replicas=0
kubectl delete pod apisix-etcd-0 apisix-etcd-1 apisix-etcd-2 -n ingress-apisix
# Wait for all 3 to show Running
kubectl get pods -n ingress-apisix -w
kubectl scale deployment apisix -n ingress-apisix --replicas=1
kubectl scale deployment apisix-ingress-controller -n ingress-apisix --replicas=1

Fix — Local cluster (apisix namespace):

kubectl scale deployment apisix -n apisix --replicas=0
kubectl scale deployment apisix-ingress-controller -n apisix --replicas=0
kubectl delete pod etcd-0 etcd-1 etcd-2 -n apisix
# Wait for all 3 to show Running
kubectl get pods -n apisix -w
kubectl scale deployment apisix -n apisix --replicas=1
kubectl scale deployment apisix-ingress-controller -n apisix --replicas=1


Problem 2: APISIX Routes Not Syncing

Symptom:

ApisixIngress synced failed:
{"error_msg":"has no healthy etcd endpoint available"}
Status: ResourceSyncAborted

Even after etcd recovered, APISIX had a stale connection to the old broken etcd.

Fix — Cloud cluster:

kubectl rollout restart deployment/apisix -n ingress-apisix
kubectl rollout restart deployment/apisix-ingress-controller -n ingress-apisix

# Force re-sync all routes
for route in argocd-routes gitlab-routes planka-routes zitadel-cloud-routes; do
  kubectl annotate apisixroute $route -n default reconcile="$(date)" --overwrite
done

for route in otw-nginx-route ticketadmin-routes ticketcms-routes webos-routes; do
  kubectl annotate apisixroute $route -n dev reconcile="$(date)" --overwrite
done

kubectl annotate apisixroute headscale-routes -n headscale reconcile="$(date)" --overwrite
kubectl annotate apisixroute grafana-routes -n monitoring reconcile="$(date)" --overwrite
kubectl annotate apisixroute nexus-docker nexus-ui -n nexus reconcile="$(date)" --overwrite
kubectl annotate apisixroute shaka-route -n shaka reconcile="$(date)" --overwrite

Fix — Local cluster:

kubectl rollout restart deployment/apisix -n apisix
kubectl rollout restart deployment/apisix-ingress-controller -n apisix

# Force re-sync all routes
kubectl annotate apisixroute nexus-docker nexus-internal -n nexus reconcile="$(date)" --overwrite
kubectl annotate apisixroute shaka-backend-route shaka-frontend-route -n shaka reconcile="$(date)" --overwrite


Problem 3: SSL Certificates Not Loading

Symptom: Safari can't establish a secure connection

Cause: Same APISIX etcd issue — ApisixTLS resources could not sync:

Message: unexpected status code 503;
{"error_msg":"has no healthy etcd endpoint available"}

Resolution: Automatically resolved after etcd and ingress-controller recovery on both clusters. All 16 SSL certs re-synced automatically from existing ApisixTLS Kubernetes CRD resources.


Problem 4: Disk Full — GitLab Registry Blobs

Discovery: Root disk at 81% (251GB/310GB used):

/dev/vda1   310G  251G  60G  81%  /

Cause: 65GB of unreferenced Docker image layer blobs accumulating in GitLab container registry with no cleanup policy:

/data/gitlab/data2/gitlab-rails/shared/registry/docker/registry/v2/
  ├── blobs/         65GB  ← orphaned image layers
  └── repositories/  113MB

Fix 1 — Run garbage collection (done):

kubectl exec -it <gitlab-pod> -- gitlab-ctl registry-garbage-collect -m

Fix 2 — Set automatic cleanup policy via GitLab Rails console (done):

kubectl exec -it <gitlab-pod> -- gitlab-rails console
Then paste:
Project.find_each do |p|
  p.container_expiration_policy.update!(
    enabled: true,
    cadence: '7d',
    older_than: '90d',
    keep_n: 10
  )
end

Fix 3 — Enable in GitLab Admin UI (done): Admin → Settings → Packages and registries → Container registry - Enable cleanup policies for projects created earlier than GitLab 12.7 - Cleanup policy maximum processing time: 3600 - Cleanup policy maximum workers: 2 - Maximum number of tags to be deleted: 0 - Enable cleanup policy caching


Verify Recovery

Cloud Cluster

# Check all pods healthy
kubectl get pods -n ingress-apisix
kubectl get pods

# Check etcd cluster (all 3 Running)
kubectl get pods -n ingress-apisix | grep etcd

# Get admin service IP
kubectl get svc -n ingress-apisix | grep admin

# Check all routes synced
curl -s http://<admin-cluster-ip>:9180/apisix/admin/routes \
  -H "X-API-KEY: <APISIX_ADMIN_KEY>" | \
  python3 -c "import sys,json; [print(i['value'].get('hosts','?')) for i in json.load(sys.stdin)['list']]"

# Test key domains
curl -I https://mashup.castis.io
curl -I https://iam.castis.io
curl -I https://argo.castis.io

# Check disk usage
df -h /

Local Cluster (NUC)

# Check all pods healthy
kubectl get pods -n apisix

# Check etcd cluster (all 3 Running)
kubectl get pods -n apisix | grep etcd

# Get admin service IP
kubectl get svc -n apisix | grep admin

# Check all routes synced
curl -s http://<admin-cluster-ip>:9180/apisix/admin/routes \
  -H "X-API-KEY: <APISIX_ADMIN_KEY>" | \
  python3 -c "import sys,json; [print(i['value'].get('host','?')) for i in json.load(sys.stdin)['list']]"

# Test key domains
curl -I https://shaka.castis.io
curl -I https://nexus.castis.io

Architecture Issues Identified

Issue 1: etcd Uses EmptyDir (No Persistence) — Both Clusters

All APISIX etcd pods on both clusters use EmptyDir — data is lost on every pod restart. The clusters only recover because all routes are defined as Kubernetes CRD resources (ApisixRoute, ApisixTLS) that the ingress controller re-syncs automatically. Without those CRDs, all config would be permanently lost on restart.

Recommended Fix — Cloud cluster:

helm upgrade apisix apisix/apisix -n ingress-apisix \
  --reuse-values \
  --set etcd.persistence.enabled=true \
  --set etcd.persistence.storageClass=longhorn \
  --set etcd.persistence.size=8Gi

Recommended Fix — Local cluster:

helm upgrade apisix apisix/apisix -n apisix \
  --reuse-values \
  --set etcd.persistence.enabled=true \
  --set etcd.persistence.storageClass=longhorn \
  --set etcd.persistence.size=8Gi

Issue 2: k3s etcd and APISIX etcd Share the Same Disk

Both etcd instances run on the same physical disk. When disk performance degrades, both are affected simultaneously causing compound failures that are harder to diagnose.

Recommended Fix: Move APISIX etcd to Longhorn (separate storage pool) so disk pressure on the root volume does not affect APISIX routing.

Issue 3: No GitLab Registry Cleanup Policy

Docker image blobs accumulated for ~1 year with no expiry, growing to 65GB and causing the disk pressure that triggered the entire incident.

Fix applied: Cleanup policy now set on all projects — runs every 7 days, keeps last 10 tags, deletes tags older than 90 days.

Issue 4: NFS as Single Point of Failure

Legacy services (gitlab, planka, zitadel) use NFS-backed PVs on the cloud cluster. An NFS server issue takes all of them down simultaneously.

Recommended Fix: Migrate to Longhorn (already running in cluster):

storageClassName: longhorn  # instead of standard (NFS)


Prevention Checklist

Action Cluster Status Priority
Run GitLab registry garbage collection Cloud Done Critical
Set GitLab container registry cleanup policy (7d / 90d / keep 10) Cloud Done Critical
Add disk usage alert at >75% Cloud Pending Critical
Add etcd latency alert >500ms Both Pending High
Add etcd quorum loss alert Both Pending High
Migrate APISIX etcd to Longhorn persistent storage Both Pending High
Migrate NFS PVCs to Longhorn Cloud Pending Medium
Add readinessProbe to zitadel-db Cloud Pending Medium

Disk Space Breakdown (at time of incident)

Path Size Notes
/data/gitlab/data2/gitlab-rails/shared/registry/docker/registry/v2/blobs 65GB Orphaned Docker blobs — cleaned by GC
/data/gitlab/data2/git-data 7.2GB Git repositories
/data/gitlab/data2/prometheus 1.7GB Metrics data
/data/gitlab/data2/postgresql 465MB Database
/data/gitlab/data2/gitlab-rails/shared/artifacts 116MB CI artifacts


Incident documented by: castis devops
Last updated: 2026-05-14