Using Availability Zones to increase the availability of your Kubernetes cluster

When you run a Kubernetes cluster in Azure on Azure Kubernetes Service (AKS), its nodes and storage are distributed over separate update- and fault-domains in the Azure infrastructure of the datacenter it runs in. This helps to keep the cluster available when hardware fails or when maintenance is performed. However, if the datacenter fails (which is highly unlikely), the Kubernetes cluster will fail as well. To guard against that, you can run your Kubernetes cluster across Azure Availability Zones.

(Availability Zones in Azure)

Availability zones are unique physical locations that are made up of one ore more datacenters. Applications that are distributed across availability zones are distributed across physical regions, which protects them against failure of any single datacenter. This makes applications that use Availability Zones highly available.

In this post, we'll deploy an Azure Kubernetes Service cluster across Availability Zones.

Prerequisites

If you want to follow along, you'll need the following:

  • An Azure subscription (If you don't have an Azure subscription, create a free account before you begin)

Steps to take during the preview period

Currently, using Availability Zones for AKS is a preview feature. If you are reading this when the feature is generally available, you can skip this section. You can check the status of Availability Zones for AKS on this page.

In order to work with this preview feature, you have to enable feature flags in your Azure subscription. You can do that by running the following commands in the Azure Cloud Shell (or locally installed Azure CLI):

az feature register --name AvailabilityZonePreview --namespace Microsoft.ContainerService
az feature register --name AKSAzureStandardLoadBalancer --namespace Microsoft.ContainerService
az feature register --name VMSSPreview --namespace Microsoft.ContainerService
1
2
3

It will take several minutes before the preview features are registered for your subscription. You can check if they are registered by running the following commands:

az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/AvailabilityZonePreview')].{Name:name,State:properties.state}"
az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/AKSAzureStandardLoadBalancer')].{Name:name,State:properties.state}"
az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/VMSSPreview')].{Name:name,State:properties.state}"
1
2
3

(Querying the status of Azure preview features with the Azure CLI)

When all the features have the status "Registered", you need to refresh the registration of the Microsoft.ContainerService resource provider with the following command:

az provider register --namespace Microsoft.ContainerService
1

Also, we need to install the aks-preview CLI extension to use the AKS preview feature. You can do that by running the following commands in the cloud shell. These install the aks-preview extension and update it to the latest version:

# Install the aks-preview extension
az extension add --name aks-preview

# Update the extension to make sure you have the latest version installed
az extension update --name aks-preview
1
2
3
4
5

Creating a Azure Kubernetes Service using Availability Zones

Let's create a new AKS cluster that uses Availability Zones to increase its availability.

  1. Go to the Azure Cloud Shell and log in. By using this, you makes sure that you are using the latest version of the Azure CLI
  2. Run the following command to create a new Resource Group that we'll use to create the ASK cluster in:
az group create --name myTipsResourceGroup --location eastus2
1
  1. Run the following command to create the ASK cluster. This uses the --node-zones parameter, which defines the zones that the agent nodes are deployed to. If you don't use the --node-zones parameter, the cluster will be created with the default behaviour, where it uses one datacenter and distributes its nodes and storage over failure- and update-domains
az aks create --resource-group myTipsResourceGroup --name tipsAndTricksAKSCluster --generate-ssh-keys --enable-vmss --load-balancer-sku standard --node-count 3 --node-zones 1 2 3
1

(AKS cluster using Availability Zones successfully created)

Conclusion

Availability Zones in Azure are unique physical locations that you can use to distribute your applications to. Whe you use Availability Zones with Azure Kubernetes Service (AKS), you make sure that its nodes run across Availability Zones and are protected against any single failure of a datacenter. Go and check it out!