etcdctl: The etcd Client
Get fluent in etcdctl — put and get keys, read whole prefixes, watch for changes live, tie keys to leases, run a compare-and-set, and inspect the cluster from the command line.
etcd is the consistent key-value store at the heart of Kubernetes and a hundred other systems, and etcdctl is how you talk to it from a terminal. It is a command-and-exit shell client: you type one command, it runs, it returns. We start from an empty keyspace and build up real fluency one small thing at a time — writing and reading keys, scanning a whole prefix, watching a key change in real time, attaching keys to leases so they expire on their own, doing an atomic compare-and-set, and finally checking the health and shape of the cluster itself. Each idea lands on its own command, the way you would actually run it.
What you'll build
- Put and get keys in the etcd keyspace
- Read whole subtrees with range reads over a prefix
- Delete single keys and prefixes
- Watch keys for live PUT and DELETE events
- Tie keys to leases so they expire automatically
- Run an atomic compare-and-set transaction
- Inspect cluster members, status and health
Contents
- Write your first key
- Read it back
- Read just the value
- Overwrite a key
- See what an overwrite replaced
- Add a few more keys
- Read a whole prefix
- List just the keys
- Delete a key
- Delete a whole prefix
- Watch a key for changes
- See the events arrive
- Watch a whole subtree
- Grant a lease
- Attach a key to the lease
- Check the time remaining
- Set up for a compare-and-set
- Run an atomic compare-and-set
- Confirm the new value
- Watch a compare fail
- List the cluster members
- Read endpoint status as a table
- Check the cluster is healthy
- Get machine-readable output