Etcd Role

Difficulty: Intermediate

Question

What role does etcd play in Kubernetes, why is it so critical, and how do you keep it healthy and backed up?

Answer

etcd is the distributed key-value store that holds the entire state of a Kubernetes cluster: every Deployment, Pod, Secret, ConfigMap, lease and custom resource. Only the API server reads and writes it, and every other component works off the API server's view of etcd, so if etcd is lost without a backup, the cluster loses its memory of what should be running.

What etcd stores and how Kubernetes uses it

  • Every object lives under a key such as /registry/deployments/shop/checkout, stored as protobuf (or JSON for custom resources).
  • etcd uses MVCC: every write gets a new global revision. Kubernetes exposes this as metadata.resourceVersion, which powers optimistic concurrency (a stale update gets a 409 Conflict).
  • The watch API streams changes from a revision onward. The API server watches etcd and fans those events out to controllers, the scheduler and kubelets. This is why the whole control plane is event-driven.
  • Leader election for the scheduler and controller manager uses Lease objects, which are also stored in etcd.

Raft, quorum and why clusters have 3 or 5 members

etcd replicates data with the Raft consensus algorithm. One member is the leader; a write is committed only when a majority (quorum) has it on disk.

MembersQuorumFailures tolerated
110
321
532

Even numbers add cost without adding fault tolerance (4 members still tolerate only 1 failure), so production clusters run 3 or 5 members spread across availability zones. If quorum is lost, the API server cannot write. Already running Pods keep running, because kubelets and containers do not need etcd moment to moment, but nothing new can be scheduled, scaled or healed.

Keeping etcd healthy

  • Fast disks: etcd calls fsync on every commit, so slow disks cause leader elections and API timeouts. Use SSDs and watch the wal_fsync_duration and backend_commit_duration metrics.
  • Size limits: the default backend quota is 2 GiB (--quota-backend-bytes). If it is exceeded, etcd raises a NOSPACE alarm and rejects writes. Kubernetes compacts old revisions automatically, but you may still need periodic defragmentation to reclaim disk space.
  • Request size: a single object is limited to about 1.5 MiB by default, which is why huge ConfigMaps fail.
  • Security: etcd is protected with mutual TLS. Secrets are only base64-encoded in etcd unless you configure encryption at rest with an EncryptionConfiguration, ideally using a KMS provider. Anyone with etcd access effectively has every Secret in the cluster.

Backup and restore

On self-managed clusters (kubeadm, bare metal) you must back up etcd yourself, typically with a scheduled etcdctl snapshot save copied off the node. Restore is done with etcdutl snapshot restore into a fresh data directory (the older etcdctl snapshot restore is deprecated), then the etcd static Pod is pointed at it. On EKS, GKE and AKS, the provider runs and backs up etcd for you, but you still want application-level backups with a tool like Velero, because you cannot restore a single namespace from a provider-managed etcd.

How a write reaches etcd and becomes an event. The API server is the only etcd client; controllers learn about changes through watches.
  1. kubectl → API Server: Apply Deployment with 5 replicas
  2. API Server → etcd: Write object after validation
  3. etcd → API Server: Committed by quorum, new revision
  4. API Server → kubectl: 200 OK with resourceVersion
  5. etcd → API Server: Watch event: Deployment modified
  6. API Server → Controller: Forward watch event
  7. Controller → API Server: Update ReplicaSet to 5 replicas

Code examples

Snapshot and health checks on a kubeadm control plane

export ETCDCTL_API=3
CERTS="--cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  --endpoints=https://127.0.0.1:2379"

# Health and status (leader, DB size, raft term)
etcdctl $CERTS endpoint health
etcdctl $CERTS endpoint status --write-out=table

# Take a snapshot
etcdctl $CERTS snapshot save /backup/etcd-$(date +%F).db
etcdutl snapshot status /backup/etcd-$(date +%F).db --write-out=table

# Restore into a new data dir, then point the etcd static Pod at it
etcdutl snapshot restore /backup/etcd-2026-10-12.db \
  --data-dir /var/lib/etcd-restore

Snapshots need the etcd client certificates. After restoring, update the hostPath in /etc/kubernetes/manifests/etcd.yaml to the new data directory.

Key points

  • etcd is the only persistent store of cluster state; only the API server talks to it
  • resourceVersion and watches come directly from etcd's MVCC revisions
  • Raft needs a majority: run 3 or 5 members across zones
  • Losing quorum stops writes; running Pods continue but nothing is reconciled
  • Default 2 GiB quota and about 1.5 MiB per-request limit; Secrets need encryption at rest

Common follow-up questions

  • What happens to running Pods if the entire etcd cluster goes down?
  • Why should etcd have an odd number of members?
  • How do you encrypt Secrets at rest in etcd?
  • How would you restore a single namespace that was accidentally deleted?

Interview tips

  • Explain quorum with the 3 and 5 member table; it is a favourite follow-up
  • Point out that running workloads survive an etcd outage, but the control plane freezes
  • Mention backups and encryption at rest to show operational maturity

Concepts covered

etcd, Raft Consensus, Quorum, Watch API, Backup and Restore

More Kubernetes & Orchestration questions