您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關單節點Rancher離線安裝的示例分析,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
Rancher 從 v2.5.x 開始,單節點 Rancher Server 內置了 K3s 作為 local 集群,該 local 集群除了支撐 Rancher Server 運行以外,還將運行 fleet、rancher-webhook、gitjob、coredns 等組件。下圖為 Rancher v2.5.8 內置 K3s 集群默認啟動的組件和所需的鏡像:
其中,docker.io/rancher/coredns-coredns 和 docker.io/rancher/pause 為 Rancher Server 內置的鏡像,其他鏡像需要在 Rancher Server 啟動后到 dockerhub 去在線下載。
如果你的環境是離線環境,并且是通過 docker run 的方式啟動 Rancher Server,會報一些鏡像下載失敗的日志:
E0511 08:39:56.060906 28 pod_workers.go:191] Error syncing pod d0f83155-f023-4ff6-9164-11b6b63ef4d6 ("helm-operation-t8mtl_cattle- system(d0f83155-f023-4ff6-9164-11b6b63ef4d6)"), skipping: [failed to "StartContainer" for "helm" with ImagePullBackOff: "Back- off pulling image \"rancher/shell:v0.1.6\"", failed to "StartContainer" for "proxy" with ImagePullBackOff: "Back-off pulling image \"rancher/shell:v0.1.6\""]
官網文檔單節點離線安裝 Rancher Server(http://docs.rancher.cn/docs/rancher2.5/installation/other-installation-methods/air-gap/install-rancher/_index/#單節點安裝)章節中指出了可以通過CATTLE_SYSTEM_DEFAULT_REGISTRY參數指定從私有鏡像倉庫去獲取 Rancher Server 所需的鏡像,但如果你的私有鏡像倉庫是啟用 TLS或有認證的情況,CATTLE_SYSTEM_DEFAULT_REGISTRY是無法滿足你的需求的。
針對上述場景,我們可以將內置 k3s 集群的**/etc/rancher/k3s/registries.yaml** 映射到宿主機上,然后通過修改registries.yaml來實現啟用 TLS或有認證 等更復雜的場景,關于 k3s 配置私有倉庫,可參考k3s 官網(http://docs.rancher.cn/docs/k3s/installation/private-registry/_index/).
以下章節將指導大家如何通過私有鏡像倉庫在離線環境下安裝單節點 Rancher Server,針對鏡像倉庫類型的不同,分為以下幾種場景:
私有倉庫為 SSL 證書頒發機構頒發的證書(https),有認證
私有倉庫為自簽名證書(https),有認證
私有倉庫不使用 SSL(使用 http),有認證
私有倉庫為 SSL 證書頒發機構頒發的證書(https),有認證
私有倉庫中已經提前上傳了 Rancher Server 所需要的鏡像,如何同步鏡像到私有鏡像倉庫可以參考官方文檔(http://docs.rancher.cn/docs/rancher2.5/installation/other-installation-methods/air-gap/populate-private-registry/_index).
1.配置 K3s registries.yaml
root@ip-172-31-14-159:~# cat /opt/registries.yaml mirrors: # 私有倉庫域名 harbor.kingsd.top: endpoint: - "https://harbor.kingsd.top" configs: "harbor.kingsd.top": auth: username: admin # 這是私有鏡像倉庫的用戶名 password: Password # 這是私有鏡像倉庫的密碼
2.啟動單節點 Rancher Server
root@ip-172-31-14-159:~# docker run -itd --privileged \ > --restart=unless-stopped \ > -p 80:80 -p 443:443 \ > -e CATTLE_SYSTEM_DEFAULT_REGISTRY=harbor.kingsd.top \ # 設置私有倉庫域名 > -v /opt/registries.yaml:/etc/rancher/k3s/registries.yaml \ # 將宿主機`registries.yaml`映射到容器內 > rancher/rancher:v2.5.8
3.驗證
等待 Rancher Server 啟動成功后,我們可以 exec 到容器內確認所需要的組件是否啟動:
root@3fd636aa513e:/var/lib/rancher# kubectl get pods -A NAMESPACE NAME READY STATUS RESTARTS AGE cattle-system helm-operation-5w49g 0/2 Completed 0 3m21s cattle-system helm-operation-gclkp 0/2 Completed 0 3m3s cattle-system helm-operation-jt948 0/2 Completed 0 3m13s cattle-system helm-operation-l76g6 0/2 Completed 0 3m41s cattle-system helm-operation-zmm6f 0/2 Completed 0 3m28s cattle-system rancher-webhook-58b8d9f6c6-bxmns 1/1 Running 0 3m24s fleet-system fleet-agent-7c7d457b6d-x4kvf 1/1 Running 0 2m33s fleet-system fleet-controller-5ddfd96f5c-lxbnt 1/1 Running 0 3m10s fleet-system gitjob-7b4ddfcbf7-6hx52 1/1 Running 0 3m10s kube-system coredns-66c464876b-hfjqk 1/1 Running 0 4m1s rancher-operator-system rancher-operator-5cbfb5d6d7-kq29z 1/1 Running 0 3m32s root@3fd636aa513e:/var/lib/rancher# k3s crictl images IMAGE TAG IMAGE ID SIZE docker.io/rancher/coredns-coredns 1.6.9 4e797b3234604 43.3MB docker.io/rancher/pause 3.1 da86e6ba6ca19 746kB harbor.kingsd.top/rancher/fleet-agent v0.3.5 2a0c55d5db357 55.9MB harbor.kingsd.top/rancher/fleet v0.3.5 981b7123a405f 23.9MB harbor.kingsd.top/rancher/gitjob v0.1.15 dac9b6c58fe07 24.8MB harbor.kingsd.top/rancher/rancher-operator v0.1.4 c18d03bea7c6f 14.5MB harbor.kingsd.top/rancher/rancher-webhook v0.1.0 aec2ca2e747d7 12.6MB harbor.kingsd.top/rancher/shell v0.1.6 2e550736e6a49 46.8MB
可以看到,除了 Rancher Server 內置的 rancher/coredns-coredns 和 rancher/pause 鏡像以外,其他的鏡像都是從 harbor.kingsd.top 拉取。
私有倉庫為自簽名證書(https),有認證
Rancher Server 連接自簽名證書的私有倉庫和 SSL 證書頒發機構的私有倉庫配置的區別主要在于連接自簽名證書的私有倉庫時需要在 k3s 的registries.yaml中指定私有鏡像倉庫的自簽名證書。
1.配置 K3s registries.yaml
root@ip-172-31-14-159:~# cat /opt/registries.yaml mirrors: # 私有倉庫域名 harbor.kingsd.top: endpoint: - "https://harbor.kingsd.top" configs: "harbor.kingsd.top": auth: username: admin # 這是私有鏡像倉庫的用戶名 password: Password # 這是私有鏡像倉庫的密碼 tls: ca_file: /opt/certs/ca.crt # 鏡像倉庫中使用的ca文件的路徑。 cert_file: /opt/certs/harbor.kingsd.top.cert # 鏡像倉庫中使用的cert文件的路徑。 key_file: /opt/certs/harbor.kingsd.top.key # 鏡像倉庫中使用的key文件的路徑。
2.啟動單節點 Rancher Server
root@ip-172-31-14-159:~# docker run -itd --privileged \ > --restart=unless-stopped \ > -p 80:80 -p 443:443 \ > -e CATTLE_SYSTEM_DEFAULT_REGISTRY=harbor.kingsd.top \ # 設置私有倉庫域名 > -v /opt/registries.yaml:/etc/rancher/k3s/registries.yaml \ # 將宿主機`registries.yaml`映射到容器內 > -v /opt/certs:/opt/certs \ # 將證書映射到容器內 > rancher/rancher:v2.5.8
3.驗證
等待 Rancher Server 啟動成功后,我們可以 exec 到容器內確認所需要的組件是否啟動:
root@381b5d2c26d9:/var/lib/rancher# kubectl get pods -A NAMESPACE NAME READY STATUS RESTARTS AGE cattle-system helm-operation-b5mvm 0/2 Completed 0 6m27s cattle-system helm-operation-cdlc8 0/2 Completed 0 5m57s cattle-system helm-operation-hcxmj 0/2 Completed 0 5m47s cattle-system helm-operation-vqz9z 0/2 Completed 0 6m4s cattle-system helm-operation-wqgz9 0/2 Completed 0 6m12s cattle-system rancher-webhook-58b8d9f6c6-z68ps 1/1 Running 0 6m18s fleet-system fleet-agent-7c7d457b6d-zznvd 1/1 Running 0 5m25s fleet-system fleet-controller-5ddfd96f5c-kcqmq 1/1 Running 0 5m53s fleet-system gitjob-7b4ddfcbf7-99l46 1/1 Running 0 5m53s kube-system coredns-66c464876b-mflfv 1/1 Running 0 6m49s rancher-operator-system rancher-operator-5cbfb5d6d7-prsqh 1/1 Running 0 6m9s root@381b5d2c26d9:/var/lib/rancher# k3s crictl images IMAGE TAG IMAGE ID SIZE docker.io/rancher/coredns-coredns 1.6.9 4e797b3234604 43.3MB docker.io/rancher/pause 3.1 da86e6ba6ca19 746kB harbor.kingsd.top/rancher/fleet-agent v0.3.5 2a0c55d5db357 55.9MB harbor.kingsd.top/rancher/fleet v0.3.5 981b7123a405f 23.9MB harbor.kingsd.top/rancher/gitjob v0.1.15 dac9b6c58fe07 24.8MB harbor.kingsd.top/rancher/rancher-operator v0.1.4 c18d03bea7c6f 14.5MB harbor.kingsd.top/rancher/rancher-webhook v0.1.0 aec2ca2e747d7 12.6MB harbor.kingsd.top/rancher/shell v0.1.6 2e550736e6a49 46.8MB
可以看到,除了 Rancher Server 內置的 rancher/coredns-coredns 和 rancher/pause 鏡像以外,其他的鏡像都是從 harbor.kingsd.top 拉取。
私有倉庫不使用 SSL(使用 http),有認證
針對 HTTP 的私有倉庫,只需要將 registries.yaml 里的 mirrors.endpoint 配置修改為http 開頭即可。
1.配置 K3s registries.yaml
root@ip-172-31-14-159:~# cat cat /opt/registries.yaml cat: cat: No such file or directory mirrors: # 私有倉庫IP 3.96.56.137: endpoint: - "http://3.96.56.137" configs: "3.96.56.137": auth: username: admin # 這是私有鏡像倉庫的用戶名 password: Password # 這是私有鏡像倉庫的密碼
2.啟動單節點 Rancher Server
root@ip-172-31-14-159:~# docker run -itd --privileged \ > --restart=unless-stopped \ > -p 80:80 -p 443:443 \ > -e CATTLE_SYSTEM_DEFAULT_REGISTRY=3.96.56.137 \ # 設置私有倉庫IP > -v /opt/registries.yaml:/etc/rancher/k3s/registries.yaml \ # 將宿主機`registries.yaml`映射到容器內 > rancher/rancher:v2.5.8
3.驗證
root@cb018bb70446:/var/lib/rancher# kubectl get pods -A NAMESPACE NAME READY STATUS RESTARTS AGE cattle-system helm-operation-44tb7 0/2 Completed 0 77s cattle-system helm-operation-cwpvz 0/2 Completed 0 66s cattle-system helm-operation-f898m 0/2 Completed 0 58s cattle-system helm-operation-fc4tj 0/2 Completed 0 51s cattle-system helm-operation-qq4kz 0/2 Completed 0 42s cattle-system rancher-webhook-c49756c7f-rjwdj 1/1 Running 0 63s fleet-system fleet-agent-55865c8959-rz8p2 1/1 Running 0 21s fleet-system fleet-controller-797ff98bfd-xj48k 1/1 Running 0 47s fleet-system gitjob-58bdfc4c69-mp84z 1/1 Running 0 47s kube-system coredns-66c464876b-dbm8v 1/1 Running 0 96s rancher-operator-system rancher-operator-578b4c64d4-4ptq9 1/1 Running 0 69s root@cb018bb70446:/var/lib/rancher# k3s crictl images IMAGE TAG IMAGE ID SIZE 3.96.56.137/rancher/fleet-agent v0.3.5 2a0c55d5db357 55.9MB 3.96.56.137/rancher/fleet v0.3.5 981b7123a405f 23.9MB 3.96.56.137/rancher/gitjob v0.1.15 dac9b6c58fe07 24.8MB 3.96.56.137/rancher/rancher-operator v0.1.4 c18d03bea7c6f 14.5MB 3.96.56.137/rancher/rancher-webhook v0.1.0 aec2ca2e747d7 12.6MB 3.96.56.137/rancher/shell v0.1.6 2e550736e6a49 46.8MB docker.io/rancher/coredns-coredns 1.6.9 4e797b3234604 43.3MB docker.io/rancher/pause 3.1 da86e6ba6ca19 746kB
可以看到,除了 Rancher Server 內置的 rancher/coredns-coredns 和 rancher/pause 鏡像以外,其他的鏡像都是從 3.96.56.137 拉取。
關于“單節點Rancher離線安裝的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。