您好,登錄后才能下訂單哦!
Rancher提供了兩種安裝方法,即單節點安裝和高可用安裝。單節點安裝可以讓用戶快速部署適用于短期開發或PoC的Rancher 2.x,而高可用部署則明顯更適合Rancher的長期部署。
要點須知
前期準備
為了順利將單個節點Rancher安裝遷移到高可用性安裝,您必須做如下準備:
(https://rancher.com/docs/rancher/v2.x/en/installation/ha/#recommended-architecture )
遷移教程
從Rancher的單個節點遷移到高可用性安裝的過程可以總結為以下幾個步驟:
在Rancher單節點實例上
1、 備份Rancher單節點容器
2、 使用單節點容器中找到的證書組裝pki.bundle.tar.gz
3、 運行臨時utility容器以執行容器內運行的嵌入式etcd的etcd快照
4、 停止舊的Rancher單節點容器
5、 將server-url的DNS記錄更改為指向新的HA負載均衡器
在您的工作站或者bastion host上
1、 將生成的pki.bundle.tar.gz和single-node-etcd-snapshot從Rancher單節點實例傳輸到工作目錄中的工作站上(工作目錄原先最好是空的)
2、 生成指向新HA節點的rke集群配置文件
3、 rke etcd snapshot-restore從單節點容器中檢索快照
4、 rke up
5、 根據文檔在HA中安裝Rancher
開始之前
在整個教程中,您將輸入一系列命令,以將您環境中的數據替換為占位符。這些占位符用斜角括號和所有大寫字母(<EXAMPLE>)表示。
下表是找到本教程中使用的各種占位符。請您在開始之前記下此信息,這將有助于您后續的操作。
在Rancher單節點實例上
步驟1 備份Rancher單節點容器
首先,您應該備份Rancher單節點容器,以確保在遷移過程中遇到問題時可以回滾到此前運行的Rancher單節點。有關這方面的更多信息,請參閱:
https://rancher.com/docs/rancher/v2.x/en/backups/backups/single-node-backups/
步驟2 使用單節點容器中找到的證書組裝pki.bundle.tar.gz
首先,鍵入docker exec,進入Rancher容器:
[root@single-node-rancher ~]# docker exec -it <RANCHER_CONTAINER_NAME> /bin/bash
進入容器后,將/ etc / kubernetes / ssl目錄tar到pki.bundle.tar.gz:
root@9f4b1729d8ca:/var/lib/rancher# tar -zcvf pki.bundle.tar.gz /etc/kubernetes/ssl
root@9f4b1729d8ca:/var/lib/rancher# exit
將剛剛生成的pki.bundle.tar.gz轉移到單節點實例上的當前工作目錄:
[root@single-node-rancher ~]# docker cp <RANCHER_CONTAINER_NAME>:/var/lib/rancher/pki.bundle.tar.gz .
步驟3 運行臨時utility容器以執行容器內運行的嵌入式etcd的etcd快照
docker運行一個名為etcd-utility的臨時rke-tools容器,并附加了Rancher容器網絡。此外,還掛載當前工作目錄(將pki.bundle.tar.gz放入其中:
docker run --net=container:<RANCHER_CONTAINER_NAME> -it -v $(pwd):/cwd --name etcd-utility rancher/rke-tools:v0.1.20
在此容器中創建一個名為ssl的文件夾,然后將pki.bundle.tar.gz解壓到:
bash-4.4# mkdir ssl && cd ssl
bash-4.4# cp /cwd/pki.bundle.tar.gz .
bash-4.4# tar -zxvf pki.bundle.tar.gz --strip-components 3
將單節點etcd快照到一個名為single-node-etcd-snapshot的文件中
bash-4.4# cd /
bash-4.4# ETCDCTL_API=3 etcdctl snapshot save --cacert=/ssl/kube-ca.pem --cert=/ssl/kube-etcd-127-0-0-1.pem --key=/ssl/kube-etcd-127-0-0-1-key.pem single-node-etcd-snapshot
bash-4.4# exit
將etcd快照從etcd-utility容器復制到當前工作目錄
[root@single-node-rancher ~]# docker cp etcd-utility:/single-node-etcd-snapshot .
單節點實例上的當前工作目錄應包含兩個文件:pki.bundle.tar.gz和single-node-etcd-snapshot。這是將Rancher從單節點遷移到HA所需的兩個組件。
步驟4 停止舊的Rancher單節點容器
[root@single-node-rancher ~]# docker stop <RANCHER_CONTAINER_NAME>
步驟5 將server-url的DNS記錄更改為指向新的HA負載均衡器
為了正確遷移Rancher,您應該更新DNS基礎結構中的DNS記錄,以將Rancher server-url指向新的HA負載均衡器。
在您的工作站或者bastion host上
將生成的pki.bundle.tar.gz和single-node-etcd-snapshot從Rancher單節點實例傳輸到工作目錄中的工作站上(工作目錄最好原先就是空的)
Endeavor:single-node-to-ha-migration chriskim$ scp root@<RANCHER_SINGLE_NODE_HOST>:/root/pki.bundle.tar.gz .
Endeavor:single-node-to-ha-migration chriskim$ scp root@<RANCHER_SINGLE_NODE_HOST>:/root/single-node-etcd-snapshot .
生成指向您的新HA節點的rke集群配置文件
舉個例子,rancher-cluster.yml文件如下所示:
nodes:
- address: <RANCHER_HA_HOST_1> user: centos role: [controlplane,worker,etcd]services:
etcd:
snapshot: true
creation: 6h
retention: 24h
在所需的HA節點上創建/ opt / rke / etcd-snapshots目錄,并將single-node-etcd-snapshot和pki.bundle.tar.gz文件復制到該目錄:
Endeavor:single-node-to-ha-migration chriskim$ ssh root@<RANCHER_HA_HOST_1> "mkdir -p /opt/rke/etcd-snapshots"Endeavor:single-node-to-ha-migration chriskim$ scp pki.bundle.tar.gz root@<RANCHER_HA_HOST_1>:/opt/rke/etcd-snapshots
Endeavor:single-node-to-ha-migration chriskim$ scp single-node-etcd-snapshot root@<RANCHER_HA_HOST_1>:/opt/rke/etcd-snapshots
使用RKE將 single-node- etcd-snapshot恢復到新的HA節點:
rke etcd snapshot-restore --name single-node-etcd-snapshot --config rancher-cluster.yml
完整命令行如下:
INFO[0000] Starting restoring snapshot on etcd hosts
INFO[0000] [dialer] Setup tunnel for host [ha-rancher01.fmt01.rancher.com]
INFO[0000] [hosts] Cleaning up host [ha-rancher01.fmt01.rancher.com]
INFO[0000] [hosts] Running cleaner container on host [ha-rancher01.fmt01.rancher.com]
INFO[0000] [kube-cleaner] Pulling image [rancher/rke-tools:v0.1.15] on host [ha-rancher01.fmt01.rancher.com]
INFO[0004] [kube-cleaner] Successfully pulled image [rancher/rke-tools:v0.1.15] on host [ha-rancher01.fmt01.rancher.com]
INFO[0004] [kube-cleaner] Successfully started [kube-cleaner] container on host [ha-rancher01.fmt01.rancher.com]
INFO[0004] [hosts] Removing cleaner container on host [ha-rancher01.fmt01.rancher.com]
INFO[0004] [hosts] Removing dead container logs on host [ha-rancher01.fmt01.rancher.com]
INFO[0005] [cleanup] Successfully started [rke-log-cleaner] container on host [ha-rancher01.fmt01.rancher.com]
INFO[0005] [remove/rke-log-cleaner] Successfully removed container on host [ha-rancher01.fmt01.rancher.com]
INFO[0005] [hosts] Successfully cleaned up host [ha-rancher01.fmt01.rancher.com]
INFO[0005] [etcd] Restoring [single-node-etcd-snapshot] snapshot on etcd host [ha-rancher01.fmt01.rancher.com]
INFO[0005] [etcd] Pulling image [rancher/coreos-etcd:v3.2.18] on host [ha-rancher01.fmt01.rancher.com]
INFO[0007] [etcd] Successfully pulled image [rancher/coreos-etcd:v3.2.18] on host [ha-rancher01.fmt01.rancher.com]
INFO[0007] [etcd] Successfully started [etcd-restore] container on host [ha-rancher01.fmt01.rancher.com]
INFO[0007] [etcd] Building up etcd plane..
INFO[0007] [etcd] Successfully started [etcd] container on host [ha-rancher01.fmt01.rancher.com]
INFO[0007] [etcd] Saving snapshot [etcd-rolling-snapshots] on host [ha-rancher01.fmt01.rancher.com]
INFO[0007] [etcd] Successfully started [etcd-rolling-snapshots] container on host [ha-rancher01.fmt01.rancher.com]
INFO[0012] [certificates] Successfully started [rke-bundle-cert] container on host [ha-rancher01.fmt01.rancher.com]
INFO[0013] [certificates] successfully saved certificate bundle [/opt/rke/etcd-snapshots//pki.bundle.tar.gz] on host [ha-rancher01.fmt01.rancher.com]
INFO[0013] [etcd] Successfully started [rke-log-linker] container on host [ha-rancher01.fmt01.rancher.com]
INFO[0013] [remove/rke-log-linker] Successfully removed container on host [ha-rancher01.fmt01.rancher.com]
INFO[0013] [etcd] Successfully started etcd plane..
INFO[0013] [certificates] Successfully started [rke-bundle-cert] container on host [ha-rancher01.fmt01.rancher.com]
INFO[0013] [certificates] successfully extracted certificate bundle on host [ha-rancher01.fmt01.rancher.com] to backup path [/etc/kubernetes/.tmp/]
INFO[0013] Finished restoring snapshot [single-node-etcd-snapshot] on all etcd hosts
此時,您可以運行rke up --config rancher-cluster.yml,并進行其他HA安裝步驟。強烈建議您立即更改Rancher的DNS記錄,以便在根據HA說明安裝后,您的用戶集群可以連接回Rancher。因此,您可能需要兩次運行rke up --config rancher-cluster.yml以確保所有插件運行都成功。
在成功安裝Kubernetes并將Rancher單節點備份恢復到您的實例后,您可以將其他HA實例添加到rancher-cluster.yml并運行rke up --config rancher-cluster.yml以將這些節點添加到您的集群。
此時,您可以使用此處的文檔繼續安裝Rancher:
https://rancher.com/docs/rancher/v2.x/en/installation/ha/helm-init/
清 理
遷移成功之后就可以開始進行清理工作了。您可以從單個節點實例中移除Rancher容器,也可以直接完全刪除實例。
[root@single-node-rancher ~]# docker rm <RANCHER_CONTAINER_NAME>
回 滾
如果遷移不成功,可以通過以下兩個條件實現回滾:
將server-url的DNS條目更改回單節點Rancher實例;
[root@single-node-rancher ~]# docker start <RANCHER_CONTAINER_NAME>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。