On this page

etcd Cluster — VM Setup

Three VMs: etcd-1 (10.0.0.1), etcd-2 (10.0.0.2), etcd-3 (10.0.0.3). This guide walks every step from bare OS to a production-ready etcd cluster — TLS mutual auth, systemd unit, bootstrap, member management, disaster recovery runbook, and Prometheus monitoring.

0/0 checks
Prerequisites etcd Internals

Cluster Architecture

graph TD
    classDef etcd fill:#2980b9,stroke:#1f618d,color:#fff
    classDef client fill:#27ae60,stroke:#1e8449,color:#fff
    classDef prom fill:#e67e22,stroke:#ca6f1e,color:#fff

    subgraph "VM 1 — etcd-1 (10.0.0.1)"
        E1["etcd<br/>client :2379<br/>peer   :2380<br/>metrics :2381"]:::etcd
    end
    subgraph "VM 2 — etcd-2 (10.0.0.2)"
        E2["etcd<br/>client :2379<br/>peer   :2380<br/>metrics :2381"]:::etcd
    end
    subgraph "VM 3 — etcd-3 (10.0.0.3)"
        E3["etcd<br/>client :2379<br/>peer   :2380<br/>metrics :2381"]:::etcd
    end

    APP["Application<br/>(etcd client)"]:::client
    PROM["Prometheus"]:::prom

    E1 -->|"peer gRPC :2380"| E2
    E1 -->|"peer gRPC :2380"| E3
    E2 -->|"peer gRPC :2380"| E3

    APP -->|"client gRPC :2379"| E1
    APP -->|"client gRPC :2379"| E2
    APP -->|"client gRPC :2379"| E3

    PROM -->|"scrape :2381/metrics"| E1
    PROM -->|"scrape :2381/metrics"| E2
    PROM -->|"scrape :2381/metrics"| E3

The etcd client library handles leader discovery automatically — give it all three endpoints and it finds the leader on its own. Client requests on 2379 are separate from Raft peer replication on 2380, which means you can firewall each independently.

Why does etcd use two separate ports — 2379 for clients and 2380 for peer communication — instead of multiplexing everything on one port?


1. Firewall Rules

Open these ports before bootstrapping — a firewall misconfiguration during bootstrap looks identical to a cluster bug and wastes hours.

Port Protocol From To Why
2379 TCP App servers, Prometheus All etcd nodes Client API
2380 TCP etcd members only All etcd nodes Raft peer replication
2381 TCP Prometheus All etcd nodes Native metrics endpoint
# Run on ALL etcd nodes — allow peer traffic between members
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.1" port port="2380" protocol="tcp" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.2" port port="2380" protocol="tcp" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.3" port port="2380" protocol="tcp" accept'

# Allow client and metrics from app tier / Prometheus
firewall-cmd --permanent --add-port=2379/tcp
firewall-cmd --permanent --add-port=2381/tcp

firewall-cmd --reload
firewall-cmd --list-all
</div>
<div class="tab-panel" data-tab-panel="ufw">
# Run on ALL etcd nodes
# Peer traffic — only from other etcd members
ufw allow from 10.0.0.1 to any port 2380 proto tcp
ufw allow from 10.0.0.2 to any port 2380 proto tcp
ufw allow from 10.0.0.3 to any port 2380 proto tcp

# Client and metrics — from app subnet and Prometheus
ufw allow 2379/tcp
ufw allow 2381/tcp

ufw status numbered
</div>
<div class="tab-panel" data-tab-panel="iptables">
# Peer: allow from each etcd member (run on all nodes)
iptables -A INPUT -p tcp -s 10.0.0.1 --dport 2380 -j ACCEPT
iptables -A INPUT -p tcp -s 10.0.0.2 --dport 2380 -j ACCEPT
iptables -A INPUT -p tcp -s 10.0.0.3 --dport 2380 -j ACCEPT

# Client and metrics
iptables -A INPUT -p tcp --dport 2379 -j ACCEPT
iptables -A INPUT -p tcp --dport 2381 -j ACCEPT

# Persist (Debian/Ubuntu)
iptables-save > /etc/iptables/rules.v4
</div>

Connectivity check — before you continue

# From etcd-1 — must succeed before any etcd config
nc -zv 10.0.0.2 2380   # Expected: Connection to 10.0.0.2 2380 port [tcp] succeeded!
nc -zv 10.0.0.3 2380
nc -zv 10.0.0.2 2379
nc -zv 10.0.0.3 2379

From etcd-1, `nc -zv 10.0.0.2 2380` hangs indefinitely with no output. A colleague says the firewall rule is in place. What else could cause this?


2. Directory & File Layout

# Create a system user with no login shell (runs etcd process)
useradd -r -s /sbin/nologin -d /var/lib/etcd etcd

# Data dir — holds the bbolt DB and WAL; must be on fast local storage (NVMe/SSD)
mkdir -p /var/lib/etcd

# Config and TLS dirs
mkdir -p /etc/etcd/tls

# Ownership: etcd process needs read/write on both
chown -R etcd:etcd /var/lib/etcd /etc/etcd

# Strict permissions: no other user should read the data dir
chmod 700 /var/lib/etcd
chmod 700 /etc/etcd/tls

Ulimits — etcd opens many file descriptors for peer connections and watch streams. Add to /etc/security/limits.conf:

etcd  soft  nofile  65536
etcd  hard  nofile  65536

Or set LimitNOFILE=65536 in the systemd [Service] block (shown in §4).


3. TLS — CA and Cert Generation

etcd requires mutual TLS on both peer and client channels for a production cluster. Generate all certs on one workstation, distribute to each node. Never copy the CA private key to the etcd nodes — only the CA cert is needed there for verification.

# ─── CA (run once, on your workstation) ──────────────────────────────────────
openssl genrsa -out ca.key 4096
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt \
  -subj "/CN=etcd-ca"

Peer cert — one per member. Peer certs must include the member's hostname AND IP in the SAN because other members may connect using either. Create peer-etcd-1.cnf:

[req]
req_extensions     = v3_req
distinguished_name = req_distinguished_name
[req_distinguished_name]
[v3_req]
keyUsage         = keyEncipherment,dataEncipherment
extendedKeyUsage = serverAuth,clientAuth
subjectAltName   = @alt_names
[alt_names]
DNS.1 = etcd-1                 # hostname
IP.1  = 10.0.0.1               # IP (must match ETCD_LISTEN_PEER_URLS)
IP.2  = 127.0.0.1              # loopback — used by local health checks
# Generate peer cert for etcd-1 (repeat with etcd-2.cnf / etcd-3.cnf for other members)
openssl genrsa -out peer-etcd-1.key 4096
openssl req -new -key peer-etcd-1.key -out peer-etcd-1.csr \
  -subj "/CN=etcd-1" \
  -config peer-etcd-1.cnf
openssl x509 -req -in peer-etcd-1.csr -CA ca.crt -CAkey ca.key \
  -CAcreateserial -out peer-etcd-1.crt -days 825 \
  -extensions v3_req -extfile peer-etcd-1.cnf

Client cert — used by etcdctl, Prometheus, and the K8s API server:

openssl genrsa -out client.key 4096
openssl req -new -key client.key -out client.csr -subj "/CN=etcd-client"
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key \
  -CAcreateserial -out client.crt -days 825

Distribute to each node:

# Copy to etcd-1 (adapt paths for etcd-2, etcd-3 — use their respective peer certs)
scp ca.crt peer-etcd-1.crt peer-etcd-1.key root@10.0.0.1:/etc/etcd/tls/
scp ca.crt peer-etcd-2.crt peer-etcd-2.key root@10.0.0.2:/etc/etcd/tls/
scp ca.crt peer-etcd-3.crt peer-etcd-3.key root@10.0.0.3:/etc/etcd/tls/

# Fix permissions on each node (private key must not be world-readable)
chmod 400 /etc/etcd/tls/*.key
chown -R etcd:etcd /etc/etcd/tls/

Set env vars so etcdctl uses TLS without repeating flags every command:

export ETCDCTL_API=3
export ETCDCTL_CACERT=/etc/etcd/tls/ca.crt
export ETCDCTL_CERT=/etc/etcd/tls/client.crt
export ETCDCTL_KEY=/etc/etcd/tls/client.key
export ETCDCTL_ENDPOINTS=https://10.0.0.1:2379,https://10.0.0.2:2379,https://10.0.0.3:2379

Add these to /etc/profile.d/etcdctl.sh on all nodes for persistence.

The peer cert only has the IP address in its SAN, not the hostname. A cluster member tries to connect using the hostname `etcd-2` instead of `10.0.0.2`. What happens?


4. etcd.service — Annotated Config

Use an EnvironmentFile for clarity. Repeat steps on each node, changing only the node-specific values.

/etc/etcd/etcd.env (etcd-1 example — change ETCD_NAME and IP references per node):

# Node identity — must be unique in the cluster
ETCD_NAME=etcd-1

# Data directory — WAL and bbolt DB land here; must be fast local storage
ETCD_DATA_DIR=/var/lib/etcd

# ── Listening ────────────────────────────────────────────────────────────────
# Peer: only accept peer connections from other etcd members
ETCD_LISTEN_PEER_URLS=https://10.0.0.1:2380

# Client: accept client gRPC from network + local loopback (for etcdctl on this node)
ETCD_LISTEN_CLIENT_URLS=https://10.0.0.1:2379,https://127.0.0.1:2379

# Metrics: separate port, no TLS required (Prometheus scrapes this)
ETCD_LISTEN_METRICS_URLS=http://10.0.0.1:2381

# ── Advertising ──────────────────────────────────────────────────────────────
# What other members announce to clients — must be reachable from app servers
ETCD_ADVERTISE_CLIENT_URLS=https://10.0.0.1:2379

# What this member announces to other members for peer traffic
ETCD_INITIAL_ADVERTISE_PEER_URLS=https://10.0.0.1:2380

# ── Bootstrap (used only on first start of a new cluster) ────────────────────
# All members listed — must match exactly on all three nodes
ETCD_INITIAL_CLUSTER=etcd-1=https://10.0.0.1:2380,etcd-2=https://10.0.0.2:2380,etcd-3=https://10.0.0.3:2380

# Unique per cluster — prevents two separate clusters merging accidentally
ETCD_INITIAL_CLUSTER_TOKEN=etcd-prod-cluster-1

# 'new' for first boot; change to 'existing' when joining a running cluster
ETCD_INITIAL_CLUSTER_STATE=new

# ── TLS — peer (member-to-member) ────────────────────────────────────────────
ETCD_PEER_CERT_FILE=/etc/etcd/tls/peer-etcd-1.crt
ETCD_PEER_KEY_FILE=/etc/etcd/tls/peer-etcd-1.key
ETCD_PEER_TRUSTED_CA_FILE=/etc/etcd/tls/ca.crt
ETCD_PEER_CLIENT_CERT_AUTH=true         # require peers to present a valid client cert

# ── TLS — client (apps to etcd) ──────────────────────────────────────────────
ETCD_CERT_FILE=/etc/etcd/tls/peer-etcd-1.crt   # server cert shown to clients
ETCD_KEY_FILE=/etc/etcd/tls/peer-etcd-1.key
ETCD_TRUSTED_CA_FILE=/etc/etcd/tls/ca.crt
ETCD_CLIENT_CERT_AUTH=true              # require clients to present a valid cert

# ── Compaction ───────────────────────────────────────────────────────────────
ETCD_AUTO_COMPACTION_MODE=periodic      # preferred for K8s; 'revision' also available
ETCD_AUTO_COMPACTION_RETENTION=1h      # keep 1h of revision history; older versions deleted

# ── Storage quota ────────────────────────────────────────────────────────────
ETCD_QUOTA_BACKEND_BYTES=8589934592    # 8 GB hard cap; alert at 80% (~6.4 GB)

# ── Metrics ──────────────────────────────────────────────────────────────────
ETCD_METRICS=extensive                 # expose per-grpc-method + histogram metrics on :2381

/etc/systemd/system/etcd.service:

[Unit]
Description=etcd key-value store
Documentation=https://etcd.io/docs/
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
User=etcd
EnvironmentFile=/etc/etcd/etcd.env
ExecStart=/usr/local/bin/etcd
Restart=on-failure
RestartSec=5s

# File descriptor limit — etcd opens many connections for watches and peers
LimitNOFILE=65536

# Prevent OOM kill; etcd must not be killed under memory pressure
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable etcd

Bootstrap sequence:

1. Start etcd-1. It starts listening and tries to find peers. Since ETCD_INITIAL_CLUSTER lists all three members, it waits for a majority before electing a leader. No writes can land yet.
2. Start etcd-2. Two of three members are now reachable — quorum is met. An election fires and one of the two becomes leader. The cluster is now operational (2/3 healthy = majority), but only with two members.
3. Start etcd-3. Joins the running cluster as a follower. All three members are healthy.
4. Verify health. etcdctl endpoint health should show all three as healthy. etcdctl endpoint status --write-out=table shows one leader and two followers, plus current DB size and revision.

ETCD_INITIAL_CLUSTER_STATE=new is left in the EnvironmentFile after the cluster's first boot. Is this a problem on subsequent restarts?


5. Member Operations

# ─── Adding a member ─────────────────────────────────────────────────────────

# Step 1: register the new member (as a learner — non-voting, doesn't affect quorum)
etcdctl member add etcd-4 \
  --peer-urls=https://10.0.0.4:2380 \
  --learner
# Output includes the new member's ID — note it

# Step 2: write /etc/etcd/etcd.env on etcd-4 with:
#   ETCD_INITIAL_CLUSTER_STATE=existing   ← not 'new'
#   ETCD_INITIAL_CLUSTER=<all 4 members>
# Then start etcd on etcd-4

# Step 3: check sync progress (raftAppliedIndex should approach leader's)
etcdctl endpoint status --endpoints=https://10.0.0.4:2379 --write-out=table

# Step 4: promote once caught up (learner becomes voting member)
etcdctl member promote <member-id>

# ─── Removing a member ───────────────────────────────────────────────────────

# Remove BEFORE stopping the process — removing a stopped member avoids quorum math issues
etcdctl member remove <member-id>
# Then stop etcd on the departing node
systemctl stop etcd

# Verify cluster is healthy after removal
etcdctl endpoint health
etcdctl member list

You add a 4th member directly as a voting member (no learner flag) to a 3-node cluster. The new member's snapshot download takes 10 minutes. What risk does this introduce vs the learner approach?


6. Disaster Recovery Runbook

Node crashed but data dir is intact. Just restart — etcd will reload from its persistent state and rejoin the cluster as a follower.

systemctl restart etcd

# Verify it rejoined and is replicating
etcdctl endpoint health --endpoints=https://10.0.0.X:2379
etcdctl endpoint status --write-out=table   # check raftAppliedIndex is catching up

If it fails to rejoin, check /var/log/messages or journalctl -u etcd for TLS or cluster token mismatches.

</div>
<div class="tab-panel" data-tab-panel="corrupt">

Data dir is corrupted or wiped. Remove the old member from the cluster, wipe the data dir, re-add as learner.

# On the surviving cluster (2-node quorum is enough to proceed):
etcdctl member remove <dead-member-id>    # get ID from 'member list'
etcdctl member add etcd-X \
  --peer-urls=https://10.0.0.X:2380 \
  --learner

# On the recovered node:
systemctl stop etcd                       # ensure it's fully stopped
rm -rf /var/lib/etcd/*                    # wipe corrupted data
chown -R etcd:etcd /var/lib/etcd

# Update EnvironmentFile on the recovered node:
# ETCD_INITIAL_CLUSTER_STATE=existing     ← joining an existing cluster
# ETCD_INITIAL_CLUSTER=<all members including this one>

systemctl start etcd

# Wait for sync — watch raftAppliedIndex approach leader
watch -n 2 "etcdctl endpoint status --endpoints=https://10.0.0.X:2379 --write-out=table"

# Promote once fully synced
etcdctl member promote <new-learner-id>
</div>
<div class="tab-panel" data-tab-panel="quorum">

Majority of nodes are permanently gone. Last resort — use --force-new-cluster to bootstrap a new single-member cluster from the surviving node's data, then re-add others.

# Step 1: find the most up-to-date surviving member
etcdctl endpoint status --write-out=table
# Look at "raft applied index" — highest value = most data

# Step 2: on that node, stop etcd and add --force-new-cluster
systemctl stop etcd

# Edit /etc/systemd/system/etcd.service:
# Add to ExecStart: --force-new-cluster
# OR add to EnvironmentFile: ETCD_FORCE_NEW_CLUSTER=true
systemctl daemon-reload
systemctl start etcd

# Step 3: verify single-member cluster is healthy
etcdctl endpoint health --endpoints=https://127.0.0.1:2379

# Step 4: IMMEDIATELY remove --force-new-cluster (leaving it is dangerous)
systemctl stop etcd
# Remove the flag from etcd.service / EnvironmentFile
systemctl daemon-reload
systemctl start etcd

# Step 5: re-add the other members as learners
etcdctl member add etcd-2 --peer-urls=https://10.0.0.2:2380 --learner
# Wipe etcd-2's data dir, set ETCD_INITIAL_CLUSTER_STATE=existing, start etcd-2
# Repeat for etcd-3
# Promote each once synced

Warning: --force-new-cluster truncates the Raft log to the current snapshot. Any writes that committed on the dead majority but haven't been applied to the surviving node are permanently lost. This is the CP tradeoff.

</div>
<div class="tab-panel" data-tab-panel="restore">

All nodes' data is lost — restore from snapshot backup.

# Step 1: stop etcd on all members
systemctl stop etcd

# Step 2: restore snapshot to a fresh data dir — run on EACH member
# Each restore command differs only in --name and --initial-advertise-peer-urls

# On etcd-1:
etcdctl snapshot restore /backup/etcd-snapshot.db \
  --name etcd-1 \
  --initial-cluster "etcd-1=https://10.0.0.1:2380,etcd-2=https://10.0.0.2:2380,etcd-3=https://10.0.0.3:2380" \
  --initial-cluster-token etcd-prod-cluster-1 \
  --initial-advertise-peer-urls https://10.0.0.1:2380 \
  --data-dir /var/lib/etcd        # restore writes directly into data dir
chown -R etcd:etcd /var/lib/etcd

# On etcd-2:
etcdctl snapshot restore /backup/etcd-snapshot.db \
  --name etcd-2 \
  --initial-cluster "etcd-1=https://10.0.0.1:2380,etcd-2=https://10.0.0.2:2380,etcd-3=https://10.0.0.3:2380" \
  --initial-cluster-token etcd-prod-cluster-1 \
  --initial-advertise-peer-urls https://10.0.0.2:2380 \
  --data-dir /var/lib/etcd
chown -R etcd:etcd /var/lib/etcd

# On etcd-3 (same pattern)...

# Step 3: set ETCD_INITIAL_CLUSTER_STATE=new in EnvironmentFile on all nodes
# (snapshot restore creates a fresh cluster identity)

# Step 4: start all members — start them close together (within election-timeout)
# Start etcd-1, etcd-2, etcd-3 in quick succession

# Step 5: verify
etcdctl endpoint health
etcdctl endpoint status --write-out=table
</div>

--force-new-cluster is accidentally left in the systemd unit after the recovery. The cluster is running fine with all three members re-added. On the next routine restart of that node, what happens?


7. Monitoring

etcd exposes Prometheus metrics natively on port 2381 — no separate exporter process needed.

# /etc/prometheus/prometheus.yml — add this scrape job
scrape_configs:
  - job_name: etcd
    scheme: https
    tls_config:
      ca_file:   /etc/prometheus/tls/etcd-ca.crt
      cert_file: /etc/prometheus/tls/etcd-client.crt
      key_file:  /etc/prometheus/tls/etcd-client.key
    static_configs:
      - targets:
          - 10.0.0.1:2381
          - 10.0.0.2:2381
          - 10.0.0.3:2381
# alerting-rules/etcd.yaml
groups:
  - name: etcd
    rules:
      - alert: EtcdWALFsyncSlow
        expr: histogram_quantile(0.99, rate(etcd_disk_wal_fsync_duration_seconds_bucket[5m])) > 0.01
        for: 5m
        labels: { severity: warning }
        annotations:
          summary: "etcd WAL fsync p99 > 10ms — disk I/O is limiting write throughput"

      - alert: EtcdBackendCommitSlow
        expr: histogram_quantile(0.99, rate(etcd_disk_backend_commit_duration_seconds_bucket[5m])) > 0.25
        for: 5m
        labels: { severity: warning }
        annotations:
          summary: "etcd backend commit p99 > 250ms — consider defrag or faster disk"

      - alert: EtcdDbSizeHigh
        expr: etcd_mvcc_db_total_size_in_bytes / etcd_server_quota_backend_bytes > 0.80
        for: 5m
        labels: { severity: warning }
        annotations:
          summary: "etcd DB size > 80% of quota — compact and defrag before NOSPACE alarm fires"

      - alert: EtcdLeaderChanging
        expr: rate(etcd_server_leader_changes_seen_total[1h]) > 1
        for: 5m
        labels: { severity: critical }
        annotations:
          summary: "etcd leader changing frequently — check disk WAL fsync latency and peer round-trip"

      - alert: EtcdProposalsFailing
        expr: rate(etcd_server_proposals_failed_total[5m]) > 0
        for: 2m
        labels: { severity: critical }
        annotations:
          summary: "etcd proposals failing — check quorum, disk, and network"

      - alert: EtcdPeerRttHigh
        expr: histogram_quantile(0.99, rate(etcd_network_peer_round_trip_time_seconds_bucket[5m])) > 0.05
        for: 5m
        labels: { severity: warning }
        annotations:
          summary: "etcd peer round-trip p99 > 50ms — heartbeat delays may cause re-elections"

Grafana dashboard: import etcd mixin (ID 3070) or the official etcd dashboard at https://github.com/etcd-io/etcd/tree/main/contrib/mixin.


8. Operational Runbook

Health checks at a glance

# All-member health (TLS flags via env vars set in §3)
etcdctl endpoint health

# Status table: leader, revision, DB size, raftAppliedIndex per member
etcdctl endpoint status --write-out=table

# Alarm check
etcdctl alarm list

# Member list with IDs (need IDs for remove/promote)
etcdctl member list --write-out=table

# DB size vs quota on each member
etcdctl endpoint status --write-out=json \
  | jq '.[] | {endpoint: .Endpoint, dbSize: .Status.dbSize, quota: .Status.dbSizeInUse}'

Common issues and fixes

# Symptom: etcdctl writes return "mvcc: database space exceeded"
# Step 1: compact (frees internal pages, does not shrink file)
REV=$(etcdctl endpoint status --write-out=json | jq '.[0].Status.header.revision')
etcdctl compact $REV

# Step 2: defrag each member one at a time (blocks that member briefly)
etcdctl defrag --endpoints=https://10.0.0.1:2379
etcdctl defrag --endpoints=https://10.0.0.2:2379
etcdctl defrag --endpoints=https://10.0.0.3:2379

# Step 3: disarm alarm
etcdctl alarm disarm

# Step 4: verify
etcdctl alarm list           # should be empty
etcdctl endpoint status --write-out=table  # DB size should be smaller
</div>
<div class="tab-panel" data-tab-panel="tls-err">
# Symptom: "certificate signed by unknown authority" or "x509: SAN mismatch"

# Check peer cert SANs on the problematic member
openssl x509 -noout -text -in /etc/etcd/tls/peer-etcd-1.crt | grep -A5 "Subject Alternative"

# Check cert expiry
openssl x509 -noout -dates -in /etc/etcd/tls/peer-etcd-1.crt

# Verify the CA cert is the same on all nodes
openssl x509 -noout -fingerprint -in /etc/etcd/tls/ca.crt
# Run on all three nodes — fingerprint must match

# Test TLS connection manually
openssl s_client -connect 10.0.0.2:2380 \
  -CAfile /etc/etcd/tls/ca.crt \
  -cert /etc/etcd/tls/peer-etcd-1.crt \
  -key /etc/etcd/tls/peer-etcd-1.key
</div>
<div class="tab-panel" data-tab-panel="elections">
# Symptom: rate(etcd_server_leader_changes_seen_total[1h]) > 1
# Root cause is almost always slow WAL fsync

# 1. Check WAL fsync latency via metrics endpoint
curl -s http://10.0.0.1:2381/metrics \
  | grep etcd_disk_wal_fsync_duration_seconds_bucket \
  | tail -5

# 2. Check disk throughput
iostat -x 1 5   # look for await > 10ms on the etcd data disk

# 3. Check peer network latency
etcdctl endpoint status --write-out=table  # compare raftAppliedIndex across members

# Fixes:
# - Move etcd data dir to NVMe/SSD
# - Dedicate a separate disk away from OS and container logs
# - Increase heartbeat-interval / election-timeout if cross-region:
#   ETCD_HEARTBEAT_INTERVAL=500     # 500ms for 50ms RTT links
#   ETCD_ELECTION_TIMEOUT=5000      # must be >= 10x heartbeat
</div>
<div class="tab-panel" data-tab-panel="unstarted">
# Symptom: etcdctl member list shows a member as "unstarted"
# Most common cause: ETCD_INITIAL_CLUSTER_STATE=new on a member joining an existing cluster

# Fix on the stuck member:
# 1. Stop etcd
systemctl stop etcd

# 2. Change EnvironmentFile
sed -i 's/ETCD_INITIAL_CLUSTER_STATE=new/ETCD_INITIAL_CLUSTER_STATE=existing/' /etc/etcd/etcd.env

# 3. Wipe the data dir (the failed-new-cluster attempt may have left corrupt state)
rm -rf /var/lib/etcd/*
chown -R etcd:etcd /var/lib/etcd

# 4. Remove and re-add the member from the running cluster, then restart
etcdctl member remove <stuck-member-id>
etcdctl member add etcd-X --peer-urls=https://10.0.0.X:2380 --learner
systemctl start etcd
# Promote once synced
</div>

9. Setup Checklist

1. Firewall verified. nc -zv <peer-ip> 2380 succeeds from all three nodes in both directions. nc -zv <peer-ip> 2379 succeeds from app servers.
2. TLS certs distributed. ca.crt, per-node peer cert and key on each node. chmod 400 on all private keys. CA private key is NOT on any etcd node.
3. EnvironmentFile written. All three nodes have correct /etc/etcd/etcd.env with node-specific name and IPs. ETCD_INITIAL_CLUSTER lists all three members consistently.
4. systemd unit written and enabled. systemctl enable etcd on all nodes. systemctl daemon-reload run after any unit changes.
5. Cluster bootstrapped and healthy. etcdctl endpoint health shows all three members healthy. endpoint status --write-out=table shows one leader, two followers.
6. ETCD_INITIAL_CLUSTER_STATE changed to existing. Updated in EnvironmentFile on all nodes after bootstrap. Prevents accidental new-cluster bootstrap on data-dir wipe.
7. Auto-compaction confirmed. ETCD_AUTO_COMPACTION_MODE=periodic and ETCD_AUTO_COMPACTION_RETENTION=1h in EnvironmentFile. Verify with etcdctl endpoint status — DB size should not grow unbounded.
8. Prometheus scraping all three members. etcd_server_has_leader metric visible in Prometheus for all three targets. Alert rules imported.
9. Snapshot backup tested. Manual etcdctl snapshot save succeeded and snapshot status shows correct hash and revision. Restore procedure tested on a scratch VM.

Edit this page on GitHub ↗