まだTillerで消耗してるの? Docker Desktop for Macで新しいHelmを使った

Kubernetes
Nishipy
新しくなったらしいHelmを、Macでさくっと触ってみたのでメモ。

はじめに

「Helmのバージョン3.0が出たらしい。」

Helm 3.0.0 has been released!
Helm - The Kubernetes Package Manager.

Helmと言えば、前もってRBACの設定をしておいて、その後helm initをやってTillerをKubernetesクラスタに配置するという点が特徴でした。しかし、先日Helm3.0がリリースされて、このTillerちゃんがレガシーとなったらしいです。これを追悼しつつ、新しくなったHelmを使ってみます。

Helmとは

Helm
Helm - The Kubernetes Package Manager.

ちょっとググると「Kubernetesのパッケージ管理ツール」という説明が書いてあります。Kubernetes上で動く動くアプリケーション、パッケージの管理を行うツールであり、pipとかHomebrewとかyumのようなイメージです。Helmというのは、もともと英語で舵という意味らしい。Kubernetes周辺のものはだいたい海とか船に関連しますね。こういうノリ好き。

Helmプロジェクトは現在、CNCFがメンテナンスしており、Google,Microsoft,Bitnamiなどがコントリビュートしているらしい。(Bitnamiって、VMwareが買収して話題になっていたけど、名前しか知らない…)

The Helm Project
The package manager for Kubernetes. The Helm Project has 35 repositories available. Follow their code on GitHub.

Helm用語

少し復習します。

Helm Chart

英語で海図という意味。Helmにおける「パッケージ」の雛形であり、Kubernetesにデプロイするアプリケーションを.tgzで固めたもの。

よく使われるChartは、Helm Hubに公開されており、簡単に利用できる。

Artifact Hub
Find, install and publish Kubernetes packages

Helm Release

Helm Chartを、Kubernetesクラスタ上にデプロイしたもの。

Helm Client と Tiller(〜Helm 2系)

Helm Client(Golang製CLIツール)から、Kubernetesクラスタ上でPodとして動作するTillerに指示を出し、Tillerがそれを受けてKubernetes API Serverを叩くことで、アプリケーションをデプロイする。

Helm 2 is a client-server architecture with the client called helm and the server called Tiller. The client is a CLI that users interact with to perform different operations like install, upgrade, and delete. As seen in the following diagram, the client interacts with Tiller and the chart repository. Tiller interacts with the Kubernetes API server. It renders Helm template files into Kubernetes manifest files, which it uses for operations on the Kubernetes cluster through the Kubernetes API.
helm2
(引用元: https://developer.ibm.com/blogs/kubernetes-helm-3/)

Tillerなき今。Helm 3.0

先に書いたように、最新のHelm3.0では、このTillerがクビになりました。理由は、この辺りに書いています。

With role-based access controls (RBAC) enabled by default in Kubernetes 1.6, locking down Tiller for use in a production scenario became more difficult to manage. Due to the vast number of possible security policies, our stance was to provide a permissive default configuration. This allowed first-time users to start experimenting with Helm and Kubernetes without having to dive headfirst into the security controls. Unfortunately, this permissive configuration could grant a user a broad range of permissions they weren’t intended to have. DevOps and SREs had to learn additional operational steps when installing Tiller into a multi-tenant cluster.
https://helm.sh/docs/faq/#changes-since-helm-2

RBACがデフォルトとなったKubernetesにおいて、Tillerに与える権限管理の煩雑さ(Tiller用に名前空間を作って、Roleを作って、ServiceAccount、RoleBinding、、、)や、マルチテナントのクラスターにTillerをインストールする際の運用負荷などを考慮して、Tillerはお役御免となったようです。

クラスタの中のTillerに指示をだすわけだから、セキュリティ面で大変なのは想像つきます。以下の記事が参考もなるかもしれません。

Configuring minimal RBAC permissions for Helm and Tiller

Helm’s tiller in a multi-tenant kubernetes cluster

TillerちゃんがいないHelm3.0。Helmの権限管理はkubeconfigを用いて行われ、Helm clientから直接Kubernetes API Severに指示を出すようなアーキテクチャになったようです。まるでkubectl!

Helm 3 has a client-only architecture with the client still called helm. As seen in the following diagram, it operates similar to the Helm 2 client, but the client interacts directly with the Kubernetes API server. The in-cluster server Tiller is now removed.
helm3
(引用元: https://developer.ibm.com/blogs/kubernetes-helm-3/)



やってみる

Docker DesktopでKubernetesを有効化

Docker Desktopの機能により、ローカルマシン上でKubernetesクラスタを小さく構築し、すぐに試すことができます。minikubeでもいいけど。

  • Enable Kubernetesにチェックを入れ、Applyします

  • リソースの割り当ては、お好みで

  • Contextは、docker-desktopを指定します

  • Kubernetes is Runningとなれば、完了です

  • kube-systemのPodたちも動きだしました

Helmのセットアップ

公式チュートリアルを参考にやっていきます。

Quickstart Guide
How to install and get started with Helm including instructions for distros, FAQs, and plugins.

インストール

Homebrewなら、コマンド一発。

ちゃんとバージョン3.0がインストールできました。

Chartリポジトリの追加

リポジトリを指定すれば、利用可能なHelm Chartが見られるようになります。

Tillerの導入

バージョン3.0なので、不要!!!

Helmの利用

インストールして、リポジトリを追加すれば、もうHelmが使えるようになりました!試しにstable/wordpressというChartを用いて、ローカルのKubernetesクラスタにwordpressをデプロイしてみます。GitHubのページがあるので、これを参考にすればいいだけです。

charts/stable/wordpress at master · helm/charts
⚠️(OBSOLETE) Curated applications for Kubernetes. Contribute to helm/charts development by creating an account on GitHub.

helm install コマンドの変更点

少し悩んだのは、helm installの作りが少し変わっているところ。GitHubの手順は更新されていなかったので、ご注意ください。
以前はこのようにhelm installしていました。--nameをつけるとHelm Releaseの名前を指定でき、つけないと自動で命名されていました。

  • Helm 2
    $ helm install stable/wordpress
    $ helm install --name my-release stable/wordpress

しかし、Helm3.0以降では、以下のようになります。--generate-nameをつけると自動で命名され、つけない場合はhelm installの直後に名前を指定しないといけない。

  • Helm 3
    $ helm install --generate-name stable/wordpress
    $ helm install my-release stable/wordpress

気を取り直して、helm install

それっぽいコマンドを打っておく。一応、Chartの説明に目を通す。

そしてインストール。いろいろオプションを指定できるらしいけど、シンプルにhelm installしてみる。



デプロイできたか確認

my-releaseという名前のHelm Releaseができました。

それっぽい名前のKubernetesのリソースもできていますね。

少し待つと、ブラウザからhttp://localhostにアクセスできるようになります。

さいごに

新しいHelm3.0を触ってみました。Tillerがいないだけで、チュートリアルもサクサク進めることができます。Helmインストール→リポジトリ追加だけで、すぐにChartが使えるようになり、これならパッケージ管理ツールと呼ぶことにも違和感がなくなりそうです。

コメント