Skip to main content
๐ŸŽ“ Claude Code Masterclass Learn AI-assisted development on Udemy โ€” plus the companion book on Leanpub & Amazon. Start Learning
etcd Cheat Sheet 2026: Kubernetes Key-Value Store
DevOps

etcd Cheat Sheet 2026: Kubernetes Key-Value Store

etcd cheat sheet for Kubernetes operations. etcdctl get/put/watch, snapshot backup and restore, cluster health, member management, and defragmentation.

LB
Luca Berton
ยท 1 min read

A quick reference for etcd โ€” the distributed key-value store behind Kubernetes. Bookmark this page.

CLI Setup

# Set endpoints
export ETCDCTL_API=3
export ETCDCTL_ENDPOINTS=https://127.0.0.1:2379
export ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt
export ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt
export ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key

Key-Value Operations

# Put a key
etcdctl put mykey "myvalue"
etcdctl put /config/database/host "postgres.svc"

# Get a key
etcdctl get mykey
etcdctl get mykey --print-value-only

# Get with prefix (list all under a path)
etcdctl get /config/ --prefix
etcdctl get /config/ --prefix --keys-only

# Delete
etcdctl del mykey
etcdctl del /config/ --prefix    # Delete all under prefix

# Watch for changes
etcdctl watch mykey
etcdctl watch /config/ --prefix

Cluster Health

# Check cluster health
etcdctl endpoint health
etcdctl endpoint health --cluster

# Check cluster status
etcdctl endpoint status
etcdctl endpoint status --cluster --write-out=table

# List members
etcdctl member list --write-out=table

# Check leader
etcdctl endpoint status --write-out=table | grep true

Backup and Restore

# Take snapshot backup
etcdctl snapshot save /backup/etcd-$(date +%Y%m%d).db

# Check snapshot status
etcdctl snapshot status /backup/etcd-20260412.db --write-out=table

# Restore from snapshot
etcdctl snapshot restore /backup/etcd-20260412.db \
  --data-dir=/var/lib/etcd-restore \
  --name=etcd-node1 \
  --initial-cluster=etcd-node1=https://10.0.0.1:2380 \
  --initial-advertise-peer-urls=https://10.0.0.1:2380

Kubernetes-Specific

# List all Kubernetes keys
etcdctl get / --prefix --keys-only

# Get specific Kubernetes resource
etcdctl get /registry/pods/default/my-pod

# Count resources
etcdctl get /registry/pods --prefix --keys-only | wc -l

# Check etcd size
etcdctl endpoint status --write-out=json | jq '.[] | {endpoint: .Endpoint, dbSize: .Status.dbSize}'

# Compact and defrag (maintenance)
rev=$(etcdctl endpoint status --write-out=json | jq '.[0].Status.header.revision')
etcdctl compact $rev
etcdctl defrag

Member Management

# Add member
etcdctl member add etcd-node3 --peer-urls=https://10.0.0.3:2380

# Remove member
etcdctl member remove MEMBER_ID

# Update member peer URLs
etcdctl member update MEMBER_ID --peer-urls=https://new-ip:2380

Tips and Tricks

  • Always use ETCDCTL_API=3 โ€” v2 API is deprecated
  • Schedule automatic backups: etcd is the single source of truth for K8s
  • Monitor etcd performance: leader elections, disk fsync latency
  • Keep etcd cluster size at 3 or 5 members (odd numbers for quorum)
  • Use dedicated SSD/NVMe for etcd data directory

Free 30-min AI & Cloud consultation

Book Now