Install the Kubernetes Event-driven Autoscaling (KEDA) add-on by using ARM template

This article shows you how to deploy the Kubernetes Event-driven Autoscaling (KEDA) add-on to Azure Kubernetes Service (AKS) by using an ARM template.

Important

The KEDA add-on installs version 2.7.0 of KEDA on your cluster.

Due to KEDA's Kubernetes Compatibility policy, the managed KEDA addon is will only be supported in Kubernetes versions <= 1.25 when generally available. Please follow the release notes to be notified for additional Kubernetes version support.

Prerequisites

  • An Azure subscription. If you don't have an Azure subscription, you can create a free account.
  • Azure CLI installed.
  • Firewall rules are configured to allow access to the Kubernetes API server. (learn more)

Install the aks-preview Azure CLI extension

Important

AKS preview features are available on a self-service, opt-in basis. Previews are provided "as is" and "as available," and they're excluded from the service-level agreements and limited warranty. AKS previews are partially covered by customer support on a best-effort basis. As such, these features aren't meant for production use. For more information, see the following support articles:

To install the aks-preview extension, run the following command:

az extension add --name aks-preview

Run the following command to update to the latest version of the extension released:

az extension update --name aks-preview

Register the 'AKS-KedaPreview' feature flag

Register the AKS-KedaPreview feature flag by using the az feature register command, as shown in the following example:

az feature register --namespace "Microsoft.ContainerService" --name "AKS-KedaPreview"

It takes a few minutes for the status to show Registered. Verify the registration status by using the az feature show command:

az feature show --namespace "Microsoft.ContainerService" --name "AKS-KedaPreview"

When the status reflects Registered, refresh the registration of the Microsoft.ContainerService resource provider by using the az provider register command:

az provider register --namespace Microsoft.ContainerService

Install the KEDA add-on with Azure Resource Manager (ARM) templates

The KEDA add-on can be enabled by deploying an AKS cluster with an Azure Resource Manager template and specifying the workloadAutoScalerProfile field:

    "workloadAutoScalerProfile": {
        "keda": {
            "enabled": true
        }
    }

Connect to your AKS cluster

To connect to the Kubernetes cluster from your local computer, you use kubectl, the Kubernetes command-line client.

If you use the Azure Cloud Shell, kubectl is already installed. You can also install it locally using the az aks install-cli command:

az aks install-cli

To configure kubectl to connect to your Kubernetes cluster, use the az aks get-credentials command. The following example gets credentials for the AKS cluster named MyAKSCluster in the MyResourceGroup:

az aks get-credentials --resource-group MyResourceGroup --name MyAKSCluster

Example deployment

The following snippet is a sample deployment that creates a cluster with KEDA enabled with a single node pool comprised of three DS2_v5 nodes.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
        {
            "apiVersion": "2022-05-02-preview",
            "dependsOn": [],
            "type": "Microsoft.ContainerService/managedClusters",
            "location": "westcentralus",
            "name": "myAKSCluster",
            "properties": {
                "kubernetesVersion": "1.23.5",
                "enableRBAC": true,
                "dnsPrefix": "myAKSCluster",
                "agentPoolProfiles": [
                    {
                        "name": "agentpool",
                        "osDiskSizeGB": 200,
                        "count": 3,
                        "enableAutoScaling": false,
                        "vmSize": "Standard_D2S_v5",
                        "osType": "Linux",
                        "storageProfile": "ManagedDisks",
                        "type": "VirtualMachineScaleSets",
                        "mode": "System",
                        "maxPods": 110,
                        "availabilityZones": [],
                        "nodeTaints": [],
                        "enableNodePublicIP": false
                    }
                ],
                "networkProfile": {
                    "loadBalancerSku": "standard",
                    "networkPlugin": "kubenet"
                },
                "workloadAutoScalerProfile": {
                    "keda": {
                        "enabled": true
                    }
                }
            },
            "identity": {
                "type": "SystemAssigned"
            }
        }
    ]
}

Start scaling apps with KEDA

Now that KEDA is installed, you can start autoscaling your apps with KEDA by using its custom resource definition has been defined (CRD).

To learn more about KEDA CRDs, follow the official KEDA documentation to define your scaler.

Clean Up

To remove the resource group, and all related resources, use the Az PowerShell module group delete command:

az group delete --name MyResourceGroup

Next steps

This article showed you how to install the KEDA add-on on an AKS cluster, and then verify that it's installed and running. With the KEDA add-on installed on your cluster, you can deploy a sample application to start scaling apps.

You can troubleshoot KEDA add-on problems in this article.