Create AKS clusters with a Helm chart? It’s possible with Cluster API!

Alessandro Vozza
Dec 7, 2020 · 4 min read

Cluster APIs are Kubernetes-native APIs to manage the lifecycle of clusters and nodes as CRDs.

Code available at https://github.com/ams0/azure-managed-cluster-capz-helm

I’ve been following the Cluster API project for some time now, but lately my interest was renewed when I find out that the cluster-api-provider-azure (sometimes abbreviated in CAPZ) now supports AKS managed clusters in preview. So I set out to come up with some simple instructions on how to create AKS clusters programmatically. However, since clusters are described by (at least) four templates (as of now), I decided to write a simple Helm chart to easily and repeatably create clusters. Helm allows for an easy packaging and distribution of complex applications, and makes it simple to group all available options either on the command line or in a values file.

Preparation

First, you’ll need to get the clusterctl command line (I recommend using v0.3.11, the latest at the time of writing). Then, you’ll need to have a Kubernetes cluster to store the CRDs for your AKS clusters. You can use any cluster (another AKS cluster for example) or to keep things simple, you can spin up a local KIND cluster, and that’s what we will do here (my preferred way to obtain kind and other tools is to use the gofish package manager):

Now clone the repo and edit the values in clusterctl.env :

The clustertlc.env contains some environment variable that will influence the installation of the cluster-api-provider-azure (like EXP_AKS=true) which you should use to get the experimental support for AKS cluster in CAPZ. Fill the comment values for AZURE_SUBSCRIPTION_ID, AZURE_TENANT_ID and AZURE_LOCATION and source clusterctl.env .

Next, use clusterctl to install the Cluster API components:

Wait until all components are deployed in the various capi-*-system namespaces.

Deploy a cluster

Ready to roll! Deploy your first cluster with Helm:

If you like you can use a values.yaml file:

The options available are a bit limited at the moment (here’s for example the supported options for the AzureManagedControlPlane CRD), but the Cluster API Azure provider is open to accept suggestions in the form of issues or pull requests. Note that the cluster is created with a SystemAssigned-managed identity and that the service principal from cluster.env is the one needed to create the cluster itself, not the one used by the cluster to interact with Azure via the cloud-controller-manager.

You can check the status of the deployment in several ways; in addition to the obvious az aks list to check the Azure side, you can check the cluster-api object and get the logs of the capz-controller-manager pod:

Access the cluster

You don’t need to access the Azure API to get the credentials for the cluster, as its kubeconfig config file is stored in the managent cluster (the KIND cluster) as a secret in the namespace where we created the cluster CRDs.

That’s it!

Adding clusters

Let’s go crazy and add a second cluster:

And so on! Now for some magic: you can delete the KIND cluster and reapply exactly the same Helm charts/Cluster API CRDs and the controller will just reconcile the desired state (2 clusters) with the current situation in Azure (2 clusters) and happily report that no change is needed. So as you can see this is a great step towards complete automation of AKS infrastructure, from start to finish (you can just add a GitOps configuration repository to the clusters, even via Azure Arc and now you have a full end-to-end automation from clusters to applications). I will expand on the concept in a later article.

I hope you find Cluster API as exciting as I do, and I’m looking forward to contributing to the project. And I will follow up with another post about day 2 operations (upgrades, scaling and so on) on AKS clusters deployed with Cluster APIs.

All things Azure