Upgrade to Pro — share decks privately, control downloads, hide ads and more …

docker-compose.yml から Helm Chartに 変換してくれるツール Katenary を試してみた

docker-compose.yml から Helm Chartに 変換してくれるツール Katenary を試してみた

kawagoo

May 29, 2023
Tweet

More Decks by kawagoo

Other Decks in Technology

Transcript

  1. Copyright © BIGLOBE Inc. 2023, All rights reserved. docker-compose.yml から

    Helm Chartに 変換してくれるツール Katenary を試してみた 2023/5/29 Kubernetes Novice Tokyo #25 川口 永一郎
  2. 2 Copyright © BIGLOBE Inc. 2023, All rights reserved. 自己紹介

    名前: 川口 永一郎 会社: BIGLOBE(新卒4年目) 所属:プロダクト技術本部 業務:会員管理システムの開発 (今年の3月までDNS基盤の運用とかオンプレシステムのAWS移行とかをメイ ンにやってました) k8s 歴は半年
  3. 3 Copyright © BIGLOBE Inc. 2023, All rights reserved. 話すこと

    初心者が Helm Chart を作成することになり、Katenary というツールをみつけ て試してみてわかったことを話します
  4. 4 Copyright © BIGLOBE Inc. 2023, All rights reserved. きっかけ

    • 運用効率化のため、サーバ / ネットワークの構成管理ツール NetBox (https://docs.netbox.dev/en/stable/)を使ってみることに • docker-compose.yml は公式に提供されてるけど、せっかくつくる ことになったから、触れたことない技術で構築したい Helm Chart つくって EKS 上で構築すればとアドバイスが k8s 興味がありつつも、業務で活かせる場面がなかなかなかったので、 挑戦してみました
  5. 6 Copyright © BIGLOBE Inc. 2023, All rights reserved. 公式のChartやドキュメントを参考にしつつ、ゼロから

    Helm Chart をつくり始めてみたものの、、、 え、けっこうムズいし、つくるの大変じゃね💦💦
  6. 7 Copyright © BIGLOBE Inc. 2023, All rights reserved. Helm

    Chart に変換して k8s に手軽にデプロイできる ツールがないか探してみる kompose (https://kompose.io/) に Helm Chart に変換できる機能もあると知 り、試してみる $ ls -1 docker-compose/templates/ env-netbox-env-configmap.yaml env-postgres-env-configmap.yaml env-redis-cache-env-configmap.yaml env-redis-env-configmap.yaml netbox-claim0-persistentvolumeclaim.yaml netbox-claim1-persistentvolumeclaim.yaml netbox-claim2-persistentvolumeclaim.yaml netbox-deployment.yaml netbox-housekeeping-claim0-persistentvolumeclaim.yaml netbox-housekeeping-claim1-persistentvolumeclaim.yaml netbox-housekeeping-claim2-persistentvolumeclaim.yaml netbox-housekeeping-deployment.yaml netbox-media-files-persistentvolumeclaim.yaml netbox-postgres-data-persistentvolumeclaim.yaml netbox-redis-cache-data-persistentvolumeclaim.yaml … $ kompose convert -c INFO Kubernetes file "docker-compose/templates/netbox-deployment.yaml" created INFO Kubernetes file "docker-compose/templates/env-netbox-env-configmap.yaml" created INFO Kubernetes file "docker-compose/templates/netbox-claim0-persistentvolumeclaim.y aml" created INFO Kubernetes file "docker-compose/templates/netbox-claim1-persistentvolumeclaim.y aml" created INFO Kubernetes file "docker-compose/templates/netbox-claim2-persistentvolumeclaim.y aml" created … ぱっと見うまく生成されたように見えるが
  7. 8 Copyright © BIGLOBE Inc. 2023, All rights reserved. Helm

    Chart に変換して k8s に手軽にデプロイできる ツールがないか探してみる 試してみるもテンプレートに沿った書き方に なってなかった values.yamlやconfigmapは生成されるが、 参照するような形式になってない $ cat docker-compose/templates/netbox-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: … spec: containers: - env: - name: CORS_ORIGIN_ALLOW_ALL valueFrom: configMapKeyRef: key: CORS_ORIGIN_ALLOW_ALL name: env-netbox-env … containers: image: netboxcommunity/netbox:${VERSION-v3.3-2.3.0} name: netbox resources: {} volumeMounts: - mountPath: /etc/netbox/config name: netbox-claim0 … '{{ .Values.netbox.repository.image }}’ みたいに変換するのを期待してた
  8. 9 Copyright © BIGLOBE Inc. 2023, All rights reserved. kompose

    (https://kompose.io/) に Helm Chart に変換できる機能もあると知 り、試してみるもテンプレートの書き方になってなかった もっと楽できるツールがないか探してみたところ、Katenary という ツールを発見 https://github.com/metal3d/katenary 使えるのか試してみた
  9. 10 Copyright © BIGLOBE Inc. 2023, All rights reserved. 実行してみると

    version: '3.4' services: netbox: &netbox image: docker.io/netboxcommunity/netbox:${VERSION-v3.5-2.6.1} depends_on: - postgres - redis - redis-cache env_file: env/netbox.env user: 'unit:root' healthcheck: start_period: 60s timeout: 3s interval: 15s test: "curl -f http://localhost:8080/api/ || exit 1" volumes: - ./configuration:/etc/netbox/config:z,ro - netbox-media-files:/opt/netbox/netbox/media:z,rw - netbox-reports-files:/opt/netbox/netbox/reports:z,rw - netbox-scripts-files:/opt/netbox/netbox/scripts:z,rw … … Netbox の docker-compose.yml $ katenary convert -f docker-compose.yml … … 📝 Generating configMap from env/netbox.env 📝 Generating configMap from env/netbox.env You cannot, at this time, have local volume in netbox deployment You cannot, at this time, have local volume in netbox deployment You cannot, at this time, have local volume in netbox deployment ⚡ Generate volume values netboxmediafiles for container named netbox in deployment netbox Error while getting port for service redis いきなりエラー redisのポートを指定しないといけないらし い
  10. 11 Copyright © BIGLOBE Inc. 2023, All rights reserved. ハマりポイント①

    • docker-compose.yml は変換のために事前に修正する必要がある redis: image: redis:7-alpine command: - sh - -c # this is to evaluate the $REDIS_PASSWORD from the env - redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose env_file: env/redis.env volumes: - netbox-redis-data:/data labels: katenary.io/ports: 6379 … redis, postgresなどにlabelsを明記す る必要がある
  11. 12 Copyright © BIGLOBE Inc. 2023, All rights reserved. テンプレートファイルが生成された

    $ ls -1 chart/netbox-test/templates/ netbox-configmapenv-netbox-env.configmap.yaml netbox.deployment.yaml netbox-housekeeping-configmapenv-netbox-env.configmap.yaml netbox-housekeeping.deployment.yaml netbox-housekeeping-netboxmediafiles.pvc.yaml netbox-netboxmediafiles.pvc.yaml netbox-worker-configmapenv-netbox-env.configmap.yaml netbox-worker.deployment.yaml netbox-worker-netboxmediafiles.pvc.yaml netbox-worker.service.yaml NOTES.txt postgres-configmapenv-postgres-env.configmap.yaml postgres.deployment.yaml postgres-netboxpostgresdata.pvc.yaml postgres.service.yaml redis-cache-configmapenv-redis-cache-env.configmap.yaml redis-cache.deployment.yaml redis-cache-netboxrediscachedata.pvc.yaml redis-cache.service.yaml redis-configmapenv-redis-env.configmap.yaml redis.deployment.yaml redis-netboxredisdata.pvc.yaml redis.service.yaml $ cat netbox.deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: '{{ .Release.Name }}-netbox' spec: replicas: 1 selector: matchLabels: katenary.io/component: netbox katenary.io/release: '{{ .Release.Name }}' template: metadata: labels: katenary.io/component: netbox katenary.io/release: '{{ .Release.Name }}' spec: … containers: - name: netbox image: '{{ .Values.netbox.repository.image }}{{ if ne .Values.netbox.repository.tag "" }}:{{ .Values.netbox.repository.tag }}{{ end }}' envFrom: - configMapRef: name: '{{ .Release.Name }}-netbox' … 動きそうなテンプレートファイルができている
  12. 13 Copyright © BIGLOBE Inc. 2023, All rights reserved. ハマりポイント②

    redis-cache みたいにハイフンがついてる場合のテンプレート生成は うまくやってくれない アプリケーションのデプロイを 試みるもテンプレートファイル の内容でエラー $ helm install test-netbox ./ Error: INSTALLATION FAILED: parse error at (netbox-test/templates/redis-cache.deployment.yaml:26): bad character U+002D '-' redis.cache.deployment.yaml - image: '{{ .Values.redis-cache.repository.image }}... + image: '{{ index .Values "redis-cache" "repository" "image" }}...
  13. 14 Copyright © BIGLOBE Inc. 2023, All rights reserved. $

    helm install test ./ $ kubectl get pod test-netbox-5f75647476-549ln 1/1 Running 0 23m test-netbox-housekeeping-6987ddbf76-b6w7n 1/1 Running 0 23m test-netbox-worker-6ff97447b4-nw2n6 1/1 Running 0 23m test-postgres-6f5998c77c-qhx42 1/1 Running 0 23m test-redis-cache-c5dbd96c7-rvnlt 1/1 Running 0 23m test-redis-db45c794f-lj5jf 1/1 Running 0 23m なんとかデプロイ成功🎉🎉🎉
  14. 15 Copyright © BIGLOBE Inc. 2023, All rights reserved. 惜しいポイント

    • configmap は values.yaml で設定した変数を参照するようになってない apiVersion: v1 kind: ConfigMap metadata: name: '{{ .Release.Name }}-netbox' labels: katenary.io/component: netbox katenary.io/path: env/netbox.env katenary.io/project: '{{ .Chart.Name }}' katenary.io/release: '{{ .Release.Name }}' annotations: katenary.io/docker-compose-sha1: e3bde3644f62c8372720137e2299fcc15f9143f8 katenary.io/version: 2.0.0-beta2 data: CORS_ORIGIN_ALLOW_ALL: "True" DB_HOST: postgres DB_NAME: netbox DB_PASSWORD: postgres apiVersion: v1 kind: ConfigMap metadata: name: '{{ .Release.Name }}-netbox' labels: katenary.io/component: netbox katenary.io/path: env/netbox.env katenary.io/project: '{{ .Chart.Name }}' katenary.io/release: '{{ .Release.Name }}' annotations: katenary.io/docker-compose-sha1: e3bde3644f62c8372720137e2299fcc15f9143f8 katenary.io/version: 2.0.0-beta2 data: {{- nindent 2 (toYaml .Values.netbox.environment) }} values.yamlを参照するように修正
  15. 16 Copyright © BIGLOBE Inc. 2023, All rights reserved. READMEにはこう書いてある

    あくまで補助ツール 惜しいところはあるけど、悪くない印象を感じた Important Note: Katenary is a tool to help to build Helm Chart from a docker-compose file, but docker-compose doesn't propose as many features as what can do Kubernetes. So, we strongly recommend to use Katenary as a "bootstrap" tool and then to manually enhance the generated helm chart.
  16. 17 Copyright © BIGLOBE Inc. 2023, All rights reserved. 開発止まっちゃってる??

    去年の5月以降 新バージョンのリリースなし 最後のcommitが今年の2月
  17. 18 Copyright © BIGLOBE Inc. 2023, All rights reserved. まとめ

    • Katenaryを試してみた結果 ◦ ところどころ手動で設定する必要はあるが、それなりに生成してくれる ◦ 公式の docker-compose.yaml があって、さくっとHelmを使って、デプロイしたいときはい いかも ◦ ただ、今後新しいバージョンがリリースされなさそうなのが残念 ◦ Helm Chart を効率よくつくるノウハウ持っている方いれば教えてください