Edit

Share via


Create an Arc-enabled AKS cluster in an Extended Zone

In this article, you'll learn how to create an Arc-enabled AKS cluster in an Extended Zone, which helps you deploy PaaS services through Arc. Refer to What is Azure Extended Zones? | Services for currently supported PaaS workloads.

Prerequisites

Getting started

If you're already familiar with the subject, you may skip this paragraph. Here are important topics you may want read before you proceed with creation:

Setup

Install the following Azure CLI extensions.

az extension add --name connectedk8s  --upgrade --yes
az extension add --name k8s-extension --upgrade --yes
az extension add --name customlocation --upgrade --yes

Register the required namespaces.

az provider register --namespace Microsoft.ExtendedLocation --wait
az provider register --namespace Microsoft.KubernetesConfiguration --wait
az provider register --namespace Microsoft.App --wait
az provider register --namespace Microsoft.OperationalInsights --wait

Create an Arc-enabled AKS cluster in Extended Zones

Before proceeding to deploy PaaS workloads in Extended Zones, an Arc-enabled AKS cluster has to be created in the target Extended Zone. The following script helps do that and ease the deployment of supported PaaS services (see related content at the end of this article to learn more about them).

Note

Make sure to keep parameters consistent and transfer them correctly from this script to any following ones.

# Create an Arc-enabled AKS cluster on an edge zone
function createArcEnabledAksOnEz {
    param(
        [string] $SubscriptionId,
        [string] $AKSClusterResourceGroupName,
        [string] $location = "westus",
        [string] $AKSName,
        [string] $edgeZone,
        [int] $nodeCount = 2,
        [string] $vmSize = "standard_nv12ads_a10_v5",
        [string] $ArcResourceGroupName,
        [switch] $Debug
    )
    # Set the subscription
    az account set --subscription $SubscriptionId
    
    # Login to Azure
    az provider register --namespace Microsoft.AzureArcData
    
    # Create new resource group
    az group create --name $AKSClusterResourceGroupName --location $location

    # Create new cluster and deploy in edge zone
    Write-Output "Creating AKS cluster in edge zone..." 
    az aks create -g $AKSClusterResourceGroupName -n $AKSName --location $location --edge-zone $edgeZone --node-count $nodeCount -s $vmSize --generate-ssh-keys 
    
    # Create new resource group for Arc
    az group create --name $ArcResourceGroupName --location eastus

    # Download cluster credentials and get AKS cluster context
    az aks get-credentials --resource-group $AKSClusterResourceGroupName --name $AKSName --overwrite-existing

    # Connect the AKS cluster to Arc
    $CLUSTER_NAME = "$ArcResourceGroupName-cluster" # Name of the connected cluster resource
    Write-Output "Connecting AKS cluster to Azure Arc..."
    az connectedk8s connect --resource-group $ArcResourceGroupName --name $CLUSTER_NAME

    # DEBUG: Test connection to Arc
    if ($Debug) {
        Write-Debug az connectedk8s show --resource-group $ArcResourceGroupName --name $CLUSTER_NAME
    }
}


createArcEnabledAksOnEz -SubscriptionId "ffc37441-49e9-4291-a520-0b2d4972bb99" `
                        -AKSClusterResourceGroupName "t1" `
                        -location "westus" `
                        -AKSName "my-aks-cluster" `
                        -edgeZone "losangeles" `
                        -nodeCount 2 `
                        -vmSize "standard_nv12ads_a10_v5" `
                        -ArcResourceGroupName "t2"

Clean up resources

When no longer needed, delete my-aks-cluster resource group and all of the resources it contains using the az group delete command.

az group delete --name my-aks-cluster