k1.node ➜ ~ ./etcdadm-linux-amd64 init INFO[0000] [install] extracting etcd archive /var/cache/etcdadm/etcd/v3.3.8/etcd-v3.3.8-linux-amd64.tar.gz to /tmp/etcd664686683 INFO[0001] [install] verifying etcd 3.3.8 is installed in /opt/bin/ INFO[0001] [certificates] creating PKI assets INFO[0001] creating a self signed etcd CA certificate and key files [certificates] Generated ca certificate and key. INFO[0001] 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 [k1.node] and IPs [127.0.0.1 172.16.10.21] INFO[0002] 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 [k1.node] and IPs [172.16.10.21] INFO[0002] creating a new client certificate for the etcdctl [certificates] Generated etcdctl-etcd-client certificate and key. INFO[0002] 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[0006] [health] Checking local etcd endpoint health INFO[0006] [health] Local etcd endpoint is healthy INFO[0006] To add another member to the cluster, copy the CA cert/key to its certificate dir and run: INFO[0006] etcdadm join https://172.16.10.21:2379
k1.node ➜ ~ ./etcdadm-linux-amd64 init --help Initialize a new etcd cluster
Usage: etcdadm init [flags]
Flags: --certs-dir string certificates directory (default "/etc/etcd/pki") --disk-priorities stringArray Setting etcd disk priority (default [Nice=-10,IOSchedulingClass=best-effort,IOSchedulingPriority=2]) --download-connect-timeout duration Maximum time in seconds that you allow the connection to the server to take. (default 10s) -h, --help help for init --install-dir string install directory (default "/opt/bin/") --name string etcd member name --release-url string URL used to download etcd (default "https://github.com/coreos/etcd/releases/download") --server-cert-extra-sans strings optional extra Subject Alternative Names for the etcd server signing cert, can be multiple comma separated DNS names or IPs --skip-hash-check Ignore snapshot integrity hash value (required if copied from data directory) --snapshot string Etcd v3 snapshot file used to initialize member --version string etcd version (default "3.3.8")
Global Flags: -l, --log-level string set log level for output, permitted values debug, info, warn, error, fatal and panic (default "info")
3.2、其他节点加入
在首个节点启动完成后,将集群 ca 证书复制到其他节点然后执行 etcdadm join ENDPOINT_ADDRESS 即可:
sent 2,932 bytes received 67 bytes 856.86 bytes/sec total size is 2,684 speedup is 0.89
# 执行 join k2.node ➜ ~ ./etcdadm-linux-amd64 join https://172.16.10.21:2379 INFO[0000] [certificates] creating PKI assets INFO[0000] creating a self signed etcd CA certificate and key files [certificates] Using the existing ca certificate and key. INFO[0000] 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 [k2.node] and IPs [172.16.10.22 127.0.0.1] INFO[0000] 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 [k2.node] and IPs [172.16.10.22] INFO[0000] creating a new client certificate for the etcdctl [certificates] Generated etcdctl-etcd-client certificate and key. INFO[0001] 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[0001] [membership] Checking if this member was added INFO[0001] [membership] Member was not added INFO[0001] Removing existing data dir "/var/lib/etcd" INFO[0001] [membership] Adding member INFO[0001] [membership] Checking if member was started INFO[0001] [membership] Member was not started INFO[0001] [membership] Removing existing data dir "/var/lib/etcd" INFO[0001] [install] extracting etcd archive /var/cache/etcdadm/etcd/v3.3.8/etcd-v3.3.8-linux-amd64.tar.gz to /tmp/etcd315786364 INFO[0003] [install] verifying etcd 3.3.8 is installed in /opt/bin/ INFO[0006] [health] Checking local etcd endpoint health INFO[0006] [health] Local etcd endpoint is healthy
其实很久以前由于我自己部署方式导致了我一直以来理解的一个错误,我一直以为 etcd server 证书要包含所有 server 地址,当然这个想法是怎么来的我也不知道,但是当我看了以下 Join 操作源码以后突然意识到 “为什么要包含所有?包含当前 server 不就行了么。”;当然对于 HTTPS 证书的理解一直是明白的,但是很奇怪就是不知道怎么就产生了这个想法(哈哈,我自己都觉的不可思议)…
由于预先拷贝了 ca 证书,所以 join 开始前 etcdadm 使用这个 ca 证书会签发自己需要的所有证书。