← All bricks

etcdctl · Beginner

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

  1. Write your first key
  2. Read it back
  3. Read just the value
  4. Overwrite a key
  5. See what an overwrite replaced
  6. Add a few more keys
  7. Read a whole prefix
  8. List just the keys
  9. Delete a key
  10. Delete a whole prefix
  11. Watch a key for changes
  12. See the events arrive
  13. Watch a whole subtree
  14. Grant a lease
  15. Attach a key to the lease
  16. Check the time remaining
  17. Set up for a compare-and-set
  18. Run an atomic compare-and-set
  19. Confirm the new value
  20. Watch a compare fail
  21. List the cluster members
  22. Read endpoint status as a table
  23. Check the cluster is healthy
  24. Get machine-readable output