#!/bin/bash # Usage: etcd_member_replace # # This script removes a (faulty) member id from the existing etcd cluster and then defines a new id. # The new etcd member should be started initialy with an empty datadir # and synced once, before we start it again from the systemd unit HOME=$( cd "$(dirname "$0")" && pwd ) source $HOME/../config systemctl stop etcd /usr/local/bin/etcdctl --endpoints="https://${ETCD_1_IP}:2379,https://${ETCD_2_IP}:2379,https://${ETCD_3_IP}:2379" --cert ${CA_DIR}/etcd.crt --key ${CA_DIR}/etcd.key --cacert ${CA_DIR}/etcd-ca.crt member remove $1 sleep 10 /usr/local/bin/etcdctl --endpoints="https://${ETCD_1_IP}:2379,https://${ETCD_2_IP}:2379,https://${ETCD_3_IP}:2379" --cert ${CA_DIR}/etcd.crt --key ${CA_DIR}/etcd.key --cacert ${CA_DIR}/etcd-ca.crt member add ${NODE_NAME_SHORT} --peer-urls="https://${NODE_IP}:2380" /usr/local/bin/etcdctl --endpoints="https://${ETCD_1_IP}:2379,https://${ETCD_2_IP}:2379,https://${ETCD_3_IP}:2379" --cert ${CA_DIR}/etcd.crt --key ${CA_DIR}/etcd.key --cacert ${CA_DIR}/etcd-ca.crt member list #rm -fr /var/lib/etcd/member/ /usr/local/bin/etcd \ --name=${NODE_NAME_SHORT} \ --listen-client-urls=https://${NODE_IP}:2379,https://127.0.0.1:2379 \ --advertise-client-urls=https://${NODE_IP}:2379 \ --data-dir=/var/lib/etcd \ --cert-file=${CA_DIR}/etcd.crt \ --key-file=${CA_DIR}/etcd.key \ --peer-cert-file=${CA_DIR}/etcd-peer.crt \ --peer-key-file=${CA_DIR}/etcd-peer.key \ --trusted-ca-file=${CA_DIR}/etcd-ca.crt \ --peer-trusted-ca-file=${CA_DIR}/etcd-ca.crt \ --peer-client-cert-auth \ --listen-peer-urls=https://${NODE_IP}:2380 \ --client-cert-auth \ --initial-advertise-peer-urls=https://${NODE_IP}:2380 \ --initial-cluster-token="k8x-21b5f25de1" \ --initial-cluster=${ETCD_1_NAME}=https://${ETCD_1_IP}:2380,${ETCD_2_NAME}=https://${ETCD_2_IP}:2380,${ETCD_3_NAME}=https://${ETCD_3_IP}:2380 \ --initial-cluster-state=existing