Kubernetes The Hard Way On VirtualBox 5日目
Kubernetesを雰囲気で使わないための修行Kubernetes The Hard Way On VirtualBoxの5日目。今日はetcdのクラスタを作成します。
Bootstrapping the etcd Cluster
Kubernetesのコンポーネントはステートレスで、クラスタの状態をetcdに保存します。今回は2ノードのetcdクラスタを作成し、高可用性とリモートアクセスの設定をします。
Prerequisites
今回は以下の手順を master-1
と master-2
の両方に行います。
Bootstrapping an etcd Cluster Member
Download and Install the etcd Binaries
公式リポジトリからetcdのバイナリを入手します。
wget -q --show-progress --https-only --timestamping \ "https://github.com/coreos/etcd/releases/download/v3.5.0/etcd-v3.5.0-linux-amd64.tar.gz"
入手したファイルを展開し、 etcd
サーバのインストールとコマンドラインユーティリティを置きます。
{ tar -xvf etcd-v3.5.0-linux-amd64.tar.gz sudo mv etcd-v3.5.0-linux-amd64/etcd* /usr/local/bin/ }
Configure the etcd Server
設定ファイルを置くディレクトリを作り、2日目で作成した証明書を置きます
{ sudo mkdir -p /etc/etcd /var/lib/etcd sudo cp ca.crt etcd-server.key etcd-server.crt /etc/etcd/ }
インスタンスの内部IPアドレスは、クライアントからのリクエストを処理し、etcdクラスターピアと通信するために使用されます。 master(etcd)ノードの内部IPアドレスを取得します。
INTERNAL_IP=$(ip addr show enp0s8 | grep "inet " | awk '{print $2}' | cut -d / -f 1)
各etcdメンバーは、etcdクラスター内で一意の名前を持っている必要があります。 現在のコンピューティングインスタンスのホスト名と一致するようにetcdの名前を設定します。
ETCD_NAME=$(hostname -s)
etcd.service
という、systemdのユニットファイルを作成します。
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 master-1=https://192.168.5.11:2380,master-2=https://192.168.5.12:2380 \\ --initial-cluster-state new \\ --data-dir=/var/lib/etcd Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target EOF
Start the etcd Server
{ sudo systemctl daemon-reload sudo systemctl enable etcd sudo systemctl start etcd }
起動状態を確認してみましょう
systemctl status etcd
Verification
動作確認のため、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
両方のノードで以下のように出力されればOKです。
45bf9ccad8d8900a, started, master-2, https://192.168.5.12:2380, https://192.168.5.12:2379, false 54a5796a6803f252, started, master-1, https://192.168.5.11:2380, https://192.168.5.11:2379, false
今日はここまで!
お読みいただきありがとうございました!