etcd Explained: The Small Database Behind Kubernetes

etcd explained in plain terms means understanding the small, careful database that remembers everything a Kubernetes cluster knows. The central question is how a system that constantly creates, moves, and deletes containers can keep a single, trustworthy record of what should be running, and the answer is a distributed key-value store that agrees on every change before it is accepted.

etcd is a distributed, reliable key-value store, written in Go and first released in 2013 by CoreOS, now maintained by the Cloud Native Computing Foundation. It is the store that Kubernetes uses to hold all of its state: which pods exist, which nodes are healthy, which services are exposed, and what the cluster should look like.

The idea is simple: keep the data small, keep it consistent, and never lose it. etcd stores keys and values, watches for changes, and guarantees that every machine in the cluster agrees on the same values, which is why Kubernetes trusts it with its most important job. This article explains what etcd is, how it works, and where it is used.

Key takeaways

  • etcd is a small, distributed key-value store built for reliability.
  • Kubernetes stores all of its cluster state in etcd.
  • It uses the Raft protocol, so every change is agreed by a majority.
  • Clients can watch keys and be told instantly when they change.
  • It is designed for small, critical data, not for large datasets.

What etcd is

etcd is a key-value store, which means it holds pairs of keys and values, like a dictionary, and nothing else. A key might be /registry/pods/default/web-1, and its value is the description of that pod, in JSON. There are no tables, no queries, and no joins, only keys, values, and the ability to list all keys under a prefix.

It is distributed, which means it runs as a cluster of machines, usually three or five, that all hold the same data. The machines agree on every change using the Raft consensus protocol, which elects one leader to propose changes and requires a majority to accept them, so that the cluster keeps working even if one machine fails.

etcd is also a watch system. A client can ask to be told whenever a key changes, and etcd will send an event as soon as the change is committed, which is how Kubernetes controllers notice that something has changed and react to it within seconds. Our guide to containers explains the technology that Kubernetes orchestrates, and our guide to distributed systems explains the consensus ideas that etcd is built on.

How etcd works

A change starts with a client sending a write to the leader. The leader appends the change to its log, sends it to the other members, and waits until a majority have stored it, which is called committing. Only then does the leader apply the change and tell the client it succeeded, so a confirmed write is one that a majority of machines have safely recorded.

If the leader fails, the remaining members hold an election and choose a new one. The election takes a second or two, during which writes pause, but reads can continue, and the cluster resumes as soon as the new leader is in place. With three members, one can fail; with five, two can fail, which is why production clusters use odd numbers.

Reads are fast, because any member can serve them from its own copy of the data, though a read that must be perfectly up to date can ask the leader to confirm it first. Most Kubernetes reads are served locally, which keeps the control plane responsive even under load.

Every key in etcd has a version, and every change increases a global revision number. Clients can ask for the data as it was at a particular revision, which makes it possible to look back in time, and the store keeps old revisions until they are compacted, so that a watch that falls behind can catch up.

Leases give keys a lifetime. A client can attach a key to a lease, and if the client stops renewing it, the key is deleted automatically, which is how Kubernetes knows that a node has disappeared: its lease expires, its keys vanish, and the controllers notice and reschedule its work.

A laptop on a dark desk with its screen showing a glowing green cluster of three servers agreeing on a shared record
A laptop showing a glowing green cluster of three servers agreeing on a shared record shows how etcd works: every change agreed by a majority.

Comparing etcd with other stores

etcd is one of several distributed key-value stores, and each suits a different need. Consul adds service discovery and health checks, ZooKeeper is the older system it was modelled on, and a traditional database holds far more data, but each has its own trade-offs.

The table below sets out the main contrasts between the leading approaches.

Aspect etcd Consul ZooKeeper
Main use Cluster state, Kubernetes Service discovery, config Coordination, older systems
Consensus Raft Raft ZAB
API style gRPC and HTTP HTTP and DNS Custom client protocol
Watch Built in, fast Built in, blocking queries One-time watches
Best for Small, critical state Services finding each other Legacy coordination

The practical result is that etcd is the right choice for small, critical cluster state, Consul wins where services must discover each other, and ZooKeeper remains in older systems that were built around it.

Where etcd is used

Kubernetes is the largest use of etcd. Every object in a cluster, from pods to services to secrets, is stored as a key in etcd, and every change to the cluster passes through it, which is why etcd’s health is the health of the whole cluster.

Service discovery uses etcd to record which services are available and where they run. A service registers itself under a key, other services watch that key, and when the service moves or fails, the watchers are told immediately.

Configuration management uses etcd as a shared source of truth. Applications read their settings from etcd, and when an operator changes a value, every application watching it receives the update at once, without being restarted.

Leader election uses etcd to choose one active worker among many. Several instances compete for a lock stored in etcd, the winner does the work, and if it fails, another takes over, which is how scheduled jobs and controllers avoid running twice.

Distributed locking uses etcd to protect shared resources. A process takes a lock before updating a shared file or record, and other processes wait, which prevents two writers from corrupting data that only one should touch at a time.

Strengths and limits

The greatest strength of etcd is its consistency. Raft guarantees that every member agrees on the order of changes, and a confirmed write is one that a majority have stored, which means the data can be trusted even when machines fail.

It is also a strength that etcd is simple and focused. It does one job, storing small amounts of critical data reliably, and it does it well, with a clear API and a watch system that lets other software react to changes instantly.

The limits are real, though. etcd is not a general database: it is designed for megabytes, not terabytes, and its performance falls if it is used as a general store. It also needs fast disks and a low-latency network, since every write waits for a majority, and a slow member slows the whole cluster.

etcd checklist

  • Run three or five members, on separate machines and racks.
  • Use fast SSDs, since every write waits for disk.
  • Keep the network between members fast and reliable.
  • Back up etcd regularly, and test restoring from a backup.
  • Keep the data small, and do not use etcd as a general database.
  • Monitor leader changes, since frequent elections mean trouble.
  • Secure the API with TLS and authentication.
  • Compact old revisions, so the store does not grow forever.
  • Test losing a member, and check the cluster keeps working.

Frequently asked questions

What is etcd in simple terms?

etcd is a small, reliable key-value store that several machines run together, agreeing on every change. Kubernetes uses it to remember everything about a cluster: which pods exist, which nodes are healthy, and what should be running.

What is the difference between etcd and a database?

etcd is much simpler and much smaller. It stores keys and values, watches for changes, and guarantees agreement, but it has no tables, no queries, and no joins, and it is not meant for large datasets.

Why does Kubernetes need etcd?

Because Kubernetes needs one trustworthy record of what the cluster should look like. Every controller reads that record from etcd and acts on it, so if etcd is wrong or lost, the whole cluster is in trouble.

What is Raft?

Raft is the consensus protocol etcd uses. One member is elected leader, proposes changes, and a majority must accept each change before it is committed, which keeps every member in agreement even when some fail.

What happens if an etcd member fails?

The cluster keeps working as long as a majority remains. With three members, one can fail; the rest elect a new leader if needed, and the failed member can rejoin and catch up when it returns.

Can etcd lose data?

Not if a majority survives. A confirmed write is stored on a majority of members, so losing a minority cannot lose it. Losing a majority, or losing all copies, is the only way data is lost, which is why backups matter.

The bottom line

etcd explained in one line is this: a small, careful store where a cluster of machines agrees on every change, so that Kubernetes always knows what should be running.

It is invisible to most users, but it is the memory of every Kubernetes cluster, and its simplicity is its strength: a few keys, a strict agreement, and a promise that what is written is what every machine will see.

This article is general information about how etcd works, not advice about running a Kubernetes cluster for a particular organisation.

Latest articles

Scroll to Top