k3OS: Using SQLite as the Single‑File State Store for Edge Clusters
Edge clusters need a lightweight, single‑file state store; k3s uses SQLite to meet that need with minimal overhead and simple backup.
28 Oct 2025, 18:47 UTC

Problem and Takeaway
Edge clusters often run on devices with limited memory, CPU, and storage. Traditional etcd imposes a multi‑process, network‑based design that adds overhead. The practical need is a lightweight, single‑file state store that can be placed on read‑only media and still support upgrades.
Requirements
- Minimal memory and CPU footprint.
- Single file that can reside on immutable media.
- Automatic schema migration during k3s upgrades.
- Simple backup and restore.
Smallest Suitable Design
k3s replaces etcd with SQLite. The entire cluster state lives in one file (k3s.db). This design satisfies the above requirements:
- The database file is a regular file on disk, eliminating the need for a separate etcd process.
- SQLite can be mounted read‑only; a small overlay (e.g., tmpfs) holds the write‑able portion, enabling air‑gapped installs.
- k3s automatically runs schema migrations when the binary version changes, preserving compatibility from v1.21 to v1.27.
Trust and Data Boundaries
The SQLite file is the single source of truth for cluster state. All API server operations read and write to this file. Because the file is the only mutable component, its integrity directly affects cluster health.
Operational Checks
- Verify the k3s binary includes SQLite. Run on the control node:
k3s version
and confirm the '--server' flag contains '--sqlite' or check /etc/rancher/k3s/k3s.yaml forcluster-registry: sqlite. - Inspect the data directory. On the control node (requires root):
ls -l /var/lib/rancher/k3s/server/db/k3s.db
Verify size and timestamp after a fresh start. - Check API responsiveness. Execute a harmless request:
curl -s http://127.0.0.1:6443/v1/nodes | jq .
Response time should be sub‑second on a typical edge device.
Failure Modes and Design‑Changing Conditions
- File growth. As etcd data accumulates, k3s.db can become large. Periodic
VACUUMcompaction is recommended on long‑running clusters. - Write serialization. SQLite serializes concurrent writes. Very high‑write workloads (e.g., many node joins/leaves) may cause API latency.
- Corruption. If the file becomes corrupted, the entire cluster must be restored from a backup; there is no incremental recovery.
- Cluster size. For clusters exceeding ~200 nodes, API response times may degrade noticeably. In such cases, consider a hybrid approach (SQLite for control plane, external DB for workload state) or increase node count to distribute load.
Concrete Example: Backup and Restore
Backup is as simple as copying the SQLite file. The following commands assume root access on the control node:
# Create a timestamped backup (requires permission to read the db file)BACKUP_DIR=/backup/k3s
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
cp /var/lib/rancher/k3s/server/db/k3s.db ${BACKUP_DIR}/k3s_${TIMESTAMP}.db
To restore, stop the k3s service, replace the file, and start again:systemctl stop k3s
cp /backup/k3s/k3s_20261204_1715.db /var/lib/rancher/k3s/server/db/k3s.db
systemctl start k3s
After restart, re‑run the operational checks to confirm the cluster is healthy.
Practical Verification of Result
- Check the file size before and after backup/restore; it should be identical.
- Verify API response time is within expected bounds (e.g.,
curl … | jq .returns in < 500 ms). - Run
k3s statusto ensure the server reports "Active".
Conclusion
Using SQLite as the state store in k3s delivers a lightweight, single‑file solution that fits edge constraints and simplifies air‑gapped deployments. The design works well for typical edge workloads, but administrators should monitor file growth, write contention, and cluster size. Regular backups, periodic compaction, and size‑aware scaling remain the practical safeguards for production reliability.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.