k8s の学習を兼ねて Kubernetes で CI/CD パイプラインを実装してみる。
- GCP を使う
- SOPS と age で秘密情報を暗号化、CI/CD ワークフロー内で複号化する
# クラスター作成
gcloud container clusters create main --addons HttpLoadBalancing,HorizontalPodAutoscaling,NetworkPolicy
# Artifact Registory にリポジトリを作成
gcloud artifacts repositories create main --repository-format=docker --location=asia-northeast1
# クラスター削除
gcloud container clusters delete main
# Artifact Registry のリポジトリを削除
gcloud artifacts repositories delete main --location=asia-northeast1
- GCP のサービスアカウントの権限を限定する
- ワークフローの起動タイミング調整 (コンテナのビルドとデプロイの依存関係調整)
- 複数環境へのデプロイ
- EKS
v*
のタグがついている場合にコンテナのビルドを行いそのタグをつける- ステージング環境とプロダクション環境で利用する
flowchart LR
repo[GitHub Repo]
developer(("🙋♀️"))
registry[Container registry]
gha[GitHub Actions]
developer -->|push| repo
repo --> |on push v* tag| gha
gha -->|push| registry
main
ブランチへの push によりコンテナのビルドと開発環境の更新を行う
flowchart LR
main[main]
developer(("🙋♀️"))
registry[Container registry]
gha[GitHub Actions]
cluster[k8s cluster]
developer -->|push| main
main --> |on push| gha
gha -->|1. push| registry
cluster -->|hash| registry
gha -->|2. kubectl apply| cluster
staging
ブランチへの push によりステージング環境の更新を行う (manifests
ディレクトリに変更がある場合のみ)
flowchart LR
staging[staging]
developer(("🙋♀️"))
registry[Container registry]
gha[GitHub Actions]
cluster[k8s cluster]
developer -->|push| staging
staging --> |on push| gha
cluster -->|v* tag| registry
gha -->|kubectl apply| cluster
production
ブランチへの push により本番環境の更新を行う (manifests
ディレクトリに変更がある場合のみ)
flowchart LR
production[production]
developer(("🙋♀️"))
registry[Container registry]
gha[GitHub Actions]
cluster[k8s cluster]
developer -->|push| production
production --> |on push| gha
cluster -->|v* tag| registry
gha -->|kubectl apply| cluster