标签:art host worker 替换 ini 需要 创建 tor image
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>
如何将Rancher 2.1.x 从单节点安装迁移到高可用安装
标签:art host worker 替换 ini 需要 创建 tor image
原文地址:http://blog.51cto.com/12462495/2347802