|NO.Z.00082|——————————|^^ 部署 ^^|——|KuberNetes&kubeadm.V11|5臺Server|---------------------------------------|kubernetes元件|calico|
阿新 • • 發佈:2022-03-29
[CloudNative:KuberNetes&kubeadm.V11] [Applications.KuberNetes] [|DevOps|k8s|**5節點**|kubeadm.v1.21.2|kubernetes元件|calico|]
一、kubernetes元件安裝
### --- 下載元件安裝原始碼包:下載版本包——在k8s-master01節點執行 ~~~ 現在k8s-ha-install版本包 [root@k8s-master01 ~]# cd /root/ ; git clone https://github.com/dotbalo/k8s-ha-install.git Cloning into 'k8s-ha-install'... remote: Enumerating objects: 652, done. remote: Counting objects: 100% (220/220), done. remote: Compressing objects: 100% (141/141), done. remote: Total 652 (delta 109), reused 141 (delta 62), pack-reused 432 Receiving objects: 100% (652/652), 19.60 MiB | 6.12 MiB/s, done. Resolving deltas: 100% (256/256), done.
二、calico元件安裝——k8s-master01節點執行### --- 切換到manual-installation-v1.21.x分支下 ~~~ 切換到1.21.x版本分支 [root@k8s-master01 ~]# cd /root/k8s-ha-install && git checkout manual-installation-v1.21.x Branch manual-installation-v1.21.x set up to track remote branch manual-installation-v1.21.x from origin. Switched to a new branch 'manual-installation-v1.21.x'
### --- 切換到1.21.x版本分支下並進入到calico安裝目錄下 ~~~ 切換到1.21.x版本分支 [root@k8s-master01 ~]# cd /root/k8s-ha-install && git checkout manual-installation-v1.21.x && cd calico/ Branch manual-installation-v1.21.x set up to track remote branch manual-installation-v1.21.x from origin. Switched to a new branch 'manual-installation-v1.21.x'
### --- 修改calico-etcd.yaml配置檔案
[root@k8s-master01 calico]# sed -i 's#etcd_endpoints: "http://<ETCD_IP>:<ETCD_PORT>"#etcd_endpoints: "https://192.168.1.11:2379,https://192.168.1.12:2379,https://192.168.1.13:2379"#g' calico-etcd.yaml
[root@k8s-master01 calico]# ETCD_CA=`cat /etc/kubernetes/pki/etcd/ca.crt | base64 | tr -d '\n'`
[root@k8s-master01 calico]# ETCD_CERT=`cat /etc/kubernetes/pki/etcd/server.crt | base64 | tr -d '\n'`
[root@k8s-master01 calico]# ETCD_KEY=`cat /etc/kubernetes/pki/etcd/server.key | base64 | tr -d '\n'`
[root@k8s-master01 calico]# sed -i "s@# etcd-key: null@etcd-key: ${ETCD_KEY}@g; s@# etcd-cert: null@etcd-cert: ${ETCD_CERT}@g; s@# etcd-ca: null@etcd-ca: ${ETCD_CA}@g" calico-etcd.yaml
[root@k8s-master01 calico]# sed -i 's#etcd_ca: ""#etcd_ca: "/calico-secrets/etcd-ca"#g; s#etcd_cert: ""#etcd_cert: "/calico-secrets/etcd-cert"#g; s#etcd_key: "" #etcd_key: "/calico-secrets/etcd-key" #g' calico-etcd.yaml
[root@k8s-master01 calico]# POD_SUBNET=`cat /etc/kubernetes/manifests/kube-controller-manager.yaml | grep cluster-cidr= | awk -F= '{print $NF}'`
[root@k8s-master01 calico]# echo $POD_SUBNET //pod的網段是寫在controller-manager下的kube-controller-manager.yaml,直接定義變數即可
172.168.0.0/12
[root@k8s-master01 calico]# sed -i 's@# - name: CALICO_IPV4POOL_CIDR@- name: CALICO_IPV4POOL_CIDR@g; s@# value: "192.168.0.0/16"@ value: '"${POD_SUBNET}"'@g' calico-etcd.yaml
### --- 注意:pod地址更改說明——不執行
~~~ # pod地址說明:注意下面的這個步驟是把calico-etcd.yaml檔案裡面的CALICO_IPV4POOL_CIDR下的網段改成自己的Pod網段,也就是把192.168.x.x/16改成自己的叢集網段,並開啟註釋:
[root@k8s-master01 calico]# vim calico-etcd.yaml
- name: CALICO_IPV4POOL_CIDR
value: "192.168.0.0/12"
~~~ # 所以更改的時候請確保這個步驟的這個網段沒有被統一替換掉,如果被替換掉了,還請改回來:
[root@k8s-master01 calico]# sed -i 's@# - name: CALICO_IPV4POOL_CIDR@- name: CALICO_IPV4POOL_CIDR@g; s@# value: "192.168.0.0/12"@ value: '"${POD_SUBNET}"'@g' calico-etcd.yaml
### --- 檢視calico-etcd.yaml配置是否生效
[root@k8s-master01 calico]# pwd
/root/k8s-ha-install/calico
[root@k8s-master01 calico]# vim calico-etcd.yaml
~~~ 註釋一:key,cert,ca已經匯入進來
etcd-key: LS0tLS1CRUdJTiBSU0EgU
etcd-cert: LS0tLS1CRUdJTiBDRVJUSUZJQ0
etcd-ca: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t
~~~ 註釋二:endpoints已經更改完成
etcd_endpoints: "https://192.168.1.11:2379,https://192.168.1.12:2379,https://192.168.1.13:2379"
~~~ 註釋三:pod地址已經更改完成
- name: CALICO_IPV4POOL_CIDR
value: "192.168.0.0/12"
### --- 部署calico元件
~~~ 部署calico元件服務
[root@k8s-master01 calico]# kubectl apply -f calico-etcd.yaml
secret/calico-etcd-secrets created
configmap/calico-config created
clusterrole.rbac.authorization.k8s.io/calico-kube-controllers created
clusterrolebinding.rbac.authorization.k8s.io/calico-kube-controllers created
clusterrole.rbac.authorization.k8s.io/calico-node created
clusterrolebinding.rbac.authorization.k8s.io/calico-node created
daemonset.apps/calico-node created
serviceaccount/calico-node created
deployment.apps/calico-kube-controllers created
serviceaccount/calico-kube-controllers created
三、檢視服務及叢集狀態### --- 檢視calico是否部署成功
~~~ 檢視calico元件是否啟動完成
[root@k8s-master01 ~]# kubectl get po -n kube-system -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
calico-kube-controllers-cdd5755b9-hjkcq 1/1 Running 0 2m39s 192.168.1.15 k8s-node02 <none> <none>
calico-node-jsprh 1/1 Running 0 2m39s 192.168.1.12 k8s-master02 <none> <none>
calico-node-n97ff 1/1 Running 0 2m39s 192.168.1.11 k8s-master01 <none> <none>
calico-node-tk4kz 1/1 Running 0 2m39s 192.168.1.15 k8s-node02 <none> <none>
calico-node-vfcxf 1/1 Running 0 2m39s 192.168.1.13 k8s-master03 <none> <none>
calico-node-wvwbh 1/1 Running 0 2m39s 192.168.1.14 k8s-node01 <none> <none>
### --- 檢視node節點狀態
~~~ 檢視node節點狀態是否為ready
[root@k8s-master01 ~]# kubectl get node -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master01 Ready control-plane,master 69m v1.21.2 192.168.1.11 <none> CentOS Linux 7 (Core) 4.19.12-1.el7.elrepo.x86_64 docker://19.3.15
k8s-master02 Ready control-plane,master 48m v1.21.2 192.168.1.12 <none> CentOS Linux 7 (Core) 4.19.12-1.el7.elrepo.x86_64 docker://19.3.15
k8s-master03 Ready control-plane,master 33m v1.21.2 192.168.1.13 <none> CentOS Linux 7 (Core) 4.19.12-1.el7.elrepo.x86_64 docker://19.3.15
k8s-node01 Ready <none> 25m v1.21.2 192.168.1.14 <none> CentOS Linux 7 (Core) 4.19.12-1.el7.elrepo.x86_64 docker://19.3.15
k8s-node02 Ready <none> 23m v1.21.2 192.168.1.15 <none> CentOS Linux 7 (Core) 4.19.12-1.el7.elrepo.x86_64 docker://19.3.15
===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)