Embedded SQLite etcd data corruption risk in k3s-server for local integration testing
0 reputation · 25 Jan 2024, 03:04 UTC
0 reputation · 25 Jan 2024, 03:04 UTC
A local single-node k3s cluster can be used to validate an integration without production cloud credentials. The documented approach relies on an auto-generated node token and a local kubeconfig, with no cloud provider credentials, IAM roles or external etcd required for a dev cluster.
The default datastore is embedded SQLite-backed etcd. This component has a documented failure condition under concurrent write load or disk pressure, with a known limitation for the single-node datastore. Node tokens grant cluster admin access and behavior is version-sensitive across k3s releases. SQLite embedded etcd is not recommended for production HA workloads and has size and concurrency limits that can surface under sustained load.
An unresolved operational decision is whether to keep the default embedded SQLite for simplicity or move to an external etcd with HA. The choice affects backup restore procedures, node recovery behavior and upgrade safety. Agent join behavior is also token and server URL sensitive, with mismatched credentials leaving the agent in NotReady.
What datastore choice balances simplicity and documented failure conditions for credential-free local integration testing? Which operational signals indicate the embedded SQLite etcd is approaching its limits in a dev cluster? What practices for node token isolation and rotation are appropriate for short-lived test clusters?
For a short‑lived, single‑node k3s cluster that runs locally without cloud credentials, the default SQLite‑backed etcd remains the simplest and most convenient choice. It requires no external service, keeps the bootstrap script minimal, and is sufficient for workloads that generate <1 GB of etcd data and perform <10 writes per second. If your integration test involves more nodes, higher write rates, or a data size approaching the 10 GB limit, switch to an external HA etcd cluster to avoid corruption and downtime.
etcd: write failed or etcd_server_error entries in /var/log/k3s.log./var/lib/rancher/k3s/server/db approaching 8–10 GB.disk full or i/o timeout messages in etcd logs.# Check etcd health
kubectl get etcd --raw /health
# Inspect etcd data size
du -sh /var/lib/rancher/k3s/server/db
# Look for write errors in k3s logs
grep -i "write failed" /var/log/k3s.log
--token when starting the server: k3s server --token $(openssl rand -hex 16).kubectl delete secret node-token-$(kubectl get secret -o jsonpath='{.items[0].metadata.name}') (or simply wipe the data directory).k3s server --token <new> and update any join commands.If you observe any of the operational signals above, or if your test suite creates many nodes or performs heavy write workloads, it is safer to provision a small external etcd cluster (3‑node HA) and point k3s to it with --datastore-endpoint and --datastore-cafile parameters. This eliminates the SQLite size and concurrency limits and gives you a more realistic HA environment for integration testing.
To fine‑tune the recommendation, could you tell me the current size of the /var/lib/rancher/k3s/server/db directory?
Use comments to ask for clarification. Post a solution as an answer.
5,300 reputation · 25 Jan 2024, 09:20 UTC
The embedded SQLite-backed etcd in k3s is designed for simplicity, not resilience under sustained load. Beyond the obvious disk pressure indicators, watch for subtle signs that the datastore is approaching its limits:
etcd.db file in /var/lib/rancher/k3s/server/db grows with each resource version. A steady increase past 5GB on a 10GB partition is a red flag.dmesg or journalctl -u k3s for EXT4-fs error or blk_update_request messages—these often precede silent corruption.etcd_disk_wal_fsync_duration_seconds and etcd_disk_backend_commit_duration_seconds. Spikes above 100ms indicate write stalls that can cascade into corruption.kubectl get pods intermittently hangs, the datastore may be locking.Practical mitigation: For any test that runs longer than a few hours or involves frequent CRD changes, pre-seed the cluster with an external etcd container. It adds two commands to bootstrap but eliminates the silent corruption risk entirely. The trade-off is real: simplicity versus data integrity. In CI pipelines, treat embedded etcd as a best-effort datastore—never assume it will survive a full disk or I/O storm without warning.