Kubernetes
etcdctl CLI
etcdctl commands for etcd key-value store management.
30 commands
Windows
MacOS
Linux
#key-value-store
#cluster
Key-Value Operations
Store a key-value pair
etcdctl put mykey "myvalue"
Retrieve a value by key
etcdctl get mykey
Get all keys with a prefix
etcdctl get --prefix /app/
Get only key names with a prefix
etcdctl get --prefix /app/ --keys-only
Delete a key
etcdctl del mykey
Delete all keys with a prefix
etcdctl del --prefix /app/
List first 10 keys in the store
etcdctl get "" --prefix --limit=10
Watch
Watch a key for changes
etcdctl watch mykey
Watch all keys with a prefix
etcdctl watch --prefix /app/
Watch from a specific revision
etcdctl watch mykey --rev 42
Start interactive watch mode
etcdctl watch -i
Lease
Create a lease with 300 second TTL
etcdctl lease grant 300
Attach a key to a lease
etcdctl put mykey "val" --lease=abc123
List all active leases
etcdctl lease list
Check remaining TTL of a lease
etcdctl lease timetolive abc123
Revoke a lease and delete its keys
etcdctl lease revoke abc123
Keep a lease alive indefinitely
etcdctl lease keep-alive abc123
Cluster Management
etcdctl endpoint status --write-out=table # Show endpoint status in table format
Check health of all endpoints
etcdctl endpoint health
List all cluster members
etcdctl member list --write-out=table
Add a new member
etcdctl member add node3 --peer-urls=http://10.0.0.3:2380
Remove a member from the cluster
etcdctl member remove abc123
Update member peer URLs
etcdctl member update abc123 --peer-urls=http://10.0.0.3:2380
Snapshot
Save a snapshot of the store
etcdctl snapshot save backup.db
Restore from a snapshot file
etcdctl snapshot restore backup.db
Show snapshot file details
etcdctl snapshot status backup.db --write-out=table
Restore to a specific directory
etcdctl snapshot restore backup.db --data-dir /var/lib/etcd-restored
Quick Commands
Store a key-value pair in the etcd cluster
etcdctl put mykey "myvalue"
Save a snapshot of the entire etcd data store to a file
etcdctl snapshot save backup.db
Check the health status of all etcd cluster endpoints
etcdctl endpoint health