Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Know it before you install
etcd uses the Raft protocol: the members elect a leader; a write is done when a majority (quorum) agrees. With 3 members, 1 may fail; with 5, 2 may fail. Always use an odd number. etcd is very sensitive to disk latency (fsync) — use SSDs.
| Item | Value |
|---|---|
| Files | etcd, etcdctl (client), etcdutl (offline tools) from github.com/etcd-io/etcd/releases |
| Config | /etc/etcd/etcd.conf.yml |
| Data | /var/lib/etcd/ |
| Ports | 2379/tcp (clients), 2380/tcp (peers) |
| Service | etcd.service (you write it) |
| In kubeadm clusters | etcd runs as a static Pod on control plane nodes (/etc/kubernetes/manifests/etcd.yaml) |
Install on RHEL and Ubuntu
On each of the 3 nodes (etcd1 10.0.3.21, etcd2 .22, etcd3 .23):
EVER=v3.6.5
curl -fsSLO https://github.com/etcd-io/etcd/releases/download/$EVER/etcd-$EVER-linux-amd64.tar.gz
tar -xzf etcd-$EVER-linux-amd64.tar.gz
install -m 0755 etcd-$EVER-linux-amd64/etcd etcd-$EVER-linux-amd64/etcdctl etcd-$EVER-linux-amd64/etcdutl /usr/local/bin/
useradd --system --no-create-home --shell /sbin/nologin etcd
mkdir -p /etc/etcd/pki /var/lib/etcd
chown etcd: /var/lib/etcd && chmod 700 /var/lib/etcd
etcd --versionCertificates
etcd holds everything (in Kubernetes: all Secrets) — always use TLS with client certificates. Make a small CA and one certificate per node (with its name and IP in the SANs), for example with openssl or cfssl:
openssl req -x509 -newkey rsa:4096 -nodes -days 3650 -subj "/CN=etcd-ca" -keyout ca.key -out ca.crt
openssl req -newkey rsa:2048 -nodes -subj "/CN=etcd1" -keyout etcd1.key -out etcd1.csr
openssl x509 -req -in etcd1.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 825 -out etcd1.crt -extfile <(printf "subjectAltName=DNS:etcd1,IP:10.0.3.21,IP:127.0.0.1\nextendedKeyUsage=serverAuth,clientAuth")Copy ca.crt, the node's .crt and .key to /etc/etcd/pki/ on that node (chown etcd:; keys 600). Keep ca.key offline.
First configuration: the cluster file
On etcd1 (change name, IPs and cert names on the other nodes):
name: etcd1
data-dir: /var/lib/etcd
listen-peer-urls: https://10.0.3.21:2380
listen-client-urls: https://10.0.3.21:2379,https://127.0.0.1:2379
initial-advertise-peer-urls: https://10.0.3.21:2380
advertise-client-urls: https://10.0.3.21:2379
initial-cluster: etcd1=https://10.0.3.21:2380,etcd2=https://10.0.3.22:2380,etcd3=https://10.0.3.23:2380
initial-cluster-state: new
initial-cluster-token: etcd-prod-1
client-transport-security:
cert-file: /etc/etcd/pki/etcd1.crt
key-file: /etc/etcd/pki/etcd1.key
trusted-ca-file: /etc/etcd/pki/ca.crt
client-cert-auth: true
peer-transport-security:
cert-file: /etc/etcd/pki/etcd1.crt
key-file: /etc/etcd/pki/etcd1.key
trusted-ca-file: /etc/etcd/pki/ca.crt
client-cert-auth: true
quota-backend-bytes: 8589934592
auto-compaction-mode: periodic
auto-compaction-retention: "1h"| Setting | Why |
|---|---|
initial-cluster (same on all) | All members know each other at the first start. |
initial-cluster-state: new | First creation. Use existing when a member joins a running cluster. |
client-cert-auth: true | Only clients with a certificate from your CA may connect. |
quota-backend-bytes (8 GiB) | The database size limit; at the limit etcd raises a NOSPACE alarm. |
auto-compaction-* | Old key versions are removed every hour, so the DB does not grow forever. |
[Unit]
Description=etcd
After=network-online.target
[Service]
User=etcd
ExecStart=/usr/local/bin/etcd --config-file /etc/etcd/etcd.conf.yml
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.targetfirewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.3.0/24" port port="2379-2380" protocol="tcp" accept'
firewall-cmd --reload
systemctl daemon-reload
systemctl enable --now etcdStart all three within a short time (the first waits for the others).
Daily use: health, backup and maintenance
Make the client settings short with environment variables:
export ETCDCTL_ENDPOINTS=https://10.0.3.21:2379,https://10.0.3.22:2379,https://10.0.3.23:2379
export ETCDCTL_CACERT=/etc/etcd/pki/ca.crt ETCDCTL_CERT=/etc/etcd/pki/etcd1.crt ETCDCTL_KEY=/etc/etcd/pki/etcd1.key
etcdctl endpoint health --cluster
etcdctl endpoint status --cluster -w table
etcdctl member list -w table
etcdctl alarm list
etcdctl put /app/config/mode "maintenance"
etcdctl get /app/config --prefixBackup (from one healthy member) and restore (offline, with etcdutl):
etcdctl --endpoints=https://127.0.0.1:2379 snapshot save /backup/etcd-$(date +%F-%H%M).db
etcdutl snapshot status /backup/etcd-2026-11-17-0200.db -w table
systemctl stop etcd
etcdutl snapshot restore /backup/etcd-2026-11-17-0200.db --name etcd1 --initial-cluster etcd1=https://10.0.3.21:2380,etcd2=https://10.0.3.22:2380,etcd3=https://10.0.3.23:2380 --initial-advertise-peer-urls https://10.0.3.21:2380 --data-dir /var/lib/etcd-restored(Restore on every member with its own --name, point data-dir to the restored folder, then start all.) Defragment one member at a time after big deletes, to give disk space back:
Real uses at work:
- The datastore of Kubernetes (stacked in kubeadm, or an external cluster like this one).
- Configuration and leader election for Patroni (PostgreSQL HA), APISIX, CoreDNS and your own services.
- Regular snapshots are your cluster disaster recovery.
Make it safe
Security checklist:
- TLS for clients and peers with
client-cert-auth: true; CA key offline. - Firewall 2379/2380 to cluster members and API servers only.
- Encrypted snapshots, stored off the nodes, with restore tests.
- Odd member count (3 or 5), on separate hosts/zones, on SSDs.
- Monitor: leader changes,
etcd_disk_wal_fsync_duration_seconds, DB size, alarms. - In Kubernetes also encrypt Secrets at rest (API server
EncryptionConfiguration) — etcd stores them in plain text otherwise.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
etcdserver: mvcc: database space exceeded / alarm NOSPACE | DB reached quota-backend-bytes. | Compact (etcdctl compact REV), defrag each member, alarm disarm; raise the quota if needed. |
Many leader changes, apply request took too long | Slow disk or overloaded node. | SSDs; check fsync latency; no other heavy I/O on the node. |
x509: certificate is valid for …, not … | The cert SANs miss the name/IP used. | New certificate with all names and IPs. |
| Cluster has no leader / requests time out | Quorum lost (2 of 3 down). | Bring members back; if impossible, restore from a snapshot. |
A rebuilt member will not join: cluster ID mismatch | Old data folder or wrong initial-cluster-state. | member remove + member add, empty data dir, start with initial-cluster-state: existing. |
context deadline exceeded from etcdctl | Wrong endpoint, firewall, or missing client certs. | Check ETCDCTL_* variables and port 2379. |
Next steps
- Quick how-to: Back up and restore etcd.
- Command page: etcdctl.
- etcd in Kubernetes: CKA — Back up etcd, Restore etcd. Practise: Lab: back up etcd, break the cluster, restore it.
- At work: etcd — the brain of Kubernetes. The cluster around it: Kubernetes with kubeadm.
1Why does an etcd cluster have 3 or 5 members, not 4?
Writes need a majority. 4 members tolerate only 1 failure, the same as 3, but cost more.
2etcd raised a NOSPACE alarm. What are the steps?
Compact, defragment every member, then etcdctl alarm disarm (and raise the quota if needed).