Helm v2->v3 移行
Helm | How to migrate from Helm v2 to Helm v3
自分のPC上のHelm
まずはv3をダウンロード https://github.com/helm/helm/releases
自分の環境で、v2はここにある。
code:shell
❯ which helm
/usr/local/bin/helm
v3はhelm3として同じ場所に設置する。
v2がいらなくなったら、helmとリネームすることにする。
※helm-tillerプラグインを使っている場合、v2をhelm2とリネームするとhelm tillerコマンドがうまく動かなかったので(helm2 tiller ~~でなにやらエラー)、helm3をhelmにリネームして使えるのはv2と完全にお別れしてからになる。
code:shell
❯ sudo mv helm /usr/local/bin/helm3
❯ helm3 version
version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}
helm-2to3というプラグインを入手する。
code:shell
❯ helm3 plugin install https://github.com/helm/helm-2to3
Downloading and installing helm-2to3 v0.2.0 ...
https://github.com/helm/helm-2to3/releases/download/v0.2.0/helm-2to3_0.2.0_linux_amd64.tar.gz
Installed plugin: 2to3
❯ helm3 plugin list
NAME VERSION DESCRIPTION
2to3 0.2.0 migrate and cleanup Helm v2 configuration and releases in-place to Helm v3
現在プラグインがサポートするのは
Helm v2 設定の移行
Helm v2 リリースの移行
cf. Helmの"Release"とは
Helm v2 設定、リリースデータ、Tiller Deploymentの掃除
設定の移行をする。まずdry-run
code:shell
❯ helm3 2to3 move config --dry-run
2019/11/20 19:31:47 NOTE: This is in dry-run mode, the following actions will not be executed.
2019/11/20 19:31:47 Run without --dry-run to take the actions described below:
2019/11/20 19:31:47
2019/11/20 19:31:47 WARNING: Helm v3 configuration maybe overwritten during this operation.
2019/11/20 19:31:47
Move Config/confirm Are you sure you want to move the v2 configration? y/N: y
2019/11/20 19:31:56
Helm v2 configuration will be moved to Helm v3 configration.
2019/11/20 19:31:56 Helm 2 Home directory: /home/takumi/.helm
2019/11/20 19:31:56 Helm 3 Config directory: /home/takumi/.config/helm
2019/11/20 19:31:56 Helm 3 Data directory: /home/takumi/.local/share/helm
2019/11/20 19:31:56 Helm 3 Create config folder "/home/takumi/.config/helm" .
2019/11/20 19:31:56 Helm 2 repositories file "/home/takumi/.helm/repository/repositories.yaml" will copy to Helm 3 config folder "/home/takumi/.config/helm/repositories.yaml" .
2019/11/20 19:31:56 Helm 3 Create data folder "/home/takumi/.local/share/helm" .
2019/11/20 19:31:56 Helm 2 plugins "/home/takumi/.helm/plugins" will copy to Helm 3 data folder "/home/takumi/.local/share/helm/plugins" .
2019/11/20 19:31:56 Helm 2 starters "/home/takumi/.helm/starters" will copy to Helm 3 data folder "/home/takumi/.local/share/helm/starters" .
実行
code:shell
❯ helm3 2to3 move config
2019/11/21 16:12:03 WARNING: Helm v3 configuration maybe overwritten during this operation.
2019/11/21 16:12:03
Move Config/confirm Are you sure you want to move the v2 configration? y/N: y
2019/11/21 16:12:06
Helm v2 configuration will be moved to Helm v3 configration.
2019/11/21 16:12:06 Helm 2 Home directory: /home/takumi/.helm
2019/11/21 16:12:06 Helm 3 Config directory: /home/takumi/.config/helm
2019/11/21 16:12:06 Helm 3 Data directory: /home/takumi/.local/share/helm
2019/11/21 16:12:06 Helm 3 Create config folder "/home/takumi/.config/helm" .
2019/11/21 16:12:06 Helm 3 Config folder "/home/takumi/.config/helm" created.
2019/11/21 16:12:06 Helm 2 repositories file "/home/takumi/.helm/repository/repositories.yaml" will copy to Helm 3 config folder "/home/takumi/.config/helm/repositories.yaml" .
2019/11/21 16:12:06 Helm 2 repositories file "/home/takumi/.helm/repository/repositories.yaml" copied successfully to Helm 3 config folder "/home/takumi/.config/helm/repositories.yaml" .
2019/11/21 16:12:06 Helm 3 Create data folder "/home/takumi/.local/share/helm" .
2019/11/21 16:12:06 Helm 3 data folder "/home/takumi/.local/share/helm" created.
2019/11/21 16:12:06 Helm 2 plugins "/home/takumi/.helm/plugins" will copy to Helm 3 data folder "/home/takumi/.local/share/helm/plugins" .
2019/11/21 16:12:06 Helm 2 plugins "/home/takumi/.helm/plugins" copied successfully to Helm 3 data folder "/home/takumi/.local/share/helm/plugins" .
2019/11/21 16:12:06 Helm 2 starters "/home/takumi/.helm/starters" will copy to Helm 3 data folder "/home/takumi/.local/share/helm/starters" .
2019/11/21 16:12:06 Helm 2 starters "/home/takumi/.helm/starters" copied successfully to Helm 3 data folder "/home/takumi/.local/share/helm/starters" .
2019/11/21 16:12:06 Helm v2 configuration was moved successfully to Helm v3 configration.
ここまでで、v2時代のリポジトリとプラグインが使えるようになった。
※ただしプラグイン毎の更新具合で、まだv3で動くように対応されていない場合がある。
この移行プラグインは、v2をTillerlessに利用するためのプラグインを使っていた場合にも対応している。
https://github.com/rimusz/helm-tiller
Helm(v2)をtillerlessに利用する
末尾に表示される--tiller-out-clusterオプションがそれに当たる。
code:shell
❯ 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
-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
v2リリースをv3リリースに変換する。まずdry-run
DEPLOYEDなv2リリースがないと失敗する。
※最新がFAILEDでもDEPLOYEDなリビジョンがあれば大丈夫なのか、は未検証
v2では対象クラスターのTillerless化をしていたので--tiller-out-clusterオプションを追加
またv2リリース情報の保存ネームスペースはtillerとしていたので--tiller-ns tillerオプションを追加
code:shell
❯ helm3 2to3 convert release_name --tiller-ns tiller --tiller-out-cluster --dry-run
2019/11/22 11:12:32 NOTE: This is in dry-run mode, the following actions will not be executed.
2019/11/22 11:12:32 Run without --dry-run to take the actions described below:
2019/11/22 11:12:32
2019/11/22 11:12:32 Release "release_name" will be converted from Helm v2 to Helm v3.
2019/11/22 11:12:32 Helm 3 Release "release_name" will be created.
2019/11/22 11:12:33 Helm 3 ReleaseVersion "release_name.v1" will be created.
--dry-runをはずして決行する。
--delete-v2-releasesを指定しなかったため、Helm v2のリリース情報はそのまま残っている。
後でhelm3 2to3 cleanupで削除できる。
code:shell
❯ helm3 2to3 convert release_name --tiller-ns tiller --tiller-out-cluster
2019/11/22 11:12:47 Release "release_name" will be converted from Helm v2 to Helm v3.
2019/11/22 11:12:47 Helm 3 Release "release_name" will be created.
2019/11/22 11:12:48 Helm 3 ReleaseVersion "release_name.v1" will be created.
2019/11/22 11:12:48 Helm 3 ReleaseVersion "release_name.v1" created.
2019/11/22 11:12:48 Helm 3 Release "release_name" created.
2019/11/22 11:12:48 Release "release_name" was converted successfully from Helm v2 to Helm v3.
2019/11/22 11:12:48 Note: The v2 release information still remains and should be removed to avoid conflicts with the migrated v3 release.
2019/11/22 11:12:48 v2 release information should only be removed using helm 2to3 cleanup and when all releases have been migrated over.
なぜ変換する?
CIツールでhelm upgrade --installを使っていると、リリースが存在しなければインストールしようとする動きになる。
v2, v3問わず、「インストール」しようとしたときに、チャートに含まれるリソースが既に存在すると、エラーとしてインストールは中止される。
リソースを消すと、アプリケーションが非稼働な時間ができる。それを避けたいので、変換を行ってv3リリースが既に存在している状態を作り出す。
アプリケーションをdefaultネームスペースで動かしていたのでdefaultにリリースができた。
https://helm.sh/docs/faq/#release-names-are-now-scoped-to-the-namespace
In Helm 3, release information about a particular release is now stored in the same namespace as the release itself.
code:shell
❯ kubectl get secret
sh.helm.release.v1.release_name.v1 helm.sh/release.v1 1 4m39s
lsでも確認できる。
code:shell
❯ helm3 ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
release_name default 1 2019-11-21 09:02:14.977305509 +0000 UTC deployed release_name-1.0.0 1.0
CIツールで使うHelm
例はCircleCIだが、ほかでも大差ないはず
v2のころはこんなふうにインストールしていた。
code:config.yml
- run:
name: Install Helm
command: |
# https://raw.githubusercontent.com/helm/helm/master/scripts/get でも同じ
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
bash ./get_helm.sh --version v2.12.3
v3はスクリプトを取ってくるURLが変わっている。https://helm.sh/docs/intro/install/#from-script
バージョン指定の引数の形は変わっていない。今は出たばかりで3.0.0しかないが今後のために指定しておく。
code:config.yml
- run:
name: Install Helm
command: |
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
bash ./get_helm.sh --version v3.0.0
v2をTillerlessに使用していたため、
helm init --client-onlyしたり、
下記のようにTillerをローカル起動したりしていたが、v3ではTillerはいなくなったので、これらの手順は不要になった。
code:config.yml
- run:
name: Run tiller server locally
command: tiller -listen=localhost:44134 -storage=secret -logtostderr
background: true
helm upgradeのオプションは、
--install --set --debug --wait
の仕様は変わらず。同じように使える。
--timeout は秒の数値のみ指定できたのが、
--timeout 300s --timeout 5m --timeout 1h のように指定できるようになった。
v2と別れる
全リリースが削除されるのでクラスター内の一部のアプリケーションだけ移行した段階では実施できない。
dry-run
code:shell
❯ helm3 2to3 cleanup --tiller-ns tiller --tiller-out-cluster --dry-run
実行
code:shell
❯ helm3 2to3 cleanup --tiller-ns tiller --tiller-out-cluster
#Helm #Kubernetes