1.官方提供的三種部署方式
2.Kubernetes 平臺環境規劃
3.自籤SSL證書
4.Etcd數 據庫集羣部署
5.Node安裝Docker
6.Flannel容 器集羣網絡部署
7.部署Master組件
8.部署Node組件
9.部署一個測試示例
10.部署Web UI (Dashboard )
11.部署集羣內部DNS解析服務(CoreDNS)node
minikubelinux
Minikube是一個工具,能夠在本地快速運行-一個單點的Kubernetes,僅用子嘗試Kubemnetes或平常開發的用戶使用。部署地址: htps://kubernetese io/docs/setup/minikube/git
kubeadmgithub
Kubeadm也是一個工具,揭供kubeadm init和ukubeadm join,用於快速部署Kubermnetes集羣,部署地址:htpst/:/ubee/es.cs/do/s/cference/scetup tos/kubedm/kubeadm/算法
二進制包docker
推薦,從官方下載發打版的二進制包,手動部署每一個組件,組成Kubermetes集羣。 下載地址:htpts//github.com/kubemetes/kuberetes/teleasesshell
單Master集羣架構圖
數據庫
組件 | 使用的證書 |
---|---|
etcd | capem, server.pem, server-key.pem |
flannel | ca.pem,server.pem, server-key.pem |
kube-apiserver | ca.pem. server.pem. server-key.pem |
kubelet | ca.pem, ca-key.pem |
kube-proxy | ca.pem, kube-proxy pem, kube-proxy-key.pem |
kubectl | ca.pem, admin.pem, admin-key.pem |
etcd是CoreOS團隊於2013年6月發起的開源項目,它的目標是構建一個高可用的分佈式鍵值(key-value)數據庫。etcd內部採用raft協議做爲一致性算法,etcd基於Go語言實現。json
etcd做爲服務發現系統,有如下的特色:vim
簡單:安裝配置簡單,並且提供了HTTP API進行交互,使用也很簡單
安全:支持SSL證書驗證
快速:根據官方提供的benchmark數據,單實例支持每秒2k+讀操做
可靠:採用raft算法,實現分佈式系統數據的可用性和一致性
一個強一致性、高可用的服務存儲目錄。
基於Ralf算法的etcd天生就是這樣一個強一致性、高可用的服務存儲目錄。
一種註冊服務和健康服務健康情況的機制。
用戶能夠在etcd中註冊服務,而且對註冊的服務配置key TTL,定時保持服務的心跳以達到監控健康狀態的效果。
/opt/etcd/bin/etcdctl \ --a-file=ca.pem -crt-file=server.pem --key-file= server-key.pem \ --endpoints=*https://192.168.0.x:2379.https://192.168.0.x:2379,https://192.168.0x:2379" \ cluster-health
主機 | 須要安裝的軟件 |
---|---|
master(192.168.142.129/24) | kube-apiserver、kube-controller-manager、kube-scheduler、etcd |
node01(192.168.142.130/24) | kubelet、kube-proxy、docker、flannel、etcd |
node02(192.168.142.131/24) | kubelet、kube-proxy、docker 、flannel 、etcd |
將上述的壓縮包複製到centos7的下面即將建立的k8s目錄中
mkdir k8s cd k8s/ mkdir etcd-cert mv etcd-cert.sh etcd-cert
vim cfssl.sh curl -L https:#pkg.cfssl.org/R1.2/cfssl_linux-amd64 -o /usr/local/bin/cfssl curl -L https:#pkg.cfssl.org/R1.2/cfssljson_linux-amd64 -o /usr/local/bin/cfssljson curl -L https:#pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 -o /usr/local/bin/cfssl-certinfo chmod +x /usr/local/bin/cfssl /usr/local/bin/cfssljson /usr/local/bin/cfssl-certinfo
bash cfssl.sh
cfssl 生成證書工具 cfssljson 經過傳入json文件生成證書 cfssl-certinfo 查看證書信息
cd etcd-cert/
cat > ca-config.json <<EOF { "signing": { "default": { "expiry": "87600h" }, "profiles": { "www": { "expiry": "87600h", "usages": [ "signing", "key encipherment", "server auth", "client auth" ] } } } } EOF
cat > ca-csr.json <<EOF { "CN": "etcd CA", "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "L": "Beijing", "ST": "Beijing" } ] } EOF
cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
cat > server-csr.json <<EOF { "CN": "etcd", "hosts": [ "192.168.142.129", "192.168.142.130", "192.168.142.131" ], "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "L": "BeiJing", "ST": "BeiJing" } ] } EOF
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=www server-csr.json | cfssljson -bare server
tar zxvf etcd-v3.3.10-linux-amd64.tar.gz
mkdir /opt/etcd/{cfg,bin,ssl} -p mv etcd-v3.3.10-linux-amd64/etcd etcd-v3.3.10-linux-amd64/etcdctl /opt/etcd/bin/
cp etcd-cert/*.pem /opt/etcd/ssl/
bash etcd.sh etcd01 192.168.142.129 etcd02=https:#192.168.142.130:2380,etcd03=https:#192.168.142.131:2380
ps -ef | grep etcd
scp -r /opt/etcd/ root@192.168.142.130:/opt/ scp -r /opt/etcd/ root@192.168.142.131:/opt/
scp /usr/lib/systemd/system/etcd.service root@192.168.142.130:/usr/lib/systemd/system/ scp /usr/lib/systemd/system/etcd.service root@192.168.142.131:/usr/lib/systemd/system/
vim /opt/etcd/cfg/etcd
#[Member] ETCD_NAME="etcd02" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https:#192.168.142.130:2380" ETCD_LISTEN_CLIENT_URLS="https:#192.168.142.130:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https:#192.168.142.130:2380" ETCD_ADVERTISE_CLIENT_URLS="https:#192.168.142.130:2379" ETCD_INITIAL_CLUSTER="etcd01=https:#192.168.142.129:2380,etcd02=https:#192.168.142.130:2380,etcd03=https:#192.168.142.131:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
systemctl start etcd systemctl status etcd
vim /opt/etcd/cfg/etcd
#[Member] ETCD_NAME="etcd03" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https:#192.168.142.131:2380" ETCD_LISTEN_CLIENT_URLS="https:#192.168.142.131:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https:#192.168.142.131:2380" ETCD_ADVERTISE_CLIENT_URLS="https:#192.168.142.131:2379" ETCD_INITIAL_CLUSTER="etcd01=https:#192.168.142.129:2380,etcd02=https:#192.168.142.130:2380,etcd03=https:#192.168.142.131:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
systemctl start etcd systemctl status etcd
/opt/etcd/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https:#192.168.142.129:2379,https:#192.168.142.130:2379,https:#192.168.142.131:2379" cluster-health
member 3eae9a550e2e3ec is healthy: got healthy result from https:#192.168.142.129:2379 member 26cd4dcf17bc5cbd is healthy: got healthy result from https:#192.168.142.130:2379 member 2fcd2df8a9411750 is healthy: got healthy result from https:#192.168.142.131:2379 cluster is healthy