How to Add and Remove Members

Guide to dealing with membership in etcd cluster

member to add,remove,update membership:

13_etcdctl_member_2016062301

1. # For each machine
2. TOKEN=my-etcd-token-1
3. CLUSTER_STATE=new
4. NAME_1=etcd-node-1
5. NAME_2=etcd-node-2
6. NAME_3=etcd-node-3
7. HOST_1=10.240.0.13
8. HOST_2=10.240.0.14
9. HOST_3=10.240.0.15
10. 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. etcd --data-dir=data.etcd --name ${THIS_NAME} \
16. --initial-advertise-peer-urls http://${THIS_IP}:2380 \
17. --listen-peer-urls http://${THIS_IP}:2380 \
18. --advertise-client-urls http://${THIS_IP}:2379 \
19. --listen-client-urls http://${THIS_IP}:2379 \
20. --initial-cluster ${CLUSTER} \
21. --initial-cluster-state ${CLUSTER_STATE} \
22. --initial-cluster-token ${TOKEN}

24. # For node 2
25. THIS_NAME=${NAME_2}
26. THIS_IP=${HOST_2}
27. etcd --data-dir=data.etcd --name ${THIS_NAME} \
28. --initial-advertise-peer-urls http://${THIS_IP}:2380 \
29. --listen-peer-urls http://${THIS_IP}:2380 \
30. --advertise-client-urls http://${THIS_IP}:2379 \
31. --listen-client-urls http://${THIS_IP}:2379 \
32. --initial-cluster ${CLUSTER} \
33. --initial-cluster-state ${CLUSTER_STATE} \
34. --initial-cluster-token ${TOKEN}

36. # For node 3
37. THIS_NAME=${NAME_3}
38. THIS_IP=${HOST_3}
39. etcd --data-dir=data.etcd --name ${THIS_NAME} \
40. --initial-advertise-peer-urls http://${THIS_IP}:2380 \
41. --listen-peer-urls http://${THIS_IP}:2380 \
42. --advertise-client-urls http://${THIS_IP}:2379 \
43. --listen-client-urls http://${THIS_IP}:2379 \
44. --initial-cluster ${CLUSTER} \
45. --initial-cluster-state ${CLUSTER_STATE} \
46. --initial-cluster-token ${TOKEN}

Then replace a member with member remove and member add commands:

1. # get member ID
2. export ETCDCTL_API=3
3. HOST_1=10.240.0.13
4. HOST_2=10.240.0.14
5. HOST_3=10.240.0.15
6. etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 member list

8. # remove the member
9. MEMBER_ID=278c654c9a6dfd3b
10. etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 \
11. member remove ${MEMBER_ID}

13. # add a new member (node 4)
14. export ETCDCTL_API=3
15. NAME_1=etcd-node-1
16. NAME_2=etcd-node-2
17. NAME_4=etcd-node-4
18. HOST_1=10.240.0.13
19. HOST_2=10.240.0.14
20. HOST_4=10.240.0.16 # new member
21. etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379 \
22. member add ${NAME_4} \
23. --peer-urls=http://${HOST_4}:2380

Next, start the new member with --initial-cluster-state existing flag:

1. # [WARNING] If the new member starts from the same disk space,
2. # make sure to remove the data directory of the old member
3. #
4. # restart with 'existing' flag
5. TOKEN=my-etcd-token-1
6. CLUSTER_STATE=existing
7. NAME_1=etcd-node-1
8. NAME_2=etcd-node-2
9. NAME_4=etcd-node-4
10. HOST_1=10.240.0.13
11. HOST_2=10.240.0.14
12. HOST_4=10.240.0.16 # new member
13. CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_4}=http://${HOST_4}:2380

15. THIS_NAME=${NAME_4}
16. THIS_IP=${HOST_4}
17. etcd --data-dir=data.etcd --name ${THIS_NAME} \
18. --initial-advertise-peer-urls http://${THIS_IP}:2380 \
19. --listen-peer-urls http://${THIS_IP}:2380 \
20. --advertise-client-urls http://${THIS_IP}:2379 \
21. --listen-client-urls http://${THIS_IP}:2379 \
22. --initial-cluster ${CLUSTER} \
23. --initial-cluster-state ${CLUSTER_STATE} \
24. --initial-cluster-token ${TOKEN}

Last modified June 24, 2025: etcd-website: reorganised tutorials to tasks (b5f1df7)