Playgrounds Cloud

HA Etcd Cluster Playground

Get access to the Kubernetes with CRI-O playground with one click

What is etcd?

Etcd is an open-source, distributed key-value database. In key-value databases, each record contains a key which is the unique identifier. A value is associated with the key. Etcd is a major component of many projects such as Kubernetes, Rook, CoreDNS, etc. Kubernetes uses etcd as a data store to maintain information about the state of the cluster. It stores the metadata ("data about data") in a fault-tolerant setup, using multiple servers. So even if one server fails, etcd should still work, if the other servers are still available.

Common etcd commands

  • To create a key-value pair:
etcdctl put key1 value1

  • To grant a lease for 10 seconds:
etcdctl lease grant 10

Leases are used to specify TTL (Time-to-live) for temporary keys. Once a lease is created, keys can be associated with this lease. We'll see how in the next example.

Note: This command will return an id. And this id should be used when you want to associate a key with this specific lease.

  • To create a key-value pair, and associate the key with a lease:
etcdctl put key2 value23 --lease=<lease_id>

  • To fetch the value of a key
etcdctl get key1

Note: This command will also print the key associated with the value.

  • To fetch only the value of a key
etcdctl get key1 --print-value-only

  • To fetch key-value pairs over a range of keys
etcdctl get key1 key5

Note: It will fetch a list of available keys from key1 to key5

  • To fetch values of keys with a certain prefix (that start with a specific sequence of characters, in our example, the word "key"):
etcdctl get --prefix=key

  • To delete a key
etcdctl del key1

Experiment with etcd 

KodeKloud provides a small etcd cluster so you can quickly and easily get hands-on experience. This playground comes up with a 3-node etcd cluster. You can access all three nodes using the same terminal. No need to install anything or go through a complex setup process. If you're unfamiliar with etcd, you can use the quick start guide link provided in the playground.