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

etcdctl Cheat Sheet: Kubernetes etcd Commands

etcdctl cheat sheet for Kubernetes cluster management. Get/put keys, snapshot backup and restore, member management, health checks, and compaction commands.

LB
Luca Berton
ยท 1 min read

A quick reference for etcdctl โ€” the etcd command-line client. Bookmark this page.

This is a companion to the etcd Cheat Sheet, focused on etcdctl commands specifically for Kubernetes cluster administration.

Setup

# Set API version (always use v3)
export ETCDCTL_API=3

# For Kubernetes clusters
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

# Or pass inline
etcdctl --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  endpoint health

Health and Status

etcdctl endpoint health
etcdctl endpoint health --cluster
etcdctl endpoint status --write-out=table
etcdctl member list --write-out=table

Backup and Restore

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

# Verify backup
etcdctl snapshot status /backup/etcd-20260413.db --write-out=table

# Restore (stop etcd first!)
etcdctl snapshot restore /backup/etcd-20260413.db \
  --data-dir=/var/lib/etcd-restored

Key Operations

etcdctl get / --prefix --keys-only | head -20
etcdctl get /registry/pods/default --prefix --keys-only
etcdctl get /registry/deployments --prefix --keys-only | wc -l

Maintenance

# Check DB size
etcdctl endpoint status --write-out=json | python3 -m json.tool

# Compact and defrag
rev=$(etcdctl endpoint status --write-out=json | python3 -c "import sys,json; print(json.load(sys.stdin)[0]['Status']['header']['revision'])")
etcdctl compact $rev
etcdctl defrag --cluster

Tips and Tricks

  • Schedule daily etcd backups โ€” it is the single source of truth for your cluster
  • Monitor etcd disk latency: etcdctl check perf
  • Use --write-out=table for human-readable output
  • Keep etcd data on fast SSD/NVMe storage
  • Set alarms: etcdctl alarm list and etcdctl alarm disarm

Free 30-min AI & Cloud consultation

Book Now