LoginSignup
1
0

More than 1 year has passed since last update.

そうだ、helmfileを使ってみよう

Last updated at Posted at 2022-10-21

はじめに

最近fishmansにドハマりしております。
好きなアルバムは「男たちの別れ」「宇宙 日本 世田谷」です。
朝方に作業する際とか、ぜひ聴いてみてください~

初期設定

環境

OS: Ubuntu 16.04
EKS Engin: 1.22.0
eksctl CLI: 0.95.0
helm CLI: 3.7.1
helmfile CLI: 0.144.0(latest)

helmとhelmfileの互換性?があまりよくわからないです。
ご存じの方がいたら教えてください。

helmfile CLI インストール

下記のhelmfileリポジトリから、自分のマシン環境にあったhelmfile CLIをインストールする

$ wget https://github.com/roboll/helmfile/releases/download/v0.144.0/helmfile_linux_amd64
$ sudo mv helmfile_linux_amd64 /usr/bin/helmfile
$ chmod 755 /usr/bin/helmfile
$ helmfile -v
helmfile version v0.144.0

デプロイしたいhelmレポジトリをインストール

airflowをデプロイしていきます

$ helm repo add airflow-stable/airflow https://airflow-helm.github.io/charts
$ helm search repo airflow-stable/airflow
NAME                            CHART VERSION   APP VERSION     DESCRIPTION                                       
airflow-stable/airflow          8.6.1           2.2.5           Airflow Helm Chart (User Community) - the stand...

values.yamlを元に、configを作成

chartをダウンロード

$ helm pull airflow-stable/airflow --version 8.5.3
$ tar -xzvf airflow-8.5.3.tgz

下記のデフォルトのvalues.yamlを元に、config.yamlに必要な設定をカスタマイズする

$ ls airflow/values.yaml
airflow/values.yaml
$ mv airflow/values.yaml <work-dir>/config.yaml

(values.yamlだけダウンロードするとかできるのだろうか・・・)

シンプルなhelmfile.yamlでデプロイしてみる

ディレクトリ構成

<work-dir>/
 ├ config.yaml
 └ helmfile.yaml

helmfile.yamlを作成

repositories: # 使用するhelmレポジトリを指定する
  - name: airflow-stable
    url: https://airflow-helm.github.io/charts

releases: # デプロイに必要な設定値を定義
  - name: airflow
    namespace: airflow
    chart: airflow-stable/airflow
    version: 8.5.3                 # chartバージョン
    values:            # 前項で作成したconfig.yamlを指定
      - ./config.yaml

デプロイ

helmfileコマンドは、helmfile.yamlが存在するディレクトリ上で実行する。
helmfile.yamlがいないとエラーになる

$ helmfile apply

helmfile.yaml 設定方法いろいろ

1. 自分で用意したchartでデプロイ

ディレクトリ構成

<work-dir>/
 ├ chart/
 │ ├ ***.yaml # マニフェストを作成&配置
 │ └ ***.yaml # マニフェストを作成&配置
 └ helmfile.yaml

helmfile.yamlを作成

repositories:
  - name: airflow-stable
    url: https://airflow-helm.github.io/charts

releases:
  - name: airflow
    namespace: airflow
    chart: ./chart # マニフェストを格納したディレクトリを指定

2. helmレポジトリ+自分で用意したchartでデプロイする

ディレクトリ構成

<work-dir>/
 ├ chart/
 │ ├ ***.yaml
 │ └ ***.yaml
 ├ config.yaml
 └ helmfile.yaml

helmfile.yamlを作成

repositories:
  - name: airflow-stable
    url: https://airflow-helm.github.io/charts

releases:
 # ↓ helmレポジトリでデプロイする分
  - name: airflow
    namespace: airflow
    chart: airflow-stable/airflow
    version: 8.5.3                 # chartバージョン
    values:            # 前項で作成したconfig.yamlを指定
      - ./config.yaml
 # ↓ 自分で用意したchartでデプロイする分
  - name: airflow-secrets     # release nameは重複しないよう設定
    namespace: airflow
    chart: ./chart

3. 複数のサービスを一括管理

ディレクトリ構成

<work-dir>/
 ├ airflow-A/
 │  ├ config.yaml
 │ └ helmfile.yaml
 ├ airflow-B/
 │  ├ config.yaml
 │  └ helmfile.yaml
 └─── helmfile.yaml # airflow-A/B を一括管理するためのhelmfile.yamlを配置

/helmfile.yamlを作成

helmfiles:
  - <work-dir>/*/helmfile.yaml
  • airflow-A, airflow-Bどちらも一括デプロイしたい場合は、work-dir/配下でhelmfileコマンドを実行する
  • airflow-Aのみをデプロイしたい場合は、work-dir/airflow-A/配下でhelmfileコマンドを実行する

4. basesに設定し、prod/dev環境でわけて管理

basesとは

helmfileはbasesに設定したファイルを、処理前にマージしてくれる、基本設定のこと。
例えば、下記の設定をいれると、

bases:
- environments.yaml
- defaults.yaml
- templates.yaml

全てのファイルを以下の順序でマージし、デプロイしてくれる

environments.yaml <- defaults.yaml <- templates.yaml <- helmfile.yaml

ディレクトリ構成

<work-dir>/
 ├ airflow/
 │  ├ config.yaml
 │ └ helmfile.yaml
 └─── environment.yaml # envを設定

work-dir/airflow/helmfile.yamlを作成

repositories: # 使用するhelmレポジトリを指定する
  - name: airflow-stable
    url: https://airflow-helm.github.io/charts

releases: # デプロイに必要な設定値を定義
  - name: airflow
    namespace: airflow
    chart: airflow-stable/airflow
    version: 8.5.3                 # chartバージョン
    values:            # 前項で作成したconfig.yamlを指定
      - ./config.yaml

bases: # bases設定を追加
  - ../environments.yaml

work-dir/environment.yamlを作成

environments:
  prod:
    kubeContext: arn:aws:eks:<region>:<aws_account_id>:cluster/<cluster_name_prod>
  dev:
    kubeContext: arn:aws:eks:<region>:<aws_account_id>:cluster/<cluster_name_prod>

helmfileコマンド実行

helmfileコマンドを実行時、[-e <環境名>]を指定する

$ helmfile -e prod apply
$ helmfile -e dev apply

よく使うhelmfileコマンド

helmfileコマンドは、helmfile.yamlが存在するディレクトリ上で実行する

デプロイ

$ helmfile apply

デプロイ済みのリリースをアンインストール

$ helmfile destroy

helmfile.yamlを元にした全リソースのマニフェストファイルを表示

$ helmfile template

デプロイテスト

$ helmfile test

参考にどうぞ

↓公式
https://helmfile.readthedocs.io/en/latest/
↓かなりよくまとまっていて、大変参考になりました
https://thinkit.co.jp/article/18009

おわりに

いろいろとカスタムできるようで、helmfile は素晴らしい。
使い倒せば、コードをすっきり、誰でもわかる状態にできそう。
アップデートがあれば積極的に記事を追加していこうと思います。

1
0
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
1
0