LoginSignup
2
3

More than 5 years have passed since last update.

Helm と Kubernetes

Posted at

Helm という Kubernetes 用のパッケージマネージャを試しました。

Helm が apt や brew などの OS のパッケージマネージャと一番違うと感じたのは、一つのパッケージ(Chart と呼びます)を複数個インストール出来る事です。例えば mysql を三回インストールすれば3つの mysql が立ち上がります。3つインストールすればそれぞれを見分けないといけないので、Release 名が付けられます。

Chart のインストールと削除

Quickstart Guide をやってみます。

まず、現在の Kubernetes 環境を確認する。とりあえず Docker for Mac についてる環境でやります。

$ kubectl config current-context 
docker-for-desktop

Helm のインストール。

brew install kubernetes-helm

初期化。これで Tiller というサーバー側の部品も Kubernetes クラスタにインストールするらしい。

helm init

試しに stable/mysql chart をインストールしてみる

$ helm repo update
$ helm install stable/mysql
NAME:   braided-quail
...

NAME: の所に表示されるのを Release 名です。これで Chart から出来たインスタンスを見分けます。適当に名付けられますが、 --name オプションで指定も出来ます。Chart をインストールすると丁寧な説明が表示されるので、そのとおりに操作して mysql が動いている事を確認する。

$ kubectl port-forward svc/braided-quail-mysql 3306 & # これはクラスタ内にアクセスするためのポートフォワーディング

$ MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default braided-quail-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)

$ mysql -h 127.0.0.1 -P 3306 -u root -p${MYSQL_ROOT_PASSWORD}
mysql: [Warning] Using a password on the command line interface can be insecure.
Handling connection for 3306
Welcome to the MySQL monitor.  Commands end with ; or \g.
...

もう一度 Release の詳しい説明を見る。

helm status braided-quail

Chart の情報を見る。

helm inspect stable/mysql

インストールした Release のリスト

$ helm ls
NAME            REVISION    UPDATED                     STATUS      CHART           APP VERSION NAMESPACE
braided-quail   1           Fri Sep  7 10:44:43 2018    DEPLOYED    mysql-0.10.1    5.7.14      default

面白い事に、再度 stable/mysql をインストールするともう一個 Release が出来る。

$ helm install stable/mysql
$ helm ls --all
NAME            REVISION    UPDATED                     STATUS      CHART           APP VERSION NAMESPACE
braided-quail   1           Fri Sep  7 10:44:43 2018    DEPLOYED    mysql-0.10.1    5.7.14      default
moldy-toucan    1           Fri Sep  7 11:15:12 2018    DEPLOYED    mysql-0.10.1    5.7.14      default

Release の削除

helm delete braided-quail

Delete しても記録が残っていて同じ名前を使えない。完全に消したい時は --purge を使う。

helm delete --purge customized

Chart をカスタマイズしてインストール

カスタマイズ項目を見てみます。

helm inspect values stable/mysql

実際にカスタマイズします。config.yaml に差分を書いて helm install の -f オプションに渡します。例えば MySQL のユーザ hoge とパスワード hige を作ります。

echo '{mysqlUser: hoge, mysqlPassword: hige}' > config.yaml
helm install stable/mysql -n customized -f config.yaml

動作確認

$ kubectl port-forward svc/customized-mysql 3306 & # ポートフォワーディングの設定

$ mysql -h 127.0.0.1 -P 3306 -u hoge -phige
mysql: [Warning] Using a password on the command line interface can be insecure.
Handling connection for 3306
Welcome to the MySQL monitor.  Commands end with ; or \g.

上手く行った。Chart の書き方に続く予定。。。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3