Kubernetes包管理:Helm2 升級 Helm3


Helm是一個非常常用的K8s應用包管理工具,負責雲原生應用的安裝部署和生命周期管理。

Helm2

Helm2有兩個主要的組件:

  • Tiller: helm的服務端,部署在k8s里面的一個pod,通常在kube-system這個系統空間里。主要負責部署helm charts,管理release,跟k8s API通信。
  • Helm Client: 主要負責從共有或者私有helm charts倉庫拉取chart包,修改變量值,然后直接扔給tiller。

Helm2的問題

Helm2的一個主要問題是需要在k8s集群里面運行一個服務端,而這就需要把tiller的端口暴露給外界,會產生安全隱患。

在helm 2中引入的tiller主要是當時k8s還沒有RBAC機制,所以就引入了服務端tiller。

而后來k8s的功能相應完善,加入了RBAC和CRD等,都使得tiller這個東西顯得多余。

Helm3

helm3只有一個客戶端,沒有服務端,所以安裝起來很方便,把相應的程序下下來即可,不需要helm init安裝了。

相對於helm2,helm3有幾大特性:

  • 移除了tiller
  • 支持分布式helm hub, 有了它就可以在很多時候不需要手動添加非官方repo了,例如helm3 search hub <package name>
  • 為chart輸入值進行json schema驗證。
  • 可以給helm charts添加test了,通過helm test <release>就能針對部署的應用跑一些tests。
  • 部署的時候release name必須指定了,helm2的時候不指定會自動生成一個。
  • 刪除的時候不需要--purge了,刪了就是刪了。

Helm2到Helm3的遷移

helm官方提供了一個小工具,幫助我們把已經部署的helm2應用遷移到helm3上。

  • 安裝插件
helm3 plugin install https://github.com/helm/helm-2to3

備注:github如果被牆了的話可以選擇源碼安裝:

$ mkdir -p ${GOPATH}/src/github.com/helm
$ cd $_
$ git clone git@github.com:helm/helm-2to3.git
$ cd helm-2to3
$ make build
$ export HELM_LINTER_PLUGIN_NO_INSTALL_HOOK=true
$ helm plugin install <your_path>/helm-2to3
  • 遷移helm2的配置,例如倉庫
helm3 2to3 move config
  • 遷移helm2部署的應用(確保helm2和helm3同時安裝在同一台機器上)

現在我們准備好,開始遷移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

讓我們列出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-v2-releases 標志,所以Helm v2 的postgres release仍然保留了下來,以后我們可以使用kubectl命令來刪除它。

遷移時直接刪除helm2 release。

helm3 2to3 convert <release-name> --delete-v2-releases

當你已經准備好了遷移你所有的releases時,你可以在一個循環中自動運行它,以應用helm3 2to3 轉換每一個Helm v2對應的release。

最后一步是清除helm2的數據,這一步不是必須的,但是是強烈建議的。helm3 2to3 cleanup

參考:https://zhuanlan.zhihu.com/p/105903477

參考:https://www.jianshu.com/p/08f2a82f0756

參考:https://blog.csdn.net/weixin_44738411/article/details/100868358


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM