The following guide shows how to run etcd with rkt and Docker using the static bootstrap process.

rkt

Running a single node etcd

The following rkt run command will expose the etcd client API on port 2379 and expose the peer API on port 2380.

Use the host IP address when configuring etcd.

  1. export NODE1=192.168.1.21

Trust the CoreOS App Signing Key.

  1. sudo rkt trust --prefix coreos.com/etcd
  2. # gpg key fingerprint is: 18AD 5014 C99E F7E3 BA5F 6CE9 50BD D3E0 FC8A 365E

Run the v3.0.6 version of etcd or specify another release version.

  1. sudo rkt run --net=default:IP=${NODE1} coreos.com/etcd:v3.0.6 -- -name=node1 -advertise-client-urls=http://${NODE1}:2379 -initial-advertise-peer-urls=http://${NODE1}:2380 -listen-client-urls=http://0.0.0.0:2379 -listen-peer-urls=http://${NODE1}:2380 -initial-cluster=node1=http://${NODE1}:2380

List the cluster member.

  1. etcdctl --endpoints=http://192.168.1.21:2379 member list

Running a 3 node etcd cluster

Setup a 3 node cluster with rkt locally, using the -initial-cluster flag.

  1. export NODE1=172.16.28.21
  2. export NODE2=172.16.28.22
  3. export NODE3=172.16.28.23
  1. # node 1
  2. sudo rkt run --net=default:IP=${NODE1} coreos.com/etcd:v3.0.6 -- -name=node1 -advertise-client-urls=http://${NODE1}:2379 -initial-advertise-peer-urls=http://${NODE1}:2380 -listen-client-urls=http://0.0.0.0:2379 -listen-peer-urls=http://${NODE1}:2380 -initial-cluster=node1=http://${NODE1}:2380,node2=http://${NODE2}:2380,node3=http://${NODE3}:2380
  3. # node 2
  4. sudo rkt run --net=default:IP=${NODE2} coreos.com/etcd:v3.0.6 -- -name=node2 -advertise-client-urls=http://${NODE2}:2379 -initial-advertise-peer-urls=http://${NODE2}:2380 -listen-client-urls=http://0.0.0.0:2379 -listen-peer-urls=http://${NODE2}:2380 -initial-cluster=node1=http://${NODE1}:2380,node2=http://${NODE2}:2380,node3=http://${NODE3}:2380
  5. # node 3
  6. sudo rkt run --net=default:IP=${NODE3} coreos.com/etcd:v3.0.6 -- -name=node3 -advertise-client-urls=http://${NODE3}:2379 -initial-advertise-peer-urls=http://${NODE3}:2380 -listen-client-urls=http://0.0.0.0:2379 -listen-peer-urls=http://${NODE3}:2380 -initial-cluster=node1=http://${NODE1}:2380,node2=http://${NODE2}:2380,node3=http://${NODE3}:2380

Verify the cluster is healthy and can be reached.

  1. ETCDCTL_API=3 etcdctl --endpoints=http://172.16.28.21:2379,http://172.16.28.22:2379,http://172.16.28.23:2379 endpoint health

DNS

Production clusters which refer to peers by DNS name known to the local resolver must mount the host’s DNS configuration.

Docker

In order to expose the etcd API to clients outside of Docker host, use the host IP address of the container. Please see docker inspect for more detail on how to get the IP address. Alternatively, specify --net=host flag to docker run command to skip placing the container inside of a separate network stack.

  1. # For each machine
  2. ETCD_VERSION=v3.0.0
  3. TOKEN=my-etcd-token
  4. CLUSTER_STATE=new
  5. NAME_1=etcd-node-0
  6. NAME_2=etcd-node-1
  7. NAME_3=etcd-node-2
  8. HOST_1=10.20.30.1
  9. HOST_2=10.20.30.2
  10. HOST_3=10.20.30.3
  11. CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380
  12. # For node 1
  13. THIS_NAME=${NAME_1}
  14. THIS_IP=${HOST_1}
  15. sudo docker run --net=host --name etcd quay.io/coreos/etcd:${ETCD_VERSION} \
  16. /usr/local/bin/etcd \
  17. --data-dir=data.etcd --name ${THIS_NAME} \
  18. --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
  19. --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
  20. --initial-cluster ${CLUSTER} \
  21. --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
  22. # For node 2
  23. THIS_NAME=${NAME_2}
  24. THIS_IP=${HOST_2}
  25. sudo docker run --net=host --name etcd quay.io/coreos/etcd:${ETCD_VERSION} \
  26. /usr/local/bin/etcd \
  27. --data-dir=data.etcd --name ${THIS_NAME} \
  28. --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
  29. --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
  30. --initial-cluster ${CLUSTER} \
  31. --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
  32. # For node 3
  33. THIS_NAME=${NAME_3}
  34. THIS_IP=${HOST_3}
  35. sudo docker run --net=host --name etcd quay.io/coreos/etcd:${ETCD_VERSION} \
  36. /usr/local/bin/etcd \
  37. --data-dir=data.etcd --name ${THIS_NAME} \
  38. --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
  39. --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
  40. --initial-cluster ${CLUSTER} \
  41. --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}

To run etcdctl using API version 3:

  1. docker exec etcd /bin/sh -c "export ETCDCTL_API=3 && /usr/local/bin/etcdctl put foo bar"

Bare Metal

To provision a 3 node etcd cluster on bare-metal, you might find the examples in the baremetal repo useful.