This repo contains instructions on how to setup GitOps with Flux v2 for AKS
-
Create a resource group using the
az group create
command.RG=aks-gitops REGION=eastus2 az login az group create --name $RG --location $REGION
-
Create AKS cluster:
CLUSTER=aks-gitops-cluster az aks create --resource-group $RG --name $CLUSTER
-
Log into AKS cluster:
az aks get-credentials --resource-group $RG --name $CLUSTER --overwrite-existing
Register the following Azure resource providers if not already regitered:
az provider register --namespace Microsoft.Kubernetes
az provider register --namespace Microsoft.ContainerService
az provider register --namespace Microsoft.KubernetesConfiguration
Enable CLI extensions:
az extension add -n k8s-configuration
az extension add -n k8s-extension
Install flux extension:
az k8s-extension create -g $RG -c $CLUSTER -n flux-system \
--extension-type microsoft.flux -t managedClusters
-
Export variablesto use:
GIT_URL=https://github.com/yortch/aks-gitops BRANCH=main
-
Run the following command to initialize the flux system and configuration in the AKS cluster:
az k8s-configuration flux create --resource-group $RG \ --cluster-name $CLUSTER --cluster-type managedClusters \ --name opa-config --scope namespace --namespace opa \ --kind git --url=$GIT_URL --interval=1m --timeout=2m \ --branch $BRANCH --kustomization name=opa-kustomize \ path=./apps/opa/base interval=1m timeout=2m prune=true force=true
-
The
kustomization
above creates aHelmRelease
using helm chart fromGitRepository
(https://github.com/yortch/opa-demo) which creates artifacts in the namespaceopa
. To validate application, run the following command to get the external IP:kubectl get service opa -n opa
-
Copy the
EXTERNAL_IP
value and navigate tohttp://{EXTERNAL_IP}:8181
in a browser.
Use the following command to add a dev flux config:
```bash
az k8s-configuration flux create --resource-group $RG \
--cluster-name $CLUSTER --cluster-type managedClusters \
--name opa-dev-config --scope namespace --namespace opa-dev \
--kind git --url=$GIT_URL --interval=1m --timeout=2m \
--branch $BRANCH --kustomization name=opa-dev-kustomize \
path=./apps/opa/dev interval=1m timeout=2m prune=true force=true retry-interval=1m
```
This shows how to add a new deployment using a separate helm chart on the same namespace
by adding a new kustomization
resource:
```bash
az k8s-configuration flux kustomization create --resource-group $RG \
--cluster-name $CLUSTER --cluster-type managedClusters --name opa-config \
--kustomization-name app3-kustomize --path ./apps/app3 \
--prune true --force true --interval 1m --timeout 2m --retry-interval 30s
```