etcd
https://raw.githubusercontent.com/etcd-io/etcd/main/logos/etcd-horizontal-color.svg https://raw.githubusercontent.com/etcd-io/etcd/main/logos/etcd-horizontal-color.svg
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.
Sample
Dockerで試す
etcd用のnetworkの作成
code:bash
docker network create etcd-network --subnet=172.16.0.0/24 --ip-range=172.16.0.0/24
etcdコンテナの作成
code:bash
rm -rf /tmp/etcd-data1.tmp && mkdir -p /tmp/etcd-data1.tmp && \
docker run -d \
--network etcd-network \
--ip 172.16.0.4 \
-p 2379:2379 \
-p 2380:2380 \
--mount type=bind,source=/tmp/etcd-data1.tmp,destination=/etcd-data \
--name etcd1 \
gcr.io/etcd-development/etcd:v3.4.5 \
/usr/local/bin/etcd \
--name etcd1 \
--data-dir /etcd-data \
--initial-cluster-token tkn \
--initial-cluster-state new
rm -rf /tmp/etcd-data2.tmp && mkdir -p /tmp/etcd-data2.tmp && \
docker run -d \
--network etcd-network \
--ip 172.16.0.5 \
-p 2381:2381 \
-p 2382:2382 \
--mount type=bind,source=/tmp/etcd-data2.tmp,destination=/etcd-data \
--name etcd2 \
gcr.io/etcd-development/etcd:v3.4.5 \
/usr/local/bin/etcd \
--name etcd2 \
--data-dir /etcd-data \
--initial-cluster-token tkn \
--initial-cluster-state new
etcdコンテナの確認
code:bash
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c5d576185df4 gcr.io/etcd-development/etcd:v3.4.5 "/usr/local/bin/etcd…" 3 minutes ago Up 3 minutes 2379-2380/tcp, 0.0.0.0:2381-2382->2381-2382/tcp etcd2
dbf2bff87e48 gcr.io/etcd-development/etcd:v3.4.5 "/usr/local/bin/etcd…" 4 minutes ago Up 4 minutes 0.0.0.0:2379-2380->2379-2380/tcp etcd1
データ投入と確認
code:bash
# 両方で追加されていることを確認
backup
code: (bash)
ETCDCTL_API=3 etcdctl \
--cert=/etc/kubernetes/pki/etcd/ca.crt \
--cacert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/ca.key \
snapshot save /opt/snapshot-pre-boot.db
restore
code: (bash)
ETCDCTL_API=3 etcdctl \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--key=/etc/kubernetes/pki/etcd/server.key \
--name=master \
--data-dir /var/lib/etcd-from-backup \
--initial-cluster-token etcd-cluster-1 \
snapshot restore /opt/snapshot-pre-boot.db
code: /etc/kubernetes/manifests/etcd.yaml
volumes:
- hostPath:
path: /var/lib/etcd-from-backup
type: DirectoryOrCreate
name: etcd-data
Reference