APISIX outage after etcd crashloop
Summary¶
A full outage of the APISIX ingress gateway occurred due to a cascading failure starting from etcd losing quorum, followed by multiple configuration and infrastructure issues that were discovered and resolved during recovery.
Timeline of Issues & Resolutions¶
Issue 1: etcd CrashLoopBackOff (Root Trigger)¶
Symptom
- apisix-etcd-0 in CrashLoopBackOff for 13+ hours (3769 restarts)
- Log: member e2571e968b89c849 has already been bootstrapped
Root Cause
- etcd data volume was configured as EmptyDir (no persistence)
- When pods restarted, they lost all data and could not rejoin the existing cluster
- etcd-1 and etcd-2 were unreachable (dial tcp <ETCD_POD_IP>:2380: connect: connection refused)
- With only etcd-0 alive, the cluster could not reach quorum (needed 2/3 votes)
Solution 1. Delete all three etcd pods to force a clean restart
2. Upgrade APISIX Helm chart with persistent storagekubectl delete statefulset apisix-etcd -n ingress-apisix --cascade=orphan
helm upgrade apisix apisix/apisix \
-n ingress-apisix \
--set etcd.persistence.enabled=true \
--set etcd.persistence.size=4Gi \
--set etcd.persistence.storageClass="longhorn-db" \
--set apisix.ssl.enabled=true \
--no-hooks \
--reuse-values
Key Lesson: etcd must always use persistent storage. EmptyDir means all data is lost on pod restart.
Issue 2: Helm Upgrade Blocked by Pre-upgrade Hooks¶
Symptom
- Multiple apisix-etcd-pre-upgrade-* pods in StartError
- Helm upgrade stuck in pending-upgrade
Root Cause - Pre-upgrade hook jobs failed silently, blocking the upgrade
Solution
helm rollback apisix -n ingress-apisix
helm upgrade apisix apisix/apisix \
--no-hooks \
--set etcd.persistence.enabled=true \
...
Issue 3: StatefulSet volumeClaimTemplates Immutability¶
Symptom
cannot patch "apisix-etcd" with kind StatefulSet: spec: Forbidden:
updates to statefulset spec for fields other than 'replicas'... are forbidden
Root Cause
- Kubernetes does not allow modifying volumeClaimTemplates on an existing StatefulSet
Solution Delete the StatefulSet without killing pods, then re-apply via Helm:
kubectl delete statefulset apisix-etcd -n ingress-apisix --cascade=orphan
helm upgrade apisix apisix/apisix --no-hooks ...
Issue 4: Longhorn PVC Stuck — "Device Apparently In Use"¶
Symptom
MountVolume.MountDevice failed: format of disk failed:
/dev/longhorn/pvc-xxx is apparently in use by the system
Root Cause - Stale Longhorn volume attachment — the device was still marked as attached from a previous failed pod
Solution 1. Force detach via Longhorn API
2. Delete pod and PVC, let StatefulSet recreate them freshkubectl delete pod apisix-etcd-0 -n ingress-apisix --force --grace-period=0
kubectl delete pvc data-apisix-etcd-0 -n ingress-apisix
Issue 5: etcd-0 "Permanently Removed from Cluster"¶
Symptom
server error: the member has been permanently removed from the cluster
data-dir used by this member must be removed
Root Cause
- etcd-0 had a fresh PVC but its WAL/data dir contained an old member ID (e2571e968b89c849) that no longer existed in the cluster
- The Bitnami etcd image stores data at /bitnami/etcd/data inside the container, which maps to /data/data/ on the PVC (not /data/ as expected)
Solution 1. Wipe the correct data path using a cleanup pod
kubectl run cleanup -n ingress-apisix --image=busybox --restart=Never \
--overrides='{"spec":{"volumes":[{"name":"data","persistentVolumeClaim":{"claimName":"data-apisix-etcd-0"}}],"containers":[{"name":"cleanup","image":"busybox","command":["sh","-c","rm -rf /data/data/* && echo done"],"volumeMounts":[{"name":"data","mountPath":"/data"}]}]}}'
kubectl exec -it apisix-etcd-1 -n ingress-apisix -- etcdctl member remove <old-id>
kubectl exec -it apisix-etcd-1 -n ingress-apisix -- etcdctl member add apisix-etcd-0 \
--peer-urls="http://apisix-etcd-0.apisix-etcd-headless.ingress-apisix.svc.cluster.local:2380"
ETCD_INITIAL_CLUSTER_STATE=existing
kubectl patch statefulset apisix-etcd -n ingress-apisix --type=json -p='[
{"op":"add","path":"/spec/template/spec/containers/0/env/-","value":{"name":"ETCD_INITIAL_CLUSTER_STATE","value":"existing"}},
{"op":"add","path":"/spec/template/spec/containers/0/env/-","value":{"name":"ETCD_INITIAL_CLUSTER","value":"apisix-etcd-0=http://apisix-etcd-0.apisix-etcd-headless.ingress-apisix.svc.cluster.local:2380,apisix-etcd-1=http://apisix-etcd-1.apisix-etcd-headless.ingress-apisix.svc.cluster.local:2380,apisix-etcd-2=http://apisix-etcd-2.apisix-etcd-headless.ingress-apisix.svc.cluster.local:2380"}}
]'
Key Lesson: The Bitnami etcd image stores data at /bitnami/etcd/data inside the container. On the PVC this maps to /data/data/, not /data/.
Issue 6: APISIX Ingress Controller 403 Forbidden¶
Symptom
Root Cause
- APISIX allow_admin config only allowed 127.0.0.1/24
- Ingress controller pod IP (<POD_IP>) was being blocked
Solution
Add the pod CIDR to allow_admin in the APISIX ConfigMap:
kubectl get configmap apisix -n ingress-apisix -o json | \
python3 -c "
import json, sys
cm = json.load(sys.stdin)
config = cm['data']['config.yaml']
config = config.replace(
'allow_admin: - <POD_CIDR> # ...\n - 127.0.0.1/24',
'allow_admin:\n - 127.0.0.1/24\n - <POD_CIDR>'
)
cm['data']['config.yaml'] = config
print(json.dumps(cm))
" | kubectl apply -f -
kubectl rollout restart deployment apisix -n ingress-apisix
Issue 7: APISIX SSL Disabled¶
Symptom
- HTTPS not working, SSL certificate errors in browser
- APISIX config had ssl: enable: false
Root Cause - SSL was explicitly disabled in the APISIX ConfigMap
Solution
Preferred — include in Helm upgrade:
helm upgrade apisix apisix/apisix \
-n ingress-apisix \
--set apisix.ssl.enabled=true \
--no-hooks \
--reuse-values
Manual fallback — patch ConfigMap directly:
kubectl get configmap apisix -n ingress-apisix -o json | \
python3 -c "
import json, sys
cm = json.load(sys.stdin)
config = cm['data']['config.yaml']
config = config.replace('ssl:\n enable: false', 'ssl:\n enable: true')
cm['data']['config.yaml'] = config
print(json.dumps(cm))
" | kubectl apply -f -
kubectl rollout restart deployment apisix -n ingress-apisix
Issue 8: Traefik Intercepting Port 443¶
Symptom
- HTTPS connections showed CN = TRAEFIK DEFAULT CERT (self-signed)
- mashup.castis.io returned connection refused
Root Cause
- Traefik was installed as a default k3s ingress controller with a LoadBalancer service bound to the external IP <DO_LB_PUBLIC_IP>
- The svclb-traefik DaemonSet was binding host ports 80/443 via iptables, intercepting all traffic before HAProxy or APISIX
Solution 1. Scale down Traefik
2. Change APISIX gateway service to LoadBalancer to claim the external IPIssue 9: HAProxy Not Forwarding HTTPS (Superseded by LoadBalancer)¶
Symptom - HAProxy config had the HTTPS frontend commented out - HTTP worked but HTTPS returned 000 - Even after fixing HAProxy, connections still returned 000 on the public IP
Root Cause
- HAProxy was pointing to 127.0.0.1:9443 which was not bound on the host
- The APISIX pod ports (9080/9443) are only accessible via pod IP, not localhost
- Pod IP changes on every restart making it unreliable as a HAProxy backend
- Ultimately, Traefik's svclb DaemonSet was intercepting port 443 before HAProxy anyway (see Issue 8)
Final Solution — LoadBalancer Service (not HAProxy)
After disabling Traefik, the cleanest solution was to change the APISIX gateway service to LoadBalancer type, which directly claims the external IP:
This bypasses HAProxy entirely. Traffic now flows:
Note: HAProxy is no longer needed for HTTPS routing. It can be kept for HTTP if needed or disabled entirely.
Final Architecture After Recovery¶
Internet
│
▼
<DO_LB_PUBLIC_IP>:80/443 (LoadBalancer External IP — assigned to apisix-gateway)
│
▼
apisix-gateway Service (type: LoadBalancer)
│
▼
APISIX Pod :9080/:9443 (HTTP redirect / SSL termination via Let's Encrypt certs)
│
▼
etcd cluster (3 nodes, persistent storage on longhorn-db PVCs)
│
▼
Upstream Services (GitLab, ArgoCD, Grafana, etc.)
Traefik is scaled to 0 replicas. HAProxy is no longer in the traffic path for HTTPS.
Verification Commands¶
# Check etcd cluster health
kubectl exec -it apisix-etcd-1 -n ingress-apisix -- \
etcdctl endpoint health --cluster
# Check all members started
kubectl exec -it apisix-etcd-1 -n ingress-apisix -- \
etcdctl member list
# Check PVCs are bound
kubectl get pvc -n ingress-apisix
# Check routes synced
kubectl exec -it apisix-etcd-0 -n ingress-apisix -- \
etcdctl get /apisix/routes --prefix --keys-only | wc -l
# Check SSL certs synced
kubectl exec -it apisix-etcd-0 -n ingress-apisix -- \
etcdctl get /apisix/ssls --prefix --keys-only
# Test HTTPS
curl -sk https://mashup.castis.io -o /dev/null -w "%{http_code}\n"
Prevention Checklist¶
| Item | Action |
|---|---|
| etcd persistence | Always use PVC with Retain policy (e.g. longhorn-db) |
| etcd backup | Enable ETCD_DISASTER_RECOVERY or periodic snapshots |
| APISIX SSL | Ensure ssl.enable: true in ConfigMap |
| Admin API access | Add pod CIDR to allow_admin |
| Ingress controller | Disable default Traefik if using APISIX |
| LoadBalancer | Use LoadBalancer service type for APISIX gateway instead of NodePort + HAProxy |
| HAProxy | Make haproxy.service enabled: systemctl enable haproxy |