Skip to content

Efficient DevOps: How to Integrate AKS with GitOps for Kubernetes Deployments

Integrating GitOps with Azure Kubernetes Service (AKS) brings automation, reliability, and scalability to your Kubernetes deployments. By leveraging Git as the single source of truth for your infrastructure and application configurations, you can achieve a declarative and version-controlled approach, ensuring consistency and easy collaboration. This article explores the benefits and steps to seamlessly integrate GitOps practices with AKS.

Overview

Flux is a popular GitOps tool that continuously monitors a Git repository for changes in Kubernetes manifests. When changes are detected, Flux automatically applies those changes to the AKS cluster, ensuring the desired state of the cluster matches the Git repository. This approach eliminates the need for manual changes and provides a declarative and version-controlled deployment process.

With Flux, you define your desired infrastructure and application configurations in Git, and Flux ensures that your AKS cluster stays in sync with those configurations by constantly monitoring and syncing any differences. This will make it easier to manage and scale applications running on AKS.

Note: This article assumes that you already have AKS deployed up and running.

Prepare your Git repo

I’m using GitHub private repo, I have also used Microsoft sample voting app yaml files.

Source: Azure-Samples/azure-voting-app-redis: Azure voting app used in docs. (github.com)

Also, a pair of SSH key needs to be created and saved to be used later on in this guide, I used ssh-keygen to generate Public/Private key pair.

ssh-keygen -o -t rsa -C email@example.com

The public will be in your repo and the private in the AKS cluster in the coming steps.

Create GitOps Configuration

Go to your AKS cluster, GitOps option under Settings then Create.

Give this GitOps configuration a Name

Provide the Namespace name where the Flux resources will be created (if Namespace doesn’t exist a new one will be created)

Choose the scope of this configuration, Cluster or specific Namespace

Choose the source kind, in our case it’s Git Repo

Provide the Git URL (it can be HTTPS or SSH), Branch Name and if the Repo is Public or Private. In this article I’m using private repo.

Then paste the private key you generated earlier.

Choose Sync Interval and Timeout, Sync Interval refers to how often the flux will pull the changes from your repo.

Then create a kustomization with your desired options

Path: if you want to sync a specific folder in your repo, by default it will be the root

Sync Interval and Timeout: How often Flux is supposed to reconcile in the cluster.

Prune: Delete resources from cluster if they are deleted from the repo

Force: force recreation of resources

Click Review and Create, after few minutes flux should be installed and ready.

Validation

Ensure that the state is succeeded, and compliance is compliant

If you go to extensions, you will find a flux extension has been installed.

Furthermore, if you check the pods from within the AKS cluster you can see the flux resources

Also you can see that the application in the repo has been created automatically

Testing the Sync

Now, let’s make a modification to one of the YAML files and observe the outcome. I will increase the replica count of the frontend app from 1 to 2 using Visual Studio Code. Afterward, I will push these changes to the repo.

Almost immediately (up to 2 mins) the changes have been reflected to the cluster

And that’s it for today!

Spread the love
Published inAKSDevOps

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *