前言
Helm v3提供了很多的新的功能,所以在此考虑对原有的Helm v2进行升级。
如果是自己的测试环境,无需考虑Helm v2配置的迁移、Helm v2版本的迁移,则直接覆盖安装虑Helm v3。但现实情况往往并非如此,我们需要考虑升级的风险,和以前的版本是否兼容等问题,所以我们可以采用官方提供的升级方案如何从Helm v2迁移到Helm v3,helm-2to3 Github。
设置Helm v3
由于我们不想覆盖Helm v2 二进制文件,因此我们需要执行一个附加步骤,以确保两个CLI版本可以共存,直到我们准备删除Helm v2 CLI及其所有相关数据为止:
- 同之前安装Helm一样,这次同样采取二进制压缩包安装,首先下载Helm v3.2.4版本安装包,选择Linux amd64版本:
VIM
[root@centos7 tmp]# wget https://get.helm.sh/helm-v3.2.4-linux-amd64.tar.gz
--2020-07-27 09:43:45-- https://get.helm.sh/helm-v3.2.4-linux-amd64.tar.gz
正在解析主机 get.helm.sh (get.helm.sh)... 152.199.39.108, 2606:2800:247:1cb7:261b:1f9c:2074:3c
正在连接 get.helm.sh (get.helm.sh)|152.199.39.108|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:12926032 (12M) [application/x-tar]
正在保存至: “helm-v3.2.4-linux-amd64.tar.gz”
100%[===================================================================================================================================================>] 12,926,032 41.5KB/s 用时 5m 23s
2020-07-27 09:49:09 (39.1 KB/s) - 已保存 “helm-v3.2.4-linux-amd64.tar.gz” [12926032/12926032])
-
解压缩:
AUTOIT
[root@centos7 tmp]# tar -zxvf helm-v3.2.4-linux-amd64.tar.gz
linux-amd64/
linux-amd64/helm
linux-amd64/README.md
linux-amd64/LICENSE
接下来的一步就是关键了,我们不是直接将解压缩后的helm
文件移动到bin
目录下,而是重命名为helm3
,再移动到bin
目录下。
- 移动helm3文件:
[root@centos7 tmp]# cd linux-amd64/
[root@centos7 linux-amd64]# mv helm helm3
[root@node-0 linux-amd64]# cp helm3 /usr/local/bin/
- 验证安装:
[root@node-0 bin]# helm3 version
version.BuildInfo{Version:"v3.2.4", GitCommit:"0ad800ef43d3b826f31a5ad8dfbb4fe05d143688", GitTreeState:"clean", GoVersion:"go1.13.12"}
查看存储库:
[root@node-0 bin]# helm3 repo list
Error: no repositories to show
到这一步helm3
就安装完毕了,后续使用命令请使用helm3
,但是存储库是空的,说明helm2
里面设置的存储库并没有被helm3
所发现,这就需要后续的迁移操作了。
使用helm-2to3插件迁移
官方是这样进行描述的:
helm-2to3 该插件将使我们能够迁移和清理Helm v2配置并就地发布到Helm v3。
已安装的Kubernetes对象将不会被修改或删除。
当然了,一切的迁移都伴随着风险,请对部分数据进行备份:
执行以下数据备份:
- Helm v2主文件夹。
- 从集群释放数据。
安装helm-2to3插件:
[root@node-0 bin]# helm3 plugin install https://github.com/helm/helm-2to3
Downloading and installing helm-2to3 v0.6.0 ...
https://github.com/helm/helm-2to3/releases/download/v0.6.0/helm-2to3_0.6.0_linux_amd64.tar.gz
查看安装的插件:
[root@node-0 bin]# helm3 plugin list
NAME VERSION DESCRIPTION
2to3 0.6.0 migrate and cleanup Helm v2 configuration and releases in-place to Helm v3
查看该插件具有哪些功能:
[root@node-0 bin]# helm3 2to3
Migrate and Cleanup Helm v2 configuration and releases in-place to Helm v3
Usage:
2to3 [command]
Available Commands:
cleanup cleanup Helm v2 configuration, release data and Tiller deployment
convert migrate Helm v2 release in-place to Helm v3
help Help about any command
move migrate Helm v2 configuration in-place to Helm v3
Flags:
-h, --help help for 2to3
Use "2to3 [command] --help" for more information about a command.
可以看到的是,helm 2to3插件支持:
- 迁移Helm v2配置
- Helm v2版本的迁移
- 清理Helm v2配置,发布数据和Tiller部署
迁移Helm v2配置
我们需要迁移Helm v2配置和数据文件夹,我们先查看一下helm-2to3插件关于迁移的命令描述:
[root@node-0 bin]# helm3 2to3 move -h
migrate Helm v2 configuration in-place to Helm v3
Usage:
2to3 move config [flags]
Flags:
--dry-run simulate a command
-h, --help help for move
发现一个很有意思的地方,首先我们需要使用helm3 2to3 move config
来进行迁移,其次,可以加入后缀--dry-run
来模拟迁移,我们可以试验一下:
[root@node-0 bin]# helm3 2to3 move config --dry-run
2020/07/27 10:41:56 NOTE: This is in dry-run mode, the following actions will not be executed.
2020/07/27 10:41:56 Run without --dry-run to take the actions described below:
2020/07/27 10:41:56
2020/07/27 10:41:56 WARNING: Helm v3 configuration may be overwritten during this operation.
2020/07/27 10:41:56
[Move Config/confirm] Are you sure you want to move the v2 configuration? [y/N]: y
2020/07/27 10:41:59
Helm v2 configuration will be moved to Helm v3 configuration.
2020/07/27 10:41:59 [Helm 2] Home directory: /root/.helm
2020/07/27 10:41:59 [Helm 3] Config directory: /root/.config/helm
2020/07/27 10:41:59 [Helm 3] Data directory: /root/.local/share/helm
2020/07/27 10:41:59 [Helm 3] Cache directory: /root/.cache/helm
2020/07/27 10:41:59 [Helm 3] Create config folder "/root/.config/helm" .
2020/07/27 10:41:59 [Helm 2] repositories file "/root/.helm/repository/repositories.yaml" will copy to [Helm 3] config folder "/root/.config/helm/repositories.yaml" .
2020/07/27 10:41:59 [Helm 3] Create cache folder "/root/.cache/helm" .
2020/07/27 10:41:59 [Helm 3] Create data folder "/root/.local/share/helm" .
2020/07/27 10:41:59 [Helm 2] starters "/root/.helm/starters" will copy to [Helm 3] data folder "/root/.local/share/helm/starters" .
很cool的操作,这是模拟迁移成功了,如果模拟迁移有问题的话,那么也就无需进行后续操作了,先解决问题再说。接下来就是实际迁移了。
[root@node-0 bin]# helm3 2to3 move config
2020/07/27 10:47:08 WARNING: Helm v3 configuration may be overwritten during this operation.
2020/07/27 10:47:08
[Move Config/confirm] Are you sure you want to move the v2 configuration? [y/N]: y
2020/07/27 10:47:10
Helm v2 configuration will be moved to Helm v3 configuration.
2020/07/27 10:47:10 [Helm 2] Home directory: /root/.helm
2020/07/27 10:47:10 [Helm 3] Config directory: /root/.config/helm
2020/07/27 10:47:10 [Helm 3] Data directory: /root/.local/share/helm
2020/07/27 10:47:10 [Helm 3] Cache directory: /root/.cache/helm
2020/07/27 10:47:10 [Helm 3] Create config folder "/root/.config/helm" .
2020/07/27 10:47:10 [Helm 3] Config folder "/root/.config/helm" created.
2020/07/27 10:47:10 [Helm 2] repositories file "/root/.helm/repository/repositories.yaml" will copy to [Helm 3] config folder "/root/.config/helm/repositories.yaml" .
2020/07/27 10:47:10 [Helm 2] repositories file "/root/.helm/repository/repositories.yaml" copied successfully to [Helm 3] config folder "/root/.config/helm/repositories.yaml" .
2020/07/27 10:47:10 [Helm 3] Create cache folder "/root/.cache/helm" .
2020/07/27 10:47:10 [Helm 3] cache folder "/root/.cache/helm" created.
2020/07/27 10:47:10 [Helm 3] Create data folder "/root/.local/share/helm" .
2020/07/27 10:47:10 [Helm 3] data folder "/root/.local/share/helm" created.
2020/07/27 10:47:10 [Helm 2] starters "/root/.helm/starters" will copy to [Helm 3] data folder "/root/.local/share/helm/starters" .
2020/07/27 10:47:10 [Helm 2] starters "/root/.helm/starters" copied successfully to [Helm 3] data folder "/root/.local/share/helm/starters" .
2020/07/27 10:47:10 Helm v2 configuration was moved successfully to Helm v3 configuration.
现在,让我们再次运行helm3 repo list
查看helm2
的存储库是否成功迁移:
[root@node-0 bin]# helm3 repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com/
brigade https://brigadecore.github.io/charts
成功了,说明现在可以使用与Helm v2中相同的Helm存储库和插件。
注意:请检查所有Helm v2插件与Helm v3能否正常工作,并删除不起作用的插件。
迁移Helm v2版本
这一步是使用convert
命令将Helm v2版本迁移到Helm v3,即迁移由Helm v2生成的应用到Helm v3下,同样的,我们查看一下convert
命令的描述:
[root@node-0 bin]# helm3 2to3 convert -h
migrate Helm v2 release in-place to Helm v3
Usage:
2to3 convert [flags] RELEASE
Flags:
--delete-v2-releases v2 release versions are deleted after migration. By default, the v2 release versions are retained
--dry-run simulate a command
-h, --help help for convert
--kube-context string name of the kubeconfig context to use
--kubeconfig string path to the kubeconfig file
-l, --label string label to select Tiller resources by (default "OWNER=TILLER")
-s, --release-storage string v2 release storage type/object. It can be 'secrets' or 'configmaps'. This is only used with the 'tiller-out-cluster' flag (default "secrets")
--release-versions-max int limit the maximum number of versions converted per release. Use 0 for no limit (default 10)
-t, --tiller-ns string namespace of Tiller (default "kube-system")
--tiller-out-cluster when Tiller is not running in the cluster e.g. Tillerless
首先查看一下已经使用Helm v2安装的应用,以便后续进行迁移测试:
[root@node-0 helm]# helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
sanguine-mouse 1 Mon Jul 27 11:07:07 2020 DEPLOYED mysql-1.6.6 5.7.30 default
自然使用--dry-run
进行模拟迁移:
[root@node-0 helm]# helm3 2to3 convert --dry-run sanguine-mouse
2020/07/27 11:09:19 NOTE: This is in dry-run mode, the following actions will not be executed.
2020/07/27 11:09:19 Run without --dry-run to take the actions described below:
2020/07/27 11:09:19
2020/07/27 11:09:19 Release "sanguine-mouse" will be converted from Helm v2 to Helm v3.
2020/07/27 11:09:19 [Helm 3] Release "sanguine-mouse" will be created.
2020/07/27 11:09:19 [Helm 3] ReleaseVersion "sanguine-mouse.v1" will be created.
模拟迁移成功,进行实际迁移:
[root@node-0 helm]# helm3 2to3 convert sanguine-mouse
2020/07/27 11:10:20 Release "sanguine-mouse" will be converted from Helm v2 to Helm v3.
2020/07/27 11:10:20 [Helm 3] Release "sanguine-mouse" will be created.
2020/07/27 11:10:20 [Helm 3] ReleaseVersion "sanguine-mouse.v1" will be created.
2020/07/27 11:10:21 [Helm 3] ReleaseVersion "sanguine-mouse.v1" created.
2020/07/27 11:10:21 [Helm 3] Release "sanguine-mouse" created.
2020/07/27 11:10:21 Release "sanguine-mouse" was converted successfully from Helm v2 to Helm v3.
2020/07/27 11:10:21 Note: The v2 release information still remains and should be removed to avoid conflicts with the migrated v3 release.
2020/07/27 11:10:21 v2 release information should only be removed using `helm 2to3` cleanup and when all releases have been migrated over.
分别使用helm
和helm3
命令查看是否迁移成功:
[root@node-0 helm]# helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
sanguine-mouse 1 Mon Jul 27 11:07:07 2020 DEPLOYED mysql-1.6.6 5.7.30 default
[root@node-0 helm]# helm3 list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
sanguine-mouse default 1 2020-07-27 03:07:07.599071812 +0000 UTC deployed mysql-1.6.6 5.7.30
如果使用Helm v2安装的应用太多了,那么就麻烦写个脚本进行循环运行吧。
清理Helm v2数据
来自官方的劝告:
最后一步是清理旧数据。尽管这不是必需的,但我们强烈建议您这样做。
[root@node-0 bin]# helm3 2to3 cleanup -h
cleanup Helm v2 configuration, release data and Tiller deployment
Usage:
2to3 cleanup [flags]
Flags:
--config-cleanup if set, configuration cleanup performed
--dry-run simulate a command
-h, --help help for cleanup
--kube-context string name of the kubeconfig context to use
--kubeconfig string path to the kubeconfig file
-l, --label string label to select Tiller resources by (default "OWNER=TILLER")
--name string the release name. When it is specified, the named release and its versions will be removed only. Should not be used with other cleanup operations
--release-cleanup if set, release data cleanup performed
-s, --release-storage string v2 release storage type/object. It can be 'secrets' or 'configmaps'. This is only used with the 'tiller-out-cluster' flag (default "secrets")
--skip-confirmation if set, skips confirmation message before performing cleanup
--tiller-cleanup if set, Tiller cleanup performed
-t, --tiller-ns string namespace of Tiller (default "kube-system")
--tiller-out-cluster when Tiller is not running in the cluster e.g. Tillerless
clean命令可以清理如下文件:
- 配置(Helm主目录)
- v2发布数据
- Tiller deployment(我暂时不知道这是什么)
同样的,自然是从最cool也最安全的--dry-run
开始:
[root@node-0 bin]# helm3 2to3 cleanup --dry-run
2020/07/27 11:01:30 NOTE: This is in dry-run mode, the following actions will not be executed.
2020/07/27 11:01:30 Run without --dry-run to take the actions described below:
2020/07/27 11:01:30
WARNING: "Helm v2 Configuration" "Release Data" "Tiller" will be removed.
This will clean up all releases managed by Helm v2\. It will not be possible to restore them if you haven't made a backup of the releases.
Helm v2 may not be usable afterwards.
[Cleanup/confirm] Are you sure you want to cleanup Helm v2 data? [y/N]: y
2020/07/27 11:01:32
Helm v2 data will be cleaned up.
2020/07/27 11:01:32 [Helm 2] Releases will be deleted.
2020/07/27 11:01:32 [Helm 2] no deployed releases for namespace: kube-system, owner: OWNER=TILLER
2020/07/27 11:01:32 [Helm 2] Tiller in "kube-system" namespace will be removed.
2020/07/27 11:01:32 [Helm 2] Home folder "/root/.helm" will be deleted.
它将显示要删除的发行版,要从kube-system名称空间删除的Tiller服务以及Helm v2主文件夹。
注意:该cleanup命令将删除Helm v2配置,发布数据和Tiller deployment。它将清理由Helm v2管理的所有发行版。如果尚未备份发行版,将无法还原它们。Helm v2之后将无法使用。
删除操作大家还是注意一下提前备份,我这里就不进行演示了,如果需要删除请使用helm3 2to3 cleanup
命令即可。
暂时遇到的一点小问题")暂时遇到的一点小问题
在迁移升级完毕后,我们使用helm3 search
命令可能会出现以下情况:
[root@node-0 helm]# helm3 search repo brigade
WARNING: Repo "stable" is corrupt or missing. Try 'helm repo update'.WARNING: Repo "brigade" is corrupt or missing. Try 'helm repo update'.No results found
brigade这个库是从Helm v2迁移过来的,看样子迁移过后需要更新一下存储库:
[root@node-0 helm]# helm3 repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "brigade" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈
更新完毕后再次搜索指定存储库:
[root@node-0 helm]# helm3 search repo brigade
NAME CHART VERSION APP VERSION DESCRIPTION
brigade/brigade 1.6.1 v1.4.0 Brigade provides event-driven scripting of Kube...
brigade/brigade-github-app 0.7.1 v0.4.1 The Brigade GitHub App, an advanced gateway for...
brigade/brigade-github-oauth 0.3.0 v0.20.0 The legacy OAuth GitHub Gateway for Brigade
brigade/brigade-k8s-gateway 0.3.0 A Helm chart for Kubernetes
brigade/brigade-project 1.0.0 v1.0.0 Create a Brigade project
brigade/kashti 0.5.0 v0.4.0 A Helm chart for Kubernetes
转载地址:https://lemonlzy.cn/2020/07/27/%E5%A6%82%E4%BD%95%E4%BB%8EHelm-v2%E8%BF%81%E7%A7%BB%E5%88%B0Helm-v3/
网友评论