kamal、やっていき高まる

3.2K Views

July 11, 24

スライド概要

高まれ

profile-image

どういうわけか暑がり

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

Kamal、やっていき高まる 2024.07.11 [email protected] kinoppyd SmartHR プログラマ

2.

だれおめー? kinoppyd programmer at SmartHR プログラミング ロードバイク ポーカー 料理

3.

Kamal、ご存じの方? 使ってる方?

4.

当日の挙手の感じを見て「み んな使ってますねー」とか「意 外と知られてないですね」とか 言うためのページ

5.

Kamal is 何

6.

https://kamal-deploy.org/

7.

今北産業 ● コンテナ時代のCapistrano ● DHH謹製 ● rootが使えるUbuntuにSSHで接続できれば、オ ンプレでもクラウドでもなんでも行ける

8.

DHH曰く Kubernetesを自分でメンテするの大変すぎるし、クラ ウドベンダは高いし、そもそも宣言的な状態定義があ んま好きじゃないんよ。

9.

最近のDHH ● オンプレ回帰(37Signalsでは ● nobuild(バンドルツールとの棲み分け ● 一人のフレームワーク(モダンアプリケーションを 作れるRails

10.

Kamalとは ● 複雑なインフラを必要としない ● チームが理解できるほどシンプルな ● 非ベンダーロックインのデプロイツール

11.

コンテナ時代のCapistrano (宣言的じゃなくて命令的)

12.

Kamalはどうやってデプロイを行っ ているか

13.

Kamalの基本的な挙動 ● sshkitを使ってサーバーに繋がり ● docker buildしてイメージをregistryに保存 ● Traefikを使って接続するコンテナを切り替え

14.

config/deploy.yml kamal init コマンドで生成されるconfig/deploy.ymlをいい感じに修正 service: hogehoge image: piyo/foo servers: - 192.168.0.1 - 192.168.0.2 registry: username: registry-user-name password: - KAMAL_REGISTRY_PASSWORD env: secret: - SECRET_KEY_BASE ssh: user: ubuntu healthcheck: path: / port: 3000 デプロイするサーバーの IP コンテナレジストリの設定 デプロイ時にアプリに渡される秘匿情報 SSHログイン時のユーザー名 コンテナヘルスチェックに使うパスとポート

15.

AWS EC2で試す場合は 事前にインスタンスでブートストラップ作業が必要 https://kamal-deploy.org/docs/configuration/ssh/ ssh でインスタンスにログイン後、aptのアップデートとdockerのリポジトリ追加、デフォルトのubuntuユーザー にdockerのグループ追加が必要。 sudo apt update sudo apt upgrade -y sudo apt install -y docker.io curl git sudo usermod -a -G docker ubuntu https://kamal-deploy.org/docs/configuration/ssh/

16.

デプロイ! kamal setup (初回)

17.

デプロイ! kamal setup (初回) Releasing the deploy lock... Finished all in 30.4 seconds ERROR (SSHKit::Command::Failed): Exception while executing on host ecX-X-X-X.ap-northeast-1.compute.amazonaws.com: docker exit status: 125 docker stdout: Nothing written docker stderr: Error response from daemon: No such container: traefik Error: failed to start containers: traefik docker: open .kamal/env/traefik/traefik.env: no such file or directory. See 'docker run --help'.

18.

🤔

19.

デプロイ! なんかenvがないというエラーだったので、色々調べた結果とりあえず事前にenvをpushすることで回避できました。 (kamal 1.6.0) https://github.com/basecamp/kamal/issues/538 kamal env push kamal setup kamal deploy kamal setup 初回以降は kamal deploy コマンドでOK

20.

Kamalのすごいところ

21.

すごい ● デプロイ時の動作がイメージしやすい ● 設定がそんなに複雑じゃない ● rootで実行できるUbuntuが1台あればデプロイ できる

22.

すごい ● アクセサリサービスのデプロイもできる ● Traefikが勝手にLet's EncryptのHTTPチャレン ジやってくれる ● ビルドキャッシュ効いたり、ローカルとリモートで アーキテクチャ変えたりもできる

23.

Kamalのちょいむず痒いところ

24.

気になる ● sshの接続で鍵が指定できず、ssh-agentを使う 必要がある ● rootを直接触れない環境では事前プロビジョン が必要 ● 宣言的じゃないから、fault tolerantはちょっと気 になる(まだ調べてない)

25.

気になる ● そもそものインフラの構築の難しさからは逃れられ ない(DHHもそう言ってる) ● リモート1台でもコンテナレジストリが必須 ● Traefikの設定がとにかくムズい

26.

ちなみにTraefikでLet's Encryptどうにかする場合

27.

こういうconfigになる servers: web: hosts: - ec2-X-X-X-X.ap-northeast-1.compute.amazonaws.com labels: traefik.http.routers.hoge.rule: Host(`hoge.kinoppyd.dev`) traefik.http.routers.hoge_secure.entrypoints: websecure traefik.http.routers.hoge_secure.rule: Host(`hoge.kinoppyd.dev`) traefik.http.routers.hogesecure.tls.certresolver: letsencrypt traefik: options: publish: - "443:443" volume: - "/letsencrypt/acme.json:/letsencrypt/acme.json" args: entryPoints.web.address: ":80" entryPoints.websecure.address: ":443" entryPoints.web.http.redirections.entryPoint.to: websecure entryPoints.web.http.redirections.entryPoint.scheme: https entryPoints.web.http.redirections.entrypoint.permanent: true certificatesResolvers.letsencrypt.acme.email: "[email protected]" certificatesResolvers.letsencrypt.acme.storage: "/letsencrypt/acme.json" certificatesResolvers.letsencrypt.acme.httpchallenge: true certificatesResolvers.letsencrypt.acme.httpchallenge.entrypoint: web https://github.com/basecamp/kamal/discussions/112 😇 なんもわからん

28.

DHH曰く We have two big areas that need to improve: SSL provisioning and multi-app-per-node. That's 95% of all the Traefik configurations people fumble with using Kamal. We will relieve their pain with Kamal 2 and a custom proxy. https://x.com/dhh/status/1765832132277276881

29.

https://rubyonrails.org/world/2024/session/kevin-mcconnell

30.

まとめ

31.

まとめ ● Capistrano like なコンテナデプロイツール ● Rails8から標準のデプロイツール ● 率直に身軽で使いやすい、でも使う人や状況は 選びそう