Cụm từ adm
không còn quá xa lạ đối với những ai đã từng cài đặt Kubernetes bằng kubeadm. Hiện nay có rất nhiều tool lấy cảm hứng từ kubeadm
để đặt tên cho tool cài đặt 1 hệ thống như vậy (ví dụ có cephadm).
Trong bài này mình sẽ giới thiệu việc cài đặt etcd cluster sử dụng công cụ etcdadm. Đây là một công cụ khá mới, giúp cho việc cài đặt 1 cụm etcd 1 cách dễ dàng hơn.
Để cài đặt etcdad, ta cần thực hiện build từ source code, do release của etcdadm không có build sẵn binary.
Lưu ý: Yêu cầu phải cài đặt golang trên máy. Hiện mình đang dùng bản go1.14.2
root@sapd-ubuntu3:~/etcdadm# go version
go version go1.14.2 linux/amd64
Clone source code etcdadm từ github
git clone https://github.com/kubernetes-sigs/etcdadm
Build binary
make etcdadm
Sau khi build được etcdadm, ta thực hiện copy file binary này lên các node dự định cài đặt etcd.
Trong bày này, mình sẽ cài đặt trên 3 node có địa chỉ IP lần lượt như sau
- 10.5.9.175
- 10.5.8.86
- 10.5.9.55
Thực hiện khởi tạo cluster, gõ lệnh ./etcdadm init
trên 1 node. Output như sau:
root@sapd-ubuntu3:~/etcdadm# ./etcdadm init
INFO[0000] [install] Artifact not found in cache. Trying to fetch from upstream: https://github.com/coreos/etcd/releases/download
INFO[0000] [install] Downloading & installing etcd https://github.com/coreos/etcd/releases/download from 3.3.8 to /var/cache/etcdadm/etcd/v3.3.8
INFO[0000] [install] downloading etcd from https://github.com/coreos/etcd/releases/download/v3.3.8/etcd-v3.3.8-linux-amd64.tar.gz to /var/cache/etcdadm/etcd/v3.3.8/etcd-v3.3.8-linux-amd64.tar.gz
######################################################################## 100.0% -#O#- # #
INFO[0005] [install] extracting etcd archive /var/cache/etcdadm/etcd/v3.3.8/etcd-v3.3.8-linux-amd64.tar.gz to /tmp/etcd172607196
INFO[0006] [install] verifying etcd 3.3.8 is installed in /opt/bin/
INFO[0006] [certificates] creating PKI assets
INFO[0006] creating a self signed etcd CA certificate and key files
[certificates] Generated ca certificate and key.
INFO[0006] creating a new server certificate and key files for etcd
[certificates] Generated server certificate and key.
[certificates] server serving cert is signed for DNS names [sapd-ubuntu3] and IPs [10.5.9.55 127.0.0.1]
INFO[0006] creating a new certificate and key files for etcd peering
[certificates] Generated peer certificate and key.
[certificates] peer serving cert is signed for DNS names [sapd-ubuntu3] and IPs [10.5.9.55]
INFO[0007] creating a new client certificate for the etcdctl
[certificates] Generated etcdctl-etcd-client certificate and key.
INFO[0008] creating a new client certificate for the apiserver calling etcd
[certificates] Generated apiserver-etcd-client certificate and key.
[certificates] valid certificates and keys now exist in "/etc/etcd/pki"
INFO[0011] [health] Checking local etcd endpoint health
INFO[0011] [health] Local etcd endpoint is healthy
INFO[0011] To add another member to the cluster, copy the CA cert/key to its certificate dir and run:
INFO[0011] etcdadm join https://10.5.9.55:2379
Tới bước này etcdadm đã thực hiện việc generate PKI Certificate trên node 10.5.9.55
tại thực mục /etc/etcd/pki/
root@sapd-ubuntu3:~/etcdadm# ls -lah /etc/etcd/pki/
total 48K
drwxr-xr-x 2 root root 4.0K May 2 22:09 .
drwxr-xr-x 3 root root 4.0K May 2 22:09 ..
-rw-r--r-- 1 root root 1.1K May 2 22:09 apiserver-etcd-client.crt
-rw------- 1 root root 1.7K May 2 22:09 apiserver-etcd-client.key
-rw-r--r-- 1 root root 1009 May 2 22:09 ca.crt
-rw------- 1 root root 1.7K May 2 22:09 ca.key
-rw-r--r-- 1 root root 1.1K May 2 22:09 etcdctl-etcd-client.crt
-rw------- 1 root root 1.7K May 2 22:09 etcdctl-etcd-client.key
-rw-r--r-- 1 root root 1.1K May 2 22:09 peer.crt
-rw------- 1 root root 1.7K May 2 22:09 peer.key
-rw-r--r-- 1 root root 1.1K May 2 22:09 server.crt
-rw------- 1 root root 1.7K May 2 22:09 server.key
Để các node khác có thể join vào cụm etcd này, ta cần thực hiện copy toàn certificate và key của CA tại thư mục này sang các node member còn lại:
rsync -avR /etc/etcd/pki/ca.* root@10.5.9.175:/
rsync -avR /etc/etcd/pki/ca.* root@10.5.8.86:/
Thực hiện join 2 node còn lại
./etcdadm join https://10.5.9.55:2379
Kiểm tra danh sách member bằng etcdctl
root@sapd-ubuntu3:~/etcdadm/etcd-v3.3.8-linux-amd64# ./etcdctl --cert-file /etc/etcd/pki/etcdctl-etcd-client.crt --key-file /etc/etcd/pki/etcdctl-etcd-client.key --ca-file /etc/etcd/pki/ca.crt --endpoints https://10.5.9.55:2379 member list
223f95c9dff0b55: name=sapd-ubuntu-2 peerURLs=https://10.5.8.86:2380 clientURLs=https://10.5.8.86:2379 isLeader=false
983953b13a9e0a4: name=sapd-ubuntu-1 peerURLs=https://10.5.9.175:2380 clientURLs=https://10.5.9.175:2379 isLeader=false
b627deeadb65a889: name=sapd-ubuntu3 peerURLs=https://10.5.9.55:2380 clientURLs=https://10.5.9.55:2379 isLeader=true