利用Helm部署高可用rancher集群-創(chuàng)新互聯(lián)

一、背景

Rancher HA有多種部署方式:

站在用戶的角度思考問題,與客戶深入溝通,找到安康網(wǎng)站設(shè)計(jì)與安康網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋安康地區(qū)。
  1. Helm HA安裝,將Rancher部署在已有的Kubernetes集群中,Rancher將使用集群的etcd存儲數(shù)據(jù),并利用Kubernetes調(diào)度實(shí)現(xiàn)高可用性。
  2. RKE HA安裝,使用RKE工具安裝獨(dú)立的Kubernetes集群,專門用于Rancher HA部署運(yùn)行,RKE HA安裝僅支持Rancher v2.0.8以及之前的版本,Rancher v2.0.8之后的版本使用helm安裝Rancher。
    本方案將基于已有的Kubernetes集群,利用Helm安裝Rancher HA,并采用四層負(fù)載均衡方式。
    利用Helm部署高可用rancher集群

    二、添加Chart倉庫地址

    使用helm repo add命令添加Rancher chart倉庫地址
    Rancher tag和Chart版本選擇參考:https://www.cnrancher.com/docs/rancher/v2.x/cn/installation/server-tags/

    #替換<CHART_REPO>為您要使用的Helm倉庫分支(即latest或stable)。
    helm repo add rancher-stable https://releases.rancher.com/server-charts/stable

    三、使用自簽名證書安裝Rancher server

    Rancher server設(shè)計(jì)默認(rèn)需要開啟SSL/TLS配置來保證安全,將ssl證書以Kubernetes Secret卷的形式傳遞給rancher server或Ingress Controller。首先創(chuàng)建證書密文,以便Rancher和Ingress Controller可以使用。

    1、 生成自簽名證書

    #腳本
    一鍵生成自簽名證書腳本
    #執(zhí)行腳本生成證書
    sh create_self-signed-cert.sh --ssl-domain=rancher.sumapay.com --ssl-trusted-ip=172.16.1.21,172.16.1.22 --ssl-size=2048 --ssl-date=3650

2、使用kubectl創(chuàng)建tls類型的secrets

#創(chuàng)建命名空間

[root@k8s-master03 ~]# kubectl create namespace cattle-system
namespace/rancher-system created

#服務(wù)證書和私鑰密文

[root@k8s-master03 self_CA]# kubectl -n cattle-system create secret tls tls-rancher-ingress --cert=./tls.crt --key=./tls.key 
secret/tls-rancher-ingress created

#ca證書密文

[root@k8s-master03 self_CA]# kubectl -n cattle-system create secret generic tls-ca --from-file=cacerts.pem 
secret/tls-ca created

3、安裝rancher server

#使用helm安裝rancher HA

[root@k8s-master03 ~]# helm install rancher-stable/rancher --name rancher2 --namespace cattle-system --set hostname=rancher.sumapay.com --set ingress.tls.source=secret --set privateCA=true
NAME:   rancher2
LAST DEPLOYED: Fri Apr 26 14:03:51 2019
NAMESPACE: cattle-system
STATUS: DEPLOYED

RESOURCES:
==> v1/ClusterRoleBinding
NAME     AGE
rancher2  0s

==> v1/Deployment
NAME     READY  UP-TO-DATE  AVAILABLE  AGE
rancher2  0/3    3           0          0s

==> v1/Pod(related)
NAME                      READY  STATUS             RESTARTS  AGE
rancher-55c884bbf7-2xqpl  0/1    ContainerCreating  0         0s
rancher-55c884bbf7-bqvjh  0/1    ContainerCreating  0         0s
rancher-55c884bbf7-hhlvh  0/1    ContainerCreating  0         0s

==> v1/Service
NAME     TYPE       CLUSTER-IP      EXTERNAL-IP  PORT(S)  AGE
rancher2  ClusterIP  10.110.148.105  <none>       80/TCP   0s

==> v1/ServiceAccount
NAME     SECRETS  AGE
rancher2  1        0s

==> v1beta1/Ingress
NAME     HOSTS                ADDRESS  PORTS  AGE
rancher2  rancher.sumapay.com  80, 443  0s

NOTES:
Rancher Server has been installed.

NOTE: Rancher may take several minutes to fully initialize. Please standby while Certificates are being issued and Ingress comes up.

Check out our docs at https://rancher.com/docs/rancher/v2.x/en/

Browse to https://rancher.sumapay.com

Happy Containering!

#查看創(chuàng)建

[root@k8s-master03 ~]# kubectl get ns
NAME                         STATUS   AGE
cattle-global-data           Active   2d5h
cattle-system                Active   2d5h

[root@k8s-master03 ~]# kubectl get ingress -n cattle-system           
NAME       HOSTS                 ADDRESS   PORTS     AGE
rancher2   rancher.sumapay.com             80, 443   57m

[root@k8s-master03 ~]# kubectl get service -n cattle-system        
NAME       TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
rancher2   ClusterIP   10.111.16.80   <none>        80/TCP    54m

[root@k8s-master03 ~]# kubectl get serviceaccount -n cattle-system           
NAME       TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
rancher2   ClusterIP   10.111.16.80   <none>        80/TCP    51m

[root@k8s-master03 ~]# kubectl get ClusterRoleBinding -n cattle-system -l app=rancher2 -o wide
NAME       AGE   ROLE                        USERS   GROUPS   SERVICEACCOUNTS
rancher2   58m   ClusterRole/cluster-admin                    cattle-system/rancher2

[root@k8s-master03 ~]# kubectl get pods -n cattle-system 
NAME                                    READY   STATUS    RESTARTS   AGE
cattle-cluster-agent-594b8f79bb-pgmdt   1/1     Running   5          2d2h
cattle-node-agent-lg44f                 1/1     Running   0          2d2h
cattle-node-agent-zgdms                 1/1     Running   5          2d2h
rancher2-9774897c-622sc                 1/1     Running   0          50m
rancher2-9774897c-czxxx                 1/1     Running   0          50m
rancher2-9774897c-sm2n5                 1/1     Running   0          50m

[root@k8s-master03 ~]# kubectl get deployment -n cattle-system 
NAME                   READY   UP-TO-DATE   AVAILABLE   AGE
cattle-cluster-agent   1/1     1            1           2d4h
rancher2               3/3     3            3           55m

4、為Agent Pod添加主機(jī)別名(/etc/hosts)

如果你沒有內(nèi)部DNS服務(wù)器而是通過添加/etc/hosts主機(jī)別名的方式指定的Rancher server域名,那么不管通過哪種方式(自定義、導(dǎo)入、Host驅(qū)動等)創(chuàng)建K8S集群,K8S集群運(yùn)行起來之后,因?yàn)閏attle-cluster-agent Pod和cattle-node-agent無法通過DNS記錄找到Rancher server,最終導(dǎo)致無法通信。

解決方法

可以通過給cattle-cluster-agent Pod和cattle-node-agent添加主機(jī)別名(/etc/hosts),讓其可以正常通信(前提是IP地址可以互通)。

#cattle-cluster-agent pod
kubectl -n cattle-system \
patch deployments cattle-cluster-agent --patch '{
    "spec": {
        "template": {
            "spec": {
                "hostAliases": [
                    {
                        "hostnames":
                        [
                            "rancher.sumapay.com"
                        ],
                            "ip": "四層負(fù)載均衡地址"
                    }
                ]
            }
        }
    }
}'

#cattle-node-agent pod
kubectl -n cattle-system \
patch  daemonsets cattle-node-agent --patch '{
    "spec": {
        "template": {
            "spec": {
                "hostAliases": [
                    {
                        "hostnames":
                        [
                            "rancher.sumapay.com"
                        ],
                            "ip": "四層負(fù)載均衡地址"
                    }
                ]
            }
        }
    }
}'

至此,rancher HA已部署完畢,由于不是NodePort形式,在沒有部署ingress-controller情況下,我們還不能直接去訪問rancher服務(wù)。
ingress-controller部署請參考traefik部署與使用。

參考:
https://www.cnrancher.com/docs/rancher/v2.x/cn/installation/ha-install/helm-rancher/tcp-l4/rancher-install/

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

當(dāng)前文章:利用Helm部署高可用rancher集群-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://muchs.cn/article32/dphssc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、ChatGPT、品牌網(wǎng)站制作網(wǎng)站維護(hù)、Google、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管