DEV Community

Carlos Mendible
Carlos Mendible

Posted on • Originally published at carlos.mendible.com on

GitOps: Deploying apps in Azure Kubernetes Service (AKS) with Flux

Recently I learned about GitOps which is a way to manage your Kubernetes clusters and the applications you run on top using Git. The idea is that you can declaratively describe the desired state of your systems in Git and roll out changes as soon as merges occur.

You can immediately see the main benefits of such an approach: Your Git repositories become the single source of truth for both your infrastructure and application code, allowing the teams to increase productivity and stability (you get the Git log to audit changes).

To implement GitOps you can use and configure Flux following some simple steps:

1. Download the helm template

helm fetch `
  --repo https://fluxcd.github.io/flux `
  --untar `
  --untardir .\.charts `
  --version 0.10.2 `
  flux

Enter fullscreen mode Exit fullscreen mode

2. Bake the template with your repo (I don’t use Tiller)

helm template flux `
  --set git.url="git@github.com:cmendible/kubernetes.samples" `
  --set git.path="19.flux" `
  --set git.pollInterval="5s" `
  --namespace flux `
  --output-dir .\.baked .\.charts\fluxcd

Enter fullscreen mode Exit fullscreen mode

As you can see I’m configuring Flux to use my k8s sample repo and the 19.flux folder, which contains a simple deployment file, but of course you can have more resource definitions.

3. Deploy the configuration to your cluster

kubectl apply -f .\.baked\flux\templates\

Enter fullscreen mode Exit fullscreen mode

4. Get the fluxctl CLI

Download the fluxctl CLI

5. Use fluxctl to get the public key

fluxctl identity --k8s-fwd-ns flux

Enter fullscreen mode Exit fullscreen mode

This key is needed to sync your cluster state with the Git repository (GitHub): Copy the key you obtained and use it to create a deploy key with write access on your GitHub repository (Settings > Deploy keys > Add deploy key > check Allow write access > paste the Flux public key > click Add key)

You are all set. If everything runs smooth you’ll find a new deployment in your cluster with the dni-function name.

To learn more about GitOps check: WeaveworksClick here to learn more about Flux

Hope it helps!

Top comments (0)