Reading Time: 5 minutes
Share:
Twitter
LinkedIn
Facebook
Reddit
Whatsapp
Follow by Email

Recently I have been going through the AKS-Preview az cli extension and found reference to a GitOps AKS addon. I have been waiting for something like this to come to AKS for a long time. In fact, it is already available for ARC enabled Kubernetes clusters. Below I will go through how to set it up in your AKS cluster.

Warning

This is still in preview, uses flux v1 and should not be used for production clusters.
You can currently only run this in eastus2euap, eastus, westeurope regions.

So, for this you will need the AKS-Preview extension and k8s-configuration of AZ CLI. If you do not already have this installed, you can add it using.

Shell

Or to update your existing use.

Shell

Register the preview feature

First, you need to register the preview feature. To do that use the following command.

Shell

After a while, close to 30 minutes run the following to check the status. It needs to show registered.

Shell

Now you will need to re-register the ContainerService provider to enable the new feature. To do that just run the following.

Shell

Install the GitOps AKS add-on

It’s time to install the GitOps AKS add-on. You can Install this add-on on cluster creation in the same way you would other add-ons or below you will see the option to upgrade an existing AKS cluster. Just change the resource group and cluster name to yours.

Shell

If you look at the pods running in the kube-system namespace you will see some new pods, gitopsmanager and config-agent.

Shell

Deploy from a repo

For this example, I have created an example repository you can use. (https://github.com/PixelRobots/aks-gitops-demo). Fork the repo as later you will be changing a value in a manifest to test a change. This repo has a few folders and inside the folders has a few Kubernetes manifest files. The manifests will provision a few namespaces, deploy a sample website, and create a config map. More information about what will be deployed can be found in the readme in the repo.

You are going to use the az cli to do the deployment and use the k8s-configuration extension you installed earlier. The command will also create some objects in your cluster.  The command is as follows. You will need to change some bits to match your setup, but I will go into more detail below.

Shell

–name is the name you give this configuration deployment. You can name this something else if you want.

–operator-instance-name Instance name of the Operator. You can name this something else if you want.

–operator-namespace the namespace where the GitOps operator is deployed to. You can change this if you want.

–repository-url The URL of your git repo.

–scope this can be set to namespace or cluster.

–cluster-type Is managedclusters as thats what AKS is.

–operator-params=’–git-branch=main’ This needs to be set to the branch where your manifests are. By default it uses master.

You can read about more parameters at https://docs.microsoft.com/en-us/cli/azure/k8s-configuration?view=azure-cli-latest

Check it has worked

It can take up to 5 minutes before anything happens. You can check to see if the resources have deployed. So as we know some namespaces are going to get created we can check by using the following.

Shell

You should be able to see your new namespaces and also the labels added fluxcd.io

You can also use the az k8s-configuration command to check the current state of the configuration.

Shell

You will notice the complicanceState is Installed and the message has a lot of information in it.

Test a change

As part of the deployment a service with type LoadBalancer was created. You can view it by using the following command.

Shell

Copy the IP address and paste it into your browser. A website should pop up.

Now in the repo you are going to make a change to the aks-gitops-demo.yaml file. This can be found in cluster-apps folder.

Change line 31 to another colour. Either red, green, blue or pink.

Commit the change. In about 5 minutes the repo will be deployed to the cluster and website will have a new background colour. You can check by going to the site again.

Awesome. It worked! The new pod has been deployed and is up and running. No other resource was recreated, just the changes that you made.

All in All

I like the way this is going. Hopefully, it will start to use flux v2 once that becomes GA, but for now it is a super quick way to set up GitOps on your AKS cluster. Please remember this is currently in preview and technically an unannounced preview at that. Hopefully once it is in public preview, we will see some integration with the Azure Portal like you do for ARC enabled Kubernetes clusters.

Test at your own peril.

I hope you found this post helpful. If you have any questions, please reach out.

Share:
Twitter
LinkedIn
Facebook
Reddit
Whatsapp
Follow by Email

Pixel Robots.

I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.

0 Comments

Leave a Reply

Avatar placeholder

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