$ command-helper

etcd (etcdctl)

Keys and prefixes, watching changes, cluster health, snapshots and compaction — including the etcd behind Kubernetes.

Requires Google sign-in

Keys

Put a value
etcdctl --endpoints=<etcd_endpoints> put <etcd_key> "value"
Get a value
etcdctl --endpoints=<etcd_endpoints> get <etcd_key>
All keys under a prefix (names only)
etcdctl --endpoints=<etcd_endpoints> get <etcd_prefix> --prefix --keys-only
Delete keys by prefix
etcdctl --endpoints=<etcd_endpoints> del <etcd_prefix> --prefix
Watch changes under a prefix
etcdctl --endpoints=<etcd_endpoints> watch <etcd_prefix> --prefix
Key with a lease (expires in 60 s)advanced
etcdctl lease grant 60 && etcdctl put <etcd_key> "value" --lease=<lease_id>

Cluster

Endpoint health
etcdctl --endpoints=<etcd_endpoints> endpoint health
Status: leader, DB size, raft index
etcdctl --endpoints=<etcd_endpoints> endpoint status --write-out=table
Cluster members
etcdctl --endpoints=<etcd_endpoints> member list --write-out=table
Active alarms (e.g. NOSPACE)advanced
etcdctl --endpoints=<etcd_endpoints> alarm list

Backup and maintenance

Snapshot of a Kubernetes control-plane etcdadvanced
ETCDCTL_API=3 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 \
  snapshot save /tmp/etcd-snapshot.db
Check a snapshotadvanced
etcdutl snapshot status /tmp/etcd-snapshot.db --write-out=table
Restore a snapshot into a new data diradvanced
etcdutl snapshot restore /tmp/etcd-snapshot.db --data-dir /var/lib/etcd-restored
Compact history and defragmentadvanced
etcdctl compact <etcd_revision> && etcdctl --endpoints=<etcd_endpoints> defrag

Take the revision from endpoint status. Defrag blocks the member briefly — one member at a time.