etcd集群證書安裝過程一


為確保安全,kubernetes 系統各組件需要使用 x509 證書對通信進行加密和認證。

CA (Certificate Authority) 是自簽名的根證書,用來簽名后續創建的其它證書。

本文檔使用 CloudFlare 的 PKI 工具集 cfssl 創建所有證書。

 

創建證書目錄:
sudo mkdir -p /opt/k8s/cert && sudo chown -R k8s /opt/k8s && cd /opt/k8s


安裝cfssl工具集:
wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 mv cfssl_linux-amd64 /opt/k8s/bin/cfssl wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 mv cfssljson_linux-amd64 /opt/k8s/bin/cfssljson




 bin/cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes etcd-csr.json | bin/cfssljson -bare etcd

完整的etcd.service服務配置如下:
 sudo cat /etc/systemd/system/etcd.service 
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
Documentation=https://github.com/coreos

[Service]
User=k8s
Type=notify
WorkingDirectory=/var/lib/etcd/
ExecStart=/opt/k8s/bin/etcd --data-dir=/var/lib/etcd --name=kubemaster --cert-file=/etc/etcd/cert/etcd.pem --key-file=/etc/etcd/cert/etcd-key.pem --trusted-ca-file=/etc/kubernetes/cert/ca.pem  --peer-cert-file=/etc/etcd/cert/etcd.pem --peer-key-file=/etc/etcd/cert/etcd-key.pem --peer-trusted-ca-file=/etc/kubernetes/cert/ca.pem --peer-client-cert-auth --client-cert-auth --listen-peer-urls https://10.10.32.102:2380 --listen-client-urls https://10.10.32.102:2379,http://127.0.0.1:2379 --advertise-client-urls https://10.10.32.102:2379 --initial-cluster-token=etcd-cluster-0 --initial-advertise-peer-urls https://10.10.32.102:2380 --initial-cluster kubemaster=https://10.10.32.102:2380,kube3=https://10.10.45.78:2380,kube2=https://10.10.61.55:2380 --initial-cluster-state=new
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

 

查看x509證書有效性:

openssl x509  -noout -text -in   etcd-key.pem

 

etcd版本號:

 

查看etcd節點健康狀態:
ETCDCTL_API=3 bin/etcdctl --endpoints=https://10.10.32.102:2379 --cacert=/etc/kubernetes/cert/ca.pem --cert=/etc/etcd/cert/etcd.pem --key=/etc/etcd/cert/etcd-key.pem endpoint health   
查看etcd成員:
ETCDCTL_API=3 bin/etcdctl --endpoints=https://10.10.61.55:2379 --cacert=/etc/kubernetes/cert/ca.pem --cert=/etc/etcd/cert/etcd.pem --key=/etc/etcd/cert/etcd-key.pem member list


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM