# Availability Zones for your Kubernetes cluster in Azure

# Using Availability Zones to increase the availability of your Kubernetes cluster

When you run a Kubernetes cluster in Azure on Azure Kubernetes Service (AKS) (opens new window), 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 (opens new window).

(Availability Zones in Azure)

Availability zones are unique physical locations that are made up of one or 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:

# 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 (opens new window).

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 (opens new window) (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

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}"

(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

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

# 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 (opens new window) and log in. By using this, you make 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 AKS cluster in:
az group create --name myTipsResourceGroup --location eastus2
  1. Run the following command to create the AKS 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

(AKS cluster using Availability Zones successfully created)

# Conclusion

Availability Zones (opens new window) in Azure are unique physical locations that you can use to distribute your applications to. When you use Availability Zones with Azure Kubernetes Service (AKS) (opens new window), 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!