如何从Helm v2迁移到Helm v3
如何迁移数据是Helm主版本升级过程中最重要的一部分。考虑到Helm版本的架构从v2到v3的重大变化。这就是为什么会产生helm-2to3插件。
1. 配置Helm v3
由于我们不想整个推翻Helm v2命令行工具,我们需要执行一个额外的操作来确保Helm v2和v3版本的命令行工具可以同时工作,直到我们准备好移除Helm v2命令行工具和所有相关的数据:
从这里下载最新的Helm v3 beta版本,重命名这个命令行工具为helm3,并把它保存到你的目标路径下。
我们已经准备好使用helm3了:
$ helm3 repo list
Error: no repositories to show
你可以看到没有设置repositories,让我们来解决这个问题。helm-2to3 plugin
2. helm-2to3插件
helm-2to3插件将允许我们将Helm v2的配置和releases迁移到Helm v3。
已经安装的Kubernetes对象不会被更改或删除。
2.1 安装
让我们来安装它:
$ helm3 plugin install https://github.com/helm/helm-2to3
Downloading and installing helm-2to3 v0.1.0 ...
https://github.com/helm/helm-2to3/releases/download/v0.1.0/helm-2to3_0.1.0_darwin_amd64.tar.gz
Installed plugin: 2to3
$ helm3 plugin list
NAME VERSION DESCRIPTION
2to3 0.1.0 migrate Helm v2 configuration and releases in-place to Helm v3
$ helm3 2to3
Migrate Helm v2 configuration and releases in-place to Helm v3
Usage:
2to3 [command]
Available Commands:
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.
非常棒!!!
2.2 插件特性
当前插件支持一下特性:
- 迁移Helm v2的配置
- 迁移Helm v2的releases
3. 迁移Helm v2的配置
第一步,我们需要迁移Helm v2的配置和数据目录:
$ helm3 2to3 move config
这条命令将迁移以下内容:
- Chart starters
- Repositories
- Plugins
注意:请检查所有的Helm v2插件都能够很好的在Helm v3下工作,并移除那些不能够正常工作的插件。
现在让我们再次来运行 Helm3 repo list命令:
$ helm3 repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com
jfrog https://charts.jfrog.io
rimusz https://charts.rimusz.net
buildkite https://buildkite.github.io/charts
jetstack https://charts.jetstack.io
odavid https://odavid.github.io/k8s-helm-charts
elastic https://helm.elastic.co
appscode https://charts.appscode.com/stable
$ helm3 plugin list
NAME VERSION DESCRIPTION
2to3 0.1.0 migrate Helm v2 configuration and releases in-place to Helm v3
edit 0.3.0 Edit a release.
gcs 0.2.0 Provides Google Cloud Storage protocol support.
https://github.com/vigles...
linter 0.1.1 Helm plugin to find hardcoded passwords in values.yaml files
monitor 0.3.0 Query at a given interval a Prometheus, ElasticSearch or Sentry instance...
很好,现在我可以使用和Helm v2相同的repositories和插件了。
当Helm v3对应的配置和数据目录不存在时,上述的移动将会帮助我们创建相应的目录,并且当repositories.yaml文件存在时,会覆盖掉它。
这个插件也支持非默认配置的Helm v2 home和Helm v3的配置和数据目录,示例如下:
$ export HELM_V2_HOME=$HOME/.helm2
$ export HELM_V3_CONFIG=$HOME/.helm3
$ export HELM_V3_DATA=$PWD/.helm3
$ helm3 2to3 move configMigrate Helm v2 releases
4. 迁移Helm v2 releases
现在我们准备好,开始迁移releases了。
让我们首先来检查可用的选项:
$ helm3 2to3 convert -h
migrate Helm v2 release in-place to Helm v3
Usage:
2to3 convert [flags] RELEASE
Flags:
--delete-v2-releases v2 releases are deleted after migration. By default, the v2 releases are retained
--dry-run simulate a convert
-h, --help help for convert
-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")
-t, --tiller-ns string namespace of Tiller (default "kube-system")
--tiller-out-cluster when Tiller is not running in the cluster e.g. Tillerless
很好,这个插件甚至支持 Tillerless Helm v2。
让我们列出Helm v2的releases,并从中挑选一个用于我们的迁移测试:
$ helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
postgres 1 Wed Sep 11 14:52:32 2019 DEPLOYED postgresql-6.3.5 11.5.0 postgres
redis 1 Wed Sep 11 14:52:57 2019 DEPLOYED redis-9.1.7 5.0.5 redis
为了保证安全,我们先使用–dry-run 标志:
$ helm3 2to3 convert --dry-run postgres
NOTE: This is in dry-run mode, the following actions will not be executed.
Run without --dry-run to take the actions described below:
Release "postgres" will be converted from Helm 2 to Helm 3.
[Helm 3] Release "postgres" will be created.
[Helm 3] ReleaseVersion "postgres.v1" will be created.
现在荣我们执行真正的迁移工作:
$ helm3 2to3 convert postgres
Release "postgres" will be converted from Helm 2 to Helm 3.
[Helm 3] Release "postgres" will be created.
[Helm 3] ReleaseVersion "postgres.v1" will be created.
[Helm 3] ReleaseVersion "postgres.v1" created.
[Helm 3] Release "postgres" created.
Release "postgres" was converted successfully from Helm 2 to Helm 3. Note: the v2 releases still remain and should be removed to avoid conflicts with the migrated v3 releases.
检查是否迁移成功:
$ helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
postgres 1 Wed Sep 11 14:52:32 2019 DEPLOYED postgresql-6.3.5 11.5.0 postgres
redis 1 Wed Sep 11 14:52:57 2019 DEPLOYED redis-9.1.7 5.0.5 redis
$ helm3 list
NAME NAMESPACE REVISION UPDATED STATUS CHART
postgres postgres 1 2019-09-11 12:52:32.529413 +0000 UTC deployed postgresql-6.3.5
注意:由于我们并没有指定 --delete-vw-releases 标志,所以Helm v2 的postgres release仍然保留了下来,以后我们可以使用kubectl命令来删除它。
当你已经准备好了迁移你所有的releases时,你可以在一个循环中自动运行它,以应用helm3 2to3 转换每一个Helm v2对应的release。
如果你在使用Tillerless Helm v2,仅仅需要添加 --tiller-out-cluster 就可以迁移对应的releases了:
$ helm3 2to3 convert postgres --tiller-out-cluster
非常地酷和简单,对吧!
让我们一起在Helm v3中快乐的遨游吧。
本文翻译自Helm官网博文,翻译不当之处敬请谅解!