当前位置: 首页 > 工具软件 > helm-secrets > 使用案例 >

helm2迁移helm3

阎德宇
2023-12-01
  • 安装helm v3版本

#当前helm版本
[root@master helm]# helm version
Client: &version.Version{SemVer:"v2.16.12", GitCommit:"47f0b88409e71fd9ca272abc7cd762a56a1c613e", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.12", GitCommit:"47f0b88409e71fd9ca272abc7cd762a56a1c613e", GitTreeState:"clean"}
#下载最新helm版本
[root@master helm3]# wget https://get.helm.sh/helm-v3.5.3-linux-amd64.tar.gz
[root@master helm3]# ls
helm-v3.5.3-linux-amd64.tar.gz
[root@master helm3]# tar -zxvf helm-v3.5.3-linux-amd64.tar.gz 
[root@master helm3]# ls
helm-v3.5.3-linux-amd64.tar.gz  linux-amd64
[root@master helm3]# cd linux-amd64/
[root@master linux-amd64]# mv helm helm3
[root@master linux-amd64]# cp ./helm3 /usr/bin/
root@master ~]# helm3 version
version.BuildInfo{Version:"v3.5.3", GitCommit:"041ce5a2c17a58be0fcd5f5e16fb3e7e95fea622", GitTreeState:"dirty", GoVersion:"go1.15.8"
#helm v1和heml v3版本信息和不一致
[root@master ~]# helm repo list
NAME  	URL                                             
stable	https://kubernetes-charts.storage.googleapis.com
local 	http://127.0.0.1:8879/charts                    
harbor	https://helm.goharbor.io   
[root@master ~]# helm3 repo list
Error: no repositories to show
  • 安装 helm-2to3插件

#helm-2to3插件作用就是让Helm V2版本的配置和release迁移到Helm V3版本
[root@master ~]#  helm3 plugin install https://github.com/helm/helm-2to3
Downloading and installing helm-2to3 v0.8.2 ...
https://github.com/helm/helm-2to3/releases/download/v0.8.2/helm-2to3_0.8.2_linux_amd64.tar.gz
Installed plugin: 2to3
[root@master ~]# helm3 plugin list
NAME	VERSION	DESCRIPTION                                                               
2to3	0.8.2  	migrate and cleanup Helm v2 configuration and releases in-place to Helm v3
#如下配置证明helm 2to3插件安装成功
[root@master ~]#  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.
  • 迁移helm2的配置

[root@master ~]# helm3 2to3 move config
2021/03/18 10:19:02 WARNING: Helm v3 configuration may be overwritten during this operation.
2021/03/18 10:19:02 
[Move config/confirm] Are you sure you want to move the v2 configuration? [y/N]: y
2021/03/18 10:19:09 
Helm v2 configuration will be moved to Helm v3 configuration.
2021/03/18 10:19:09 [Helm 2] Home directory: /root/.helm
2021/03/18 10:19:09 [Helm 3] Config directory: /root/.config/helm
2021/03/18 10:19:09 [Helm 3] Data directory: /root/.local/share/helm
2021/03/18 10:19:09 [Helm 3] Cache directory: /root/.cache/helm
2021/03/18 10:19:09 [Helm 3] Create config folder "/root/.config/helm" .
2021/03/18 10:19:09 [Helm 3] Config folder "/root/.config/helm" created.
2021/03/18 10:19:09 [Helm 2] repositories file "/root/.helm/repository/repositories.yaml" will copy to [Helm 3] config folder "/root/.config/helm/repositories.yaml" .
2021/03/18 10:19:09 [Helm 2] repositories file "/root/.helm/repository/repositories.yaml" copied successfully to [Helm 3] config folder "/root/.config/helm/repositories.yaml" .
2021/03/18 10:19:09 [Helm 3] Create cache folder "/root/.cache/helm" .
2021/03/18 10:19:09 [Helm 3] cache folder "/root/.cache/helm" created.
2021/03/18 10:19:09 [Helm 3] Create data folder "/root/.local/share/helm" .
2021/03/18 10:19:09 [Helm 3] data folder "/root/.local/share/helm" created.
2021/03/18 10:19:09 [Helm 2] starters "/root/.helm/starters" will copy to [Helm 3] data folder "/root/.local/share/helm/starters" .
2021/03/18 10:19:09 [Helm 2] starters "/root/.helm/starters" copied successfully to [Helm 3] data folder "/root/.local/share/helm/starters" .
2021/03/18 10:19:09 Helm v2 configuration was moved successfully to Helm v3 configuration.
#和之前 helm repo list的输出信息相同
[root@master ~]# helm3 repo list
NAME  	URL                                             
stable	https://kubernetes-charts.storage.googleapis.com
local 	http://127.0.0.1:8879/charts                    
harbor	https://helm.goharbor.io   
[root@master ~]# helm3 plugin list                                              
2to3	0.8.2  	migrate and cleanup Helm v2 configuration and releases in-place to Helm v3 
  • 迁移helm2的release

[root@master ~]# 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
#可以看到最后的 --tiller-out-cluster 参数,甚至支持 Tillerless Helm v2。
#helm2下的release
$ helm list
NAME    	REVISION	UPDATED                 	STATUS  	CHART           	APP VERSION	NAMESPACE
minio	    1       	Wed Sep 11 11:47:51 2019	DEPLOYED	minio-2.5.13	RELEASE.2019-08-07T01-59-21Z	argo
redis   	1       	Wed Sep 11 14:52:57 2019	DEPLOYED	redis-9.1.7     	5.0.5      	redis
$ helm3 2to3 convert minio
Release "minio" will be converted from Helm 2 to Helm 3.
[Helm 3] Release "minio" will be created.
[Helm 3] ReleaseVersion "minio.v1" will be created.
[Helm 3] ReleaseVersion "minio.v1" created.
[Helm 3] Release "minio" created.
Release "minio" 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.
#helm2 release
$ helm list
NAME    	REVISION	UPDATED                 	STATUS  	CHART           	APP VERSION	NAMESPACE
minio	    1       	Wed Sep 11 11:47:51 2019	DEPLOYED	minio-2.5.13	RELEASE.2019-08-07T01-59-21Z	argo
redis   	1       	Wed Sep 11 14:52:57 2019	DEPLOYED	redis-9.1.7     	5.0.5      	redis
#helm3 release
$ helm3 list -n argo
NAME 	NAMESPACE	REVISION	UPDATED                                	STATUS  	CHART
minio	argo     	1       	2019-09-11 03:47:51.239461137 +0000 UTC	deployed	minio-2.5.13
注意:由于我们没有指定--delete-v2-releases选项,所以 Helm V2 minio 这个 release 信息还是存在的,我们可以在以后使用 kubectl 进行删除
当你准备好迁移你所有的 releases 的时候,你可以循环helm list里面的所有 release 来自动的将每个 Helm V2 release 迁移到 Helm V3 版本去。
如果你正在使用 Tillerless Helm V2,只需要指定--tiller-out-cluster选项来迁移 release 即可:
$ helm3 2to3 convert minio --tiller-out-cluster
  • 清理 Helm V2 数据

    最后当然就是清理之前版本的旧数据了,虽然这并不是必须的,但是还是建议你清理下,可以避免一些冲突。清理 Helm V2 的数据比较简单:

  • 删除主文件夹~/.helm
  • 如果你没有使用--delete-v2-releases选项,那么旧使用 kubectl 工具来删除 Tiller releases 数据
  • 卸载掉烦人的 Tiller

 参考文档链接:https://www.qikqiak.com/post/migrate-helm-to-v3/

 类似资料: