etcd and the API Server — The Write Path, Raft, and Why 3 vs 5 Members Matters
How a Kubernetes write travels from kubectl through the API server into etcd and back out as watch events, how Raft quorum decides availability and write latency, and how to run, size, repair and restore etcd without losing the cluster.
Overview
Every Kubernetes object lives in etcd. The API server is the only component that should talk to it, and every create, update and delete becomes an etcd transaction that a majority of etcd members must write to disk before the API server answers. When etcd is slow, every write in the cluster is slow. When etcd loses quorum, the cluster cannot change state: the Kubernetes docs say that pods already scheduled may keep running, but no new pods can be scheduled.
Most etcd outages are not exotic. The etcd FAQ names the usual causes: a slow or shared disk that delays the write-ahead log fsync, CPU starvation, a congested network between members, a keyspace that was never compacted, and membership changes done in the wrong order. Restores done while API servers are still running, or without handling the revision going backwards, break the controllers that cache cluster state.
The path a write takes
A write travels through a short chain of components, and each one can reject or slow it. The figure shows the chain and the three places where it most often goes wrong.
Key concepts
- Quorum
- Failure tolerance
- Raft commit
- Revision
- resourceVersion
- Compaction
- Defragmentation
- NOSPACE alarm
- Learner
- Watch cache
Interview questions
- Explain what happens in etcd when the kubernetes API server writes an object, and why etcd cluster size (3 vs 5 nodes) matters for both availability and write latency.
- A user gets 409 Conflict with "the object has been modified". Is etcd broken?
- Why do etcd clusters use odd member counts, and why not run 7 or 9 members for safety?
- etcd keeps changing leaders and API writes are slow. How do you troubleshoot it?
- Writes fail with "mvcc: database space exceeded". Walk through the recovery.
- How do you replace a failed etcd member in a 3-member cluster, and why does the order matter?
- How do you back up and restore etcd for a Kubernetes cluster, and what breaks if you do it wrong?
- Should you spread etcd members across availability zones or regions?
- What is an etcd learner and when would you use one?
- How does the API server avoid sending every read and watch to etcd, and what does 410 Gone mean?
Sign up free to read the full topic
More DevOps topics
- DORA Four Keys — Implementation
- DORA Metrics
- DORA Metrics — Definitions, the Math, and How to Measure Them
- eBPF Observability
- eBPF Programming
- Ephemeral and Preview Environments
- Event-Driven Architecture
- Event-Driven Automation and StackStorm
- External Secrets Operator
- Feature Flags
- FinOps & Cloud Cost Engineering
- Firecracker microVMs
Start free on Cariara · Coding problems · System design studio