Etcd
From Christoph's Personal Wiki
Revision as of 18:45, 5 May 2020 by Christoph (Talk | contribs) (Created page with "'''etcd''' is a strongly consistent, distributed key-value store that provides a reliable way to store data that needs to be accessed by a distributed system or cluster of mac...")
etcd is a strongly consistent, distributed key-value store that provides a reliable way to store data that needs to be accessed by a distributed system or cluster of machines. It gracefully handles leader elections during network partitions and can tolerate machine failure, even in the leader node.
Create a single-node etcd cluster running in Docker
- Start up a Docker container for the single-node etcd cluster:
$ export DATA_DIR="etcd-data" $ export NODE1=10.x.x.x # <= You host IP $ REGISTRY=quay.io/coreos/etcd $ docker volume create --name etcd-data $ docker run \ -p 2379:2379 \ -p 2380:2380 \ --volume=${DATA_DIR}:/etcd-data \ --name etcd ${REGISTRY}:latest \ /usr/local/bin/etcd \ --data-dir=/etcd-data --name node1 \ --initial-advertise-peer-urls http://${NODE1}:2380 --listen-peer-urls http://0.0.0.0:2380 \ --advertise-client-urls http://${NODE1}:2379 --listen-client-urls http://0.0.0.0:2379 \ --initial-cluster node1=http://${NODE1}:2380
- In a different shell:
$ go get github.com/coreos/etcd/etcdctl $ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 member list 5ef3db6412b1adfb, started, node1, http://10.x.x.x:2380, http://10.x.x.x:2379, false $ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 -w table member list +------------------+---------+-------+----------------------+----------------------+------------+ | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER | +------------------+---------+-------+----------------------+----------------------+------------+ | 5ef3db6412b1adfb | started | node1 | http://10.x.x.x:2380 | http://10.x.x.x:2379 | false | +------------------+---------+-------+----------------------+----------------------+------------+ $ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 -w table endpoint --cluster status +----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | http://10.x.x.x:2379 | 5ef3db6412b1adfb | 3.3.8 | 20 kB | true | false | 4 | 9 | 0 | | +----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ $ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 put foo1 bar1 $ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 put get foo1