Bootstrapping the etcd Cluster
今回 etcd は Stacked Topology でマスターノード内で動かすので、以下の作業は両方のマスターノードで実施する。
Bootstrapping an etcd Cluster Member
Download and Install the etcd Binaries
$ wget -q --show-progress --https-only --timestamping \
> "https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz"
$ tar -xvf etcd-v3.3.9-linux-amd64.tar.gz
$ sudo mv etcd-v3.3.9-linux-amd64/etcd* /usr/local/bin/
Configure the etcd Server
設定ファイルで使う環境変数の設定。
INTERNAL_IP=$(ip addr show eth0 | grep "inet " | awk '{print $2}' | cut -d / -f 1)
ETCD_NAME=$(hostname -s)
設定ファイル
cat <<EOF | sudo tee /etc/systemd/system/etcd.service
[Unit]
Description=etcd
Documentation=https://github.com/coreos
[Service]
ExecStart=/usr/local/bin/etcd \\
--name ${ETCD_NAME} \\
--cert-file=/etc/etcd/etcd-server.crt \\
--key-file=/etc/etcd/etcd-server.key \\
--peer-cert-file=/etc/etcd/etcd-server.crt \\
--peer-key-file=/etc/etcd/etcd-server.key \\
--trusted-ca-file=/etc/etcd/ca.crt \\
--peer-trusted-ca-file=/etc/etcd/ca.crt \\
--peer-client-cert-auth \\
--client-cert-auth \\
--initial-advertise-peer-urls https://${INTERNAL_IP}:2380 \\
--listen-peer-urls https://${INTERNAL_IP}:2380 \\
--listen-client-urls https://${INTERNAL_IP}:2379,https://127.0.0.1:2379 \\
--advertise-client-urls https://${INTERNAL_IP}:2379 \\
--initial-cluster-token etcd-cluster-0 \\
--initial-cluster ip-192-168-0-37=https://192.168.0.37:2380,ip-192-168-1-159=https://192.168.1.159:2380 \\
--initial-cluster-state new \\
--data-dir=/var/lib/etcd
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
※ 注意
initial-cluster オプションで、各 master の host 名と Private IP の組を入れている。
ここが誤ってると起動しなかった。
参考にした資料ではここの対応が異なっていても動いていた(?)みたいだが、今はこのようにする必要がありそう。
つまり、環境変数に入れてる意味は特になくなってしまった。
起動
$ sudo systemctl daemon-reload
$ sudo systemctl enable etcd
Created symlink /etc/systemd/system/multi-user.target.wants/etcd.service → /etc/systemd/system/etcd.service.
$ sudo systemctl start etcd
動作確認
$ sudo ETCDCTL_API=3 etcdctl member list \
> --endpoints=https://127.0.0.1:2379 \
> --cacert=/etc/etcd/ca.crt \
> --cert=/etc/etcd/etcd-server.crt \
> --key=/etc/etcd/etcd-server.key
93505c81388a1b18, started, ip-192-168-0-37, https://192.168.0.37:2380, https://192.168.0.37:2379
c8e5d79e25edfe3f, started, ip-192-168-1-159, https://192.168.1.159:2380, https://192.168.1.159:2379
