• Helm V2 迁移到 V3
    • 安装 2to3 插件
    • 迁移 Helm V2 配置
    • 迁移 Heml V2 Release
    • 参考资料

    Helm V2 迁移到 V3

    Helm V3 与 V2 版本架构变化较大,数据迁移比较麻烦,官方提供了一个名为 helm-2to3 的插件来简化迁移工作,本文将介绍如何利用此插件迁移 Helm V2 到 V3 版本。这里前提是 Helm V3 已安装,安装方法请参考 这里。

    安装 2to3 插件

    一键安装:

    1. $ helm3 plugin install https://github.com/helm/helm-2to3
    2. Downloading and installing helm-2to3 v0.1.1 ...
    3. https://github.com/helm/helm-2to3/releases/download/v0.1.1/helm-2to3_0.1.1_linux_amd64.tar.gz
    4. Installed plugin: 2to3

    检查插件是否安装成功:

    1. $ helm3 plugin list
    2. NAME VERSION DESCRIPTION
    3. 2to3 0.1.1 migrate Helm v2 configuration and releases in-place to Helm v3

    迁移 Helm V2 配置

    1. $ helm3 2to3 move config
    2. [Helm 2] Home directory: /root/.helm
    3. [Helm 3] Config directory: /root/.config/helm
    4. [Helm 3] Data directory: /root/.local/share/helm
    5. [Helm 3] Create config folder "/root/.config/helm" .
    6. [Helm 3] Config folder "/root/.config/helm" created.
    7. [Helm 2] repositories file "/root/.helm/repository/repositories.yaml" will copy to [Helm 3] config folder "/root/.config/helm/repositories.yaml" .
    8. [Helm 2] repositories file "/root/.helm/repository/repositories.yaml" copied successfully to [Helm 3] config folder "/root/.config/helm/repositories.yaml" .
    9. [Helm 3] Create data folder "/root/.local/share/helm" .
    10. [Helm 3] data folder "/root/.local/share/helm" created.
    11. [Helm 2] plugins "/root/.helm/plugins" will copy to [Helm 3] data folder "/root/.local/share/helm/plugins" .
    12. [Helm 2] plugins "/root/.helm/plugins" copied successfully to [Helm 3] data folder "/root/.local/share/helm/plugins" .
    13. [Helm 2] starters "/root/.helm/starters" will copy to [Helm 3] data folder "/root/.local/share/helm/starters" .
    14. [Helm 2] starters "/root/.helm/starters" copied successfully to [Helm 3] data folder "/root/.local/share/helm/starters" .

    上面的操作主要是迁移:

    • Chart 仓库
    • Helm 插件
    • Chart starters

    检查下 repo 和 plugin:

    1. $ helm3 repo list
    2. NAME URL
    3. stable https://kubernetes-charts.storage.googleapis.com
    4. local http://127.0.0.1:8879/charts
    5. $
    6. $
    7. $ helm3 plugin list
    8. NAME VERSION DESCRIPTION
    9. 2to3 0.1.1 migrate Helm v2 configuration and releases in-place to Helm v3
    10. push 0.1.1 Push chart package to TencentHub

    迁移 Heml V2 Release

    已经用 Helm V2 部署的应用也可以使用 2to3convert 子命令迁移到 V3,先看下有哪些选项:

    1. $ helm3 2to3 convert --help
    2. migrate Helm v2 release in-place to Helm v3
    3. Usage:
    4. 2to3 convert [flags] RELEASE
    5. Flags:
    6. --delete-v2-releases v2 releases are deleted after migration. By default, the v2 releases are retained
    7. --dry-run simulate a convert
    8. -h, --help help for convert
    9. -l, --label string label to select tiller resources by (default "OWNER=TILLER")
    10. -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")
    11. -t, --tiller-ns string namespace of Tiller (default "kube-system")
    12. --tiller-out-cluster when Tiller is not running in the cluster e.g. Tillerless
    • --tiller-out-cluster: 如果你的 Helm V2 是 tiller 在集群外面 (tillerless) 的安装方式,请带上这个参数
    • --dry-run: 模拟迁移但不做真实迁移操作,建议每次迁移都先带上这个参数测试下效果,没问题的话再去掉这个参数做真实迁移
    • --tiller-ns: 通常 tiller 如果部署在集群中,并且不在 kube-system 命名空间才指定

    看下目前有哪些 helm v2 的 release:

    1. $ helm ls
    2. NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
    3. redis 1 Mon Sep 16 14:46:58 2019 DEPLOYED redis-9.1.3 5.0.5 default

    选一个用 --dry-run 试下效果:

    1. $ helm3 2to3 convert redis --dry-run
    2. NOTE: This is in dry-run mode, the following actions will not be executed.
    3. Run without --dry-run to take the actions described below:
    4. Release "redis" will be converted from Helm 2 to Helm 3.
    5. [Helm 3] Release "redis" will be created.
    6. [Helm 3] ReleaseVersion "redis.v1" will be created.

    没有报错,去掉 --dry-run 执行迁移:

    1. $ helm3 2to3 convert redis
    2. Release "redis" will be converted from Helm 2 to Helm 3.
    3. [Helm 3] Release "redis" will be created.
    4. [Helm 3] ReleaseVersion "redis.v1" will be created.
    5. [Helm 3] ReleaseVersion "redis.v1" created.
    6. [Helm 3] Release "redis" created.
    7. Release "redis" 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.

    检查迁移结果:

    1. $ helm ls
    2. NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
    3. redis 1 Mon Sep 16 14:46:58 2019 DEPLOYED redis-9.1.3 5.0.5 default
    4. $
    5. $
    6. $ helm3 ls -a
    7. NAME NAMESPACE REVISION UPDATED STATUS CHART
    8. redis default 1 2019-09-16 06:46:58.541391356 +0000 UTC deployed redis-9.1.3
    • helm 3 的 release 区分了命名空间,带上 -a 参数展示所有命名空间的 release

    参考资料

    • How to migrate from Helm v2 to Helm v3: https://helm.sh/blog/migrate-from-helm-v2-to-helm-v3/