etcd on dedicated servers

etcd is the consistent key-value store behind Kubernetes and many coordination systems. Its speed depends almost entirely on disk sync latency and network round trips, so quiet NVMe drives matter more than size.

What is etcd used for?

Storing small, critical data that every node must agree on: Kubernetes cluster state, service discovery, leader election, distributed locks and configuration for systems such as Patroni-managed PostgreSQL clusters. It replicates with Raft, so every write is confirmed by a majority of members before it succeeds.

How many members should a cluster have?

Three or five. Three tolerate one failure, five tolerate two. Even numbers add no tolerance, and more than five slows writes because each needs more acknowledgements. Place members in one data centre for the lowest latency, or in three nearby data centres such as Gravelines, Roubaix and Strasbourg if surviving the loss of a site matters more than a few milliseconds per write.

How do I start a member?

etcd --name etcd-1 --data-dir /var/lib/etcd \
  --listen-peer-urls https://10.80.0.1:2380 --initial-advertise-peer-urls https://10.80.0.1:2380 \
  --listen-client-urls https://10.80.0.1:2379,https://127.0.0.1:2379 --advertise-client-urls https://10.80.0.1:2379 \
  --initial-cluster etcd-1=https://10.80.0.1:2380,etcd-2=https://10.80.0.2:2380,etcd-3=https://10.80.0.3:2380 \
  --initial-cluster-state new --initial-cluster-token prod-etcd \
  --cert-file /etc/etcd/pki/server.crt --key-file /etc/etcd/pki/server.key --trusted-ca-file /etc/etcd/pki/ca.crt --client-cert-auth \
  --peer-cert-file /etc/etcd/pki/peer.crt --peer-key-file /etc/etcd/pki/peer.key --peer-trusted-ca-file /etc/etcd/pki/ca.crt --peer-client-cert-auth

Port 2379 serves clients and 2380 carries peer traffic. Use TLS with client certificate checks on both, because servers here talk over public ports; a WireGuard tunnel adds a second layer.

Why is fsync latency so important?

Every write is appended to the write-ahead log and synced to disk on a majority of members before it is acknowledged. A slow sync slows every write and, at worst, causes missed heartbeats and leader elections. Watch the etcd_disk_wal_fsync_duration_seconds metric: the 99th percentile should stay under about 10 ms. NVMe drives on our machines sync in well under a millisecond, and a dedicated machine means no neighbour floods the drive at the wrong moment. Test before going live:

fio --rw=write --ioengine=sync --fdatasync=1 --directory=/var/lib/etcd-test --size=22m --bs=2300 --name=etcd-fsync

How do quota, compaction and defragmentation work?

etcd keeps a history of every key revision until it is compacted. The backend has a size quota, 2 GB by default and commonly raised up to 8 GB with --quota-backend-bytes; when it is reached, etcd accepts only reads and deletes until space is freed. Enable automatic compaction, for example --auto-compaction-retention=1h, and defragment members one at a time to return the freed space to the file system.

etcdctl --endpoints=https://10.80.0.2:2379 defrag
etcdctl endpoint status --cluster -w table

How do I back it up?

Take snapshots with etcdctl snapshot save from one member on a schedule, check them with etcdutl snapshot status, and copy them to another machine. A snapshot restores a whole cluster with etcdutl snapshot restore on each new member. For Kubernetes, this snapshot is the most important backup in the cluster.

ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert /etc/etcd/pki/ca.crt --cert /etc/etcd/pki/backup.crt --key /etc/etcd/pki/backup.key snapshot save /var/backups/etcd-$(date +%F-%H).db

What about cross-site latency?

The defaults, a 100 ms heartbeat and a 1 second election timeout, suit members within one region. If round trips between members exceed about 10 ms, raise the heartbeat to roughly the round-trip time and the election timeout to ten times that. Measure with ping between members over the tunnel before deciding.

Which machine fits?

etcd needs little CPU and memory: a few cores and 8 GB cover a large Kubernetes cluster. What it needs is a quiet, fast drive and a stable network. Small machines with NVMe are ideal.

UseMachine
Dedicated etcd members, three or fiveESSENTIAL-1 or ESSENTIAL-2
etcd alongside control-plane servicesESSENTIAL-S
Busy clusters with many watchersBUSINESS-1 2024

ESSENTIAL-2 costs $43.20 a month with two NVMe drives in software RAID 1. Our PostgreSQL servers page shows etcd in a failover setup.

Machines for etcd members

Lowest monthly price of each model across its data centres; the model page shows the price in every location.

ModelProcessorCoresMemoryDrivesPortPer month
ESSENTIAL-1Intel Xeon-E 2386G632 GB2x 512 GB SSD NVMe1 Gbps unmetered$38.40
ESSENTIAL-2Intel Xeon-E 2388G832 GB2x 512 GB SSD NVMe1 Gbps unmetered$43.20
ESSENTIAL-SAMD Ryzen 7 9700X864 GB2x 512 GB SSD NVMe1 Gbps unmetered$46.20
ESSENTIAL-3AMD Ryzen 9 5900X1232 GB2x 512 GB SSD NVMe1 Gbps unmetered$61.20
BUSINESS-1 2024AMD EPYC 4244P632 GB2x 960 GB SSD NVMe3 Gbps unmetered$81.60
BUSINESS-1 2026AMD EPYC 4245P632 GB2x 960 GB SSD NVMe3 Gbps unmetered$113.40

Small NVMe machines make ideal etcd members; run three or five of them.

See all servers and prices

Related pages

PostgreSQL servers

Run PostgreSQL on dedicated hardware: current versions from the project repository, memory settings, NVMe planner costs, replicas, pgBackRest and failover.

Read more

Database servers

NVMe machines with large memory for PostgreSQL, MySQL, MariaDB and MongoDB, from a single primary to replicated pairs.

Read more

NVMe vs SATA SSD vs HDD

Throughput, latency and cost per terabyte of the three drive types in our machines, and which job suits each.

Read more

Choosing a data centre location

Latency, traffic rules, data residency and price: how to pick one of our twelve data centres for the people you serve.

Read more

Questions and answers

How many etcd members should I run?

Three or five. Three survive one failure and five survive two; even numbers add no extra tolerance.

Which ports does etcd use?

2379 for clients and 2380 for peer traffic between members. Protect both with TLS and client certificates.

Why does etcd need fast disks?

Every write is synced to the write-ahead log on a majority of members, so fsync latency sets write latency and cluster stability.

What happens when the etcd quota is reached?

etcd accepts only reads and deletes until space is freed by compaction and defragmentation, or the quota is raised.

How do I back up etcd?

Run etcdctl snapshot save on a schedule, verify the file, and copy it to another machine for restores with etcdutl.