{ export ETCD_VER=v3.4.10 wget -q "https://github.com/etcd-io/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz" tar zxf etcd-v3.4.10-linux-amd64.tar.gz mv etcd-v3.4.10-linux-amd64/etcd* /usr/local/bin/ rm -rf etcd*
PATH=$PATH:/usr/local/bin
}
Change below name and IPs for 1,2,3 accordingly
ETCD_NAME="etcd3"
NODE_IP=$(hostname -i)
ETCD1_IP="172.31.8.194"
ETCD2_IP="172.31.12.116"
ETCD3_IP="172.31.13.204"
cat <<EOF >/etc/systemd/system/etcd.service
[Unit]
Description=etcd
[Service]
Type=notify
ExecStart=/usr/local/bin/etcd \\
--name ${ETCD_NAME} \\
--initial-advertise-peer-urls http://${NODE_IP}:2380 \\
--listen-peer-urls http://${NODE_IP}:2380 \\
--advertise-client-urls http://${NODE_IP}:2379 \\
--listen-client-urls http://${NODE_IP}:2379,http://127.0.0.1:2379 \\
--initial-cluster-token etcd-cluster-1 \\
--initial-cluster etcd1=http://${ETCD1_IP}:2380,etcd2=http://${ETCD2_IP}:2380,etcd3=http://${ETCD3_IP}:2380 \\
--initial-cluster-state new
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
{
systemctl daemon-reload
systemctl enable --now etcd
}
ETCDCTL_API=3 etcdctl --endpoints=http://127.0.0.1:2379 member list
ETCD Cluster is ready now
How to use cluster in kubeadm?
{ ETCD1_IP="172.31.8.194" ETCD2_IP="
172.31.12.116
" ETCD3_IP="
172.31.13.204
" cat <<EOF > kubeadm-config.yaml apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration networking: podSubnet: "192.168.0.0/16" etcd: external: endpoints: - https://${ETCD1_IP}:2379 - https://${ETCD2_IP}:2379 - https://${ETCD3_IP}:2379 --- apiVersion: kubeadm.k8s.io/v1beta1 kind: InitConfiguration localAPIEndpoint: advertiseAddress: "172.16.16.100" EOF }
kubeadm init --config kubeadm-config.yaml --ignore-preflight-errors=all
kubectl --kubeconfig=/etc/kubernetes/admin.conf create -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
kubeadm token create --print-join-command
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
How delete etcd data in cluster?
# rm -Rf /etc/etcd/* # rm -Rf /var/lib/etcd/*