How to create a Kubernetes cluster on Azure AKS?

This articles walks through the steps necessary to create an AKS cluster.
An authenticated service principal with contributor role , or sufficient permissions on your user role are required.

  1. Install prerequisite binaries.
brew install azure-cli
az aks install-cli --kubelogin-install-location mykubetools/kubelogin
  1. Login with your service principal; Sign in with Azure CLI — Login and Authentication | Microsoft Learn
    az login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant>

  2. Register the AKS provider in Azure ; Resource providers and resource types - Azure Resource Manager | Microsoft Learn

az provider register -n Microsoft.ContainerService

  1. Create a resource group for your cluster, and export the value for follow-on commands.
export rg="prefect_aks-rg"
az group create --name $rg --location eastus
  1. Create a vnet and subnet. For simplicity in this tutorial, we will allow AKS to use “kubenet” networking, which is by default, and requires no additional steps or configuration.
    If provisioning through Terraform, Azure CNI will be used - more details can be found here.
    Configure Azure CNI networking in Azure Kubernetes Service (AKS) - Azure Kubernetes Service | Microsoft Learn
az network vnet create -g $rg -n prefectvnet --address-prefix 10.1.0.0/16 \
    --subnet-name prefectsubnet --subnet-prefix 10.1.1.0/24
  1. Create the AKS Cluster. This provisions the cluster with 2 nodes, that are Standard_B2s size.
    NOTE - Standard_B2s nodes might not be available in the eastus region if you are using a free-tier Azure account. See the following articles for more help in determining suitable locations / sku’s if you are using a free tier.
    Resource Skus - List - REST API (Azure Compute) | Microsoft Learn
    SKU not available errors - Azure Resource Manager | Microsoft Learn
export aks="myprefectAKSCluster"
az aks create --resource-group $rg --name "$aks" --node-count 2 --node-vm-size "Standard_B2s"
  1. Retrieve the connection kubeconfig from the cluster to interface.
    Here we are setting the output kubeconfig to an alternate location, to not merge with any existing contexts you might already have.
    az aks get-credentials --resource-group $rg --name "$aks" -f "~/.kube/$aks_config"

  2. Verify your connectivity:

kubectl get nodes