/learn-k8s-cicd

I'm learning k8s CI/CD.

Primary LanguageTypeScript

k8s-cicd

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

TODO

  • 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

Loading

開発環境

  • 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

Loading

ステージング環境

  • 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

Loading

本番環境

  • 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

Loading