0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

パブリックプレビューの AKS GitOps を試してみた

Posted at

背景と目的

自分の周辺で GitOps と言えば、ArgoCD だったりするのですが、AKS で Flux v2 を使った GitOps がマネージドで使えるようなので、実際に試してみました。

前提条件

コマンドの実施環境は、Mac + Azure CLI です。

bash
$ sw_vers
ProductName:    macOS
ProductVersion: 12.1
BuildVersion:   21C52

$ az version
{
  "azure-cli": "2.30.0",
  "azure-cli-core": "2.30.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

検証用 AKS を用意します

bash
# 環境変数を設定します
region=japaneast
prefix=mnraksops

# リソースグループを作成します
az group create \
  --name ${prefix}-rg \
  --location $region

# AKS を作成します
az aks create \
  --resource-group ${prefix}-rg \
  --name ${prefix}-aks \
  --node-vm-size Standard_B2s \
  --node-count 1 \
  --generate-ssh-keys

# kubectl 用のクレデンシャルを取得します
az aks get-credentials \
  --resource-group ${prefix}-rg \
  --name ${prefix}-aks

# AKS の動作確認を行います
kubectl get node
kubectl run nginx --image=nginx
kubectl get pod nginx
kubectl delete pod nginx

AKS で GitOps を使えるようにします

bash
# 拡張機能を登録します
az feature register \
  --namespace Microsoft.ContainerService \
  --name AKS-ExtensionManager

# 拡張機能を伝播します
az provider register \
  --namespace Microsoft.ContainerService

# Registerd になったか確認します(自分の環境だと 30 分くらいかかりました)
az feature list \
  --query "[?contains(name, 'Microsoft.ContainerService/AKS-ExtensionManager')].{Name:name,State:properties.state}" \
  --output table

# 他に必要なリソースプロバイダーが登録されているか念のため確認します
az provider show \
  --namespace Microsoft.Kubernetes \
  --output table
az provider show \
  --namespace Microsoft.ContainerService \
  --output table
az provider show \
  --namespace Microsoft.KubernetesConfiguration \
  --output table

# CLI 拡張機能を有効にします
az extension add \
  --name k8s-configuration
az extension add \
  --name k8s-extension

# CLI 拡張機能を確認します
az version

# AKS に GitOps の設定をインストールします
az k8s-configuration flux create \
  --resource-group ${prefix}-rg \
  --cluster-name ${prefix}-aks \
  --cluster-type managedClusters \
  --name gitops-demo \
  --namespace gitops-demo \
  --scope cluster \
  --url https://github.com/fluxcd/flux2-kustomize-helm-example \
  --branch main \
  --kustomization name=infra path=./infrastructure prune=true \
  --kustomization name=apps path=./apps/staging prune=true dependsOn=["infra"]

# GitOps の設定状態を確認します
az k8s-configuration flux show \
  --resource-group ${prefix}-rg \
  --cluster-name ${prefix}-aks \
  --cluster-type managedClusters \
  --name gitops-demo

# 動作確認を行います
kubectl get namespaces
kubectl get pods -n flux-system
kubectl get pods -n gitops-demo
kubectl get pods -n nginx
kubectl get pods -n podinfo
kubectl get pods -n redis
kubectl get crds
kubectl get fluxconfigs -A
kubectl get gitrepositories -A
kubectl get helmreleases -A
kubectl get kustomizations -A
kubectl get deploy -n nginx
kubectl get deploy -n podinfo
kubectl get all -n redis

参考

bash
# Flux構成を削除します
az k8s-configuration flux delete \
  --resource-group ${prefix}-rg \
  --cluster-name ${prefix}-aks \
  --cluster-type managedClusters \
  --name gitops-demo

# Fluxクラスター拡張機能を削除します
az k8s-extension delete \
  --resource-group ${prefix}-rg \
  --cluster-name ${prefix}-aks \
  --cluster-type managedClusters \
  --name flux

# リソースグループを削除します
az group delete \
  --name ${prefix}-rg

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?