etcd is an open-source, distributed and strongly consistent key-value store that serves as the single source of truth for a Kubernetes cluster. Every object the Kubernetes API accepts, from Pods and Deployments to ConfigMaps and Secrets, is persisted in etcd, and every controller learns about changes by watching keys through the API server.
The name combines the Unix configuration directory /etc with d for distributed. Originally developed at CoreOS in 2013, etcd is now a graduated project of the Cloud Native Computing Foundation and uses the Raft consensus algorithm to keep replicas identical even when individual members fail.
How the store keeps replicas consistent
The store guarantees linearizable reads and writes by running the Raft protocol among an odd number of members. One member is elected leader; it accepts every write, appends it to a replicated log and commits the entry only after a majority of members, the quorum, has persisted it to disk.
If the leader stops sending heartbeats, followers start an election after a randomized election timeout, by default 1,000 milliseconds, with a heartbeat interval of 100 milliseconds. Each committed entry increments a cluster-wide revision number, which gives every key a version history that clients can read or watch from a specific point.
The table shows how cluster size determines fault tolerance.
| Members | Quorum size | Tolerated failures | Typical use |
|---|---|---|---|
| 1 | 1 | 0 | Development and testing only |
| 3 | 2 | 1 | Most production control planes |
| 5 | 3 | 2 | Large or critical clusters |
| 7 | 4 | 3 | Rare; write latency increases |
Even cluster sizes add no tolerance: four members still survive only one failure, yet need three acknowledgments per write. Odd member counts are therefore the rule.
The role of the store in a Kubernetes control plane
In Kubernetes, only the API server talks to the store directly. The scheduler, the controller manager, kubelets and kubectl all read and write cluster state through the API server, which validates requests, applies admission control and then serializes objects into keys under the /registry prefix.
The watch mechanism is what makes the reconciliation model work. Controllers open long-lived watches through the API server, receive every change with its revision, and react by moving actual state toward desired state. The API server keeps a watch cache so that thousands of clients do not each load the database.
Two topologies are common, and the choice affects resilience and hardware cost.
| Topology | Where members run | Advantage | Drawback |
|---|---|---|---|
| Stacked | On the same nodes as the API server | Fewer machines, simpler setup | Losing a node removes both roles |
| External | On dedicated hosts | Isolated failure domains and resources | More machines to operate |
| Managed service | Hidden by the provider | No operational burden | No direct access or tuning |
Managed offerings such as Amazon EKS and Google Kubernetes Engine run and back up the store for the customer, who never sees the members directly.
Key features and operational parameters
The version 3 API exposes keys in a flat binary key space over gRPC, with range queries, transactions, leases and watches. Data lives in a B+ tree database called bbolt, while the write-ahead log and periodic snapshots allow recovery after a crash.
| Parameter | Default or guidance | What it controls |
|---|---|---|
| –quota-backend-bytes | 2 GB default, 8 GB suggested maximum | Database size before alarms block writes |
| Request size limit | 1.5 MB per request | Largest single object that can be stored |
| –auto-compaction-retention | Kubernetes compacts every 5 minutes | How much revision history is kept |
| –heartbeat-interval | 100 ms | Leader liveness signal |
| –election-timeout | 1,000 ms | Delay before a new leader is chosen |
| –snapshot-count | 100,000 entries | When the log is snapshotted |
Compaction and defragmentation work together: compaction discards old revisions logically, while defragmentation returns freed space to the file system. Without both, the database grows until it hits the quota and the cluster enters a read-only alarm state.
Backup, restore and security
Because the store holds the entire cluster definition, regular snapshots are the most important disaster recovery control for self-managed Kubernetes. A snapshot taken with etcdctl snapshot save captures a consistent copy that can rebuild a new cluster.
- Encrypt traffic with mutual TLS between members and between the API server and the store.
- Enable encryption at rest for Secrets in the API server, since values are otherwise only base64 encoded.
- Restrict network access to the client port 2379 and peer port 2380.
- Test restores regularly, because an untested snapshot is not a reliable backup.
Anyone with direct access to the store can read every Secret and rewrite any object, bypassing Kubernetes RBAC entirely, so access to the members equals full cluster control.
Performance limits and common mistakes
The store is sensitive to disk and network latency because every write waits for an fsync on a quorum of members. Guidance calls for SSD storage with 99th percentile WAL fsync latency under 10 milliseconds; slower disks cause leader elections and API timeouts.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Frequent leader changes | Slow disks or overloaded hosts | Move to dedicated SSDs, isolate members |
| Database space exceeded alarm | Missing compaction or defragmentation | Compact, defragment, then disarm the alarm |
| Slow kubectl responses | Large lists of objects or events | Reduce object churn, paginate requests |
| Cluster unavailable after outage | Quorum lost | Restore from snapshot or recover members |
| Members spread across regions | High round-trip latency | Keep members within one region |
A frequent misconception is that the store can serve as a general-purpose database. It is designed for small, critical coordination data measured in gigabytes, not for application payloads or high-volume analytics.
A non-technical view
Think of a Kubernetes cluster as a large, busy workshop. Somewhere there must be one official notebook that records what should be running, where and how. That notebook is etcd.
To make sure the notebook is never lost or contradictory, several identical copies are kept on different machines. A change counts only when most copies agree, so the workshop keeps working even if one copy is destroyed.
A concrete example
A logistics company operates a self-managed Kubernetes cluster with about 300 worker nodes running its tracking services. The control plane uses three external etcd members on dedicated virtual machines in three availability zones of one region.
One morning, engineers see API requests slowing and logs reporting repeated leader elections. Metrics show WAL fsync latency of 40 milliseconds on one member, caused by a noisy neighbor sharing its storage volume. The team moves that member to a dedicated NVMe-backed volume, and fsync latency drops below 5 milliseconds.
Months later, an operator accidentally deletes a critical namespace. Because the team takes automated snapshots every 30 minutes and rehearses restores quarterly, they rebuild the control plane state on a staging cluster, extract the lost objects and reapply them in under an hour.