|
| 1 | +--- |
| 2 | +title: Install the Kubernetes Event-driven Autoscaling (KEDA) add-on by using Azure CLI |
| 3 | +description: Use Azure CLI to deploy the Kubernetes Event-driven Autoscaling (KEDA) add-on to Azure Kubernetes Service (AKS). |
| 4 | +author: raorugan |
| 5 | +ms.author: raorugan |
| 6 | +ms.service: container-service |
| 7 | +ms.topic: article |
| 8 | +ms.date: 06/08/2022 |
| 9 | +ms.custom: template-how-to |
| 10 | +--- |
| 11 | + |
| 12 | +# Install the Kubernetes Event-driven Autoscaling (KEDA) add-on by using Azure CLI |
| 13 | + |
| 14 | +This article shows you how to install the Kubernetes Event-driven Autoscaling (KEDA) add-on to Azure Kubernetes Service (AKS) by using Azure CLI. The article includes steps to verify that it's installed and running. |
| 15 | + |
| 16 | +[!INCLUDE [Current version callout](./includes/keda/current-version-callout.md)] |
| 17 | + |
| 18 | +[!INCLUDE [preview features callout](./includes/preview/preview-callout.md)] |
| 19 | + |
| 20 | +## Prerequisites |
| 21 | + |
| 22 | +- An Azure subscription. If you don't have an Azure subscription, you can create a [free account](https://azure.microsoft.com/free). |
| 23 | +- [Azure CLI installed](/cli/azure/install-azure-cli). |
| 24 | + |
| 25 | +### Install the extension `aks-preview` |
| 26 | + |
| 27 | +Install the `aks-preview` extension in the AKS cluster to make sure you have the latest version of AKS extension before installing KEDA add-on. |
| 28 | + |
| 29 | +```azurecli |
| 30 | +- az extension add --upgrade --name aks-preview |
| 31 | +``` |
| 32 | + |
| 33 | +### Register the `AKS-KedaPreview` feature flag |
| 34 | + |
| 35 | +To use the KEDA, you must enable the `AKS-KedaPreview` feature flag on your subscription. |
| 36 | + |
| 37 | +```azurecli |
| 38 | +az feature register --name AKS-KedaPreview --namespace Microsoft.ContainerService |
| 39 | +``` |
| 40 | + |
| 41 | +You can check on the registration status by using the `az feature list` command: |
| 42 | + |
| 43 | +```azurecli-interactive |
| 44 | +az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/AKS-KedaPreview')].{Name:name,State:properties.state}" |
| 45 | +``` |
| 46 | + |
| 47 | +When ready, refresh the registration of the *Microsoft.ContainerService* resource provider by using the `az provider register` command: |
| 48 | + |
| 49 | +```azurecli-interactive |
| 50 | +az provider register --namespace Microsoft.ContainerService |
| 51 | +``` |
| 52 | + |
| 53 | +## Install the KEDA add-on with Azure CLI |
| 54 | +To install the KEDA add-on, use `--enable-keda` when creating or updating a cluster. |
| 55 | + |
| 56 | +The following example creates a *myResourceGroup* resource group. Then it creates a *myAKSCluster* cluster with the KEDA add-on. |
| 57 | + |
| 58 | +```azurecli-interactive |
| 59 | +az group create --name myResourceGroup --location eastus |
| 60 | +
|
| 61 | +az aks create \ |
| 62 | + --resource-group myResourceGroup \ |
| 63 | + --name myAKSCluster \ |
| 64 | + --enable-keda |
| 65 | +``` |
| 66 | + |
| 67 | +For existing clusters, use `az aks update` with `--enable-keda` option. The following code shows an example. |
| 68 | + |
| 69 | +```azurecli-interactive |
| 70 | +az aks update \ |
| 71 | + --resource-group myResourceGroup \ |
| 72 | + --name myAKSCluster \ |
| 73 | + --enable-keda |
| 74 | +``` |
| 75 | + |
| 76 | +## Get the credentials for your cluster |
| 77 | + |
| 78 | +Get the credentials for your AKS cluster by using the `az aks get-credentials` command. The following example command gets the credentials for *myAKSCluster* in the *myResourceGroup* resource group: |
| 79 | + |
| 80 | +```azurecli-interactive |
| 81 | +az aks get-credentials --resource-group myResourceGroup --name myAKSCluster |
| 82 | +``` |
| 83 | + |
| 84 | +## Verify that the KEDA add-on is installed on your cluster |
| 85 | + |
| 86 | +To see if the KEDA add-on is installed on your cluster, verify that the `enabled` value is `true` for `keda` under `workloadAutoScalerProfile`. |
| 87 | + |
| 88 | +The following example shows the status of the KEDA add-on for *myAKSCluster* in *myResourceGroup*: |
| 89 | + |
| 90 | +```azurecli-interactive |
| 91 | +az aks show -g "myResourceGroup" --name myAKSCluster --query "workloadAutoScalerProfile.keda.enabled" |
| 92 | +``` |
| 93 | +## Verify that KEDA is running on your cluster |
| 94 | + |
| 95 | +You can verify KEDA that's running on your cluster. Use `kubectl` to display the operator and metrics server installed in the AKS cluster under kube-system namespace. For example: |
| 96 | + |
| 97 | +```azurecli-interactive |
| 98 | +kubectl get pods -n kube-system |
| 99 | +``` |
| 100 | + |
| 101 | +The following example output shows that the KEDA operator and metrics API server are installed in the AKS cluster along with its status. |
| 102 | + |
| 103 | +```output |
| 104 | +kubectl get pods -n kube-system |
| 105 | +
|
| 106 | +keda-operator-********-k5rfv 1/1 Running 0 43m |
| 107 | +keda-operator-metrics-apiserver-*******-sj857 1/1 Running 0 43m |
| 108 | +``` |
| 109 | +To verify the version of your KEDA, use `kubectl get crd/scaledobjects.keda.sh -o yaml `. For example: |
| 110 | + |
| 111 | +```azurecli-interactive |
| 112 | +kubectl get crd/scaledobjects.keda.sh -o yaml |
| 113 | +``` |
| 114 | +The following example output shows the configuration of KEDA in the `app.kubernetes.io/version` label: |
| 115 | + |
| 116 | +```yaml |
| 117 | +kind: CustomResourceDefinition |
| 118 | +metadata: |
| 119 | + annotations: |
| 120 | + controller-gen.kubebuilder.io/version: v0.8.0 |
| 121 | + creationTimestamp: "2022-06-08T10:31:06Z" |
| 122 | + generation: 1 |
| 123 | + labels: |
| 124 | + addonmanager.kubernetes.io/mode: Reconcile |
| 125 | + app.kubernetes.io/component: operator |
| 126 | + app.kubernetes.io/name: keda-operator |
| 127 | + app.kubernetes.io/part-of: keda-operator |
| 128 | + app.kubernetes.io/version: 2.7.0 |
| 129 | + name: scaledobjects.keda.sh |
| 130 | + resourceVersion: "2899" |
| 131 | + uid: 85b8dec7-c3da-4059-8031-5954dc888a0b |
| 132 | +spec: |
| 133 | + conversion: |
| 134 | + strategy: None |
| 135 | + group: keda.sh |
| 136 | + names: |
| 137 | + kind: ScaledObject |
| 138 | + listKind: ScaledObjectList |
| 139 | + plural: scaledobjects |
| 140 | + shortNames: |
| 141 | + - so |
| 142 | + singular: scaledobject |
| 143 | + scope: Namespaced |
| 144 | + # Redacted for simplicity |
| 145 | + ``` |
| 146 | + |
| 147 | +While KEDA provides various customization options, the KEDA add-on currently provides basic common configuration. |
| 148 | + |
| 149 | +If you have requirement to run with another custom configurations, such as namespaces that should be watched or tweaking the log level, then you may edit the KEDA YAML manually and deploy it. |
| 150 | + |
| 151 | +However, when the installation is customized there will no support offered for custom configurations. |
| 152 | + |
| 153 | +## Disable KEDA add-on from your AKS cluster |
| 154 | + |
| 155 | +When you no longer need KEDA add-on in the cluster, use the `az aks update` command with--disable-keda option. This execution will disable KEDA workload auto-scaler. |
| 156 | + |
| 157 | +```azurecli-interactive |
| 158 | +az aks update \ |
| 159 | + --resource-group myResourceGroup \ |
| 160 | + --name myAKSCluster \ |
| 161 | + --disable-keda |
| 162 | +``` |
| 163 | + |
| 164 | +### Enabling add-on on clusters with self-managed open-source KEDA installations |
| 165 | + |
| 166 | +While Kubernetes only allows one metric server to be installed, you can in theory install KEDA multiple times. However, it isn't recommended given only one installation will work. |
| 167 | + |
| 168 | +When the KEDA add-on is installed in an AKS cluster, the previous installation of open-source KEDA will be overridden and the add-on will take over. |
| 169 | + |
| 170 | +This means that the customization and configuration of the self-installed KEDA deployment will get lost and no longer be applied. |
| 171 | + |
| 172 | +While there's a possibility that the existing autoscaling will keep on working, there's a risk given it will be configured differently and won't support features such as managed identity. |
| 173 | + |
| 174 | +It's recommended to uninstall existing KEDA installations before enabling the KEDA add-on given the installation will succeed without any error. |
| 175 | + |
| 176 | +Following error will be thrown in the operator logs but the installation of KEDA add-on will be completed. |
| 177 | + |
| 178 | +Error logged in now-suppressed non-participating KEDA operator pod: |
| 179 | +the error logged inside the already installed KEDA operator logs. |
| 180 | +E0520 11:51:24.868081 1 leaderelection.go:330] error retrieving resource lock default/operator.keda.sh: config maps "operator.keda.sh" is forbidden: User "system:serviceaccount:default:keda-operator" can't get resource "config maps" in API group "" in the namespace "default" |
| 181 | + |
| 182 | +## Next steps |
| 183 | +This article showed you how to install the KEDA add-on on an AKS cluster using Azure CLI. The steps to verify that KEDA add-on is installed and running are included. With the KEDA add-on installed on your cluster, you can [deploy a sample application][keda-sample] to start scaling apps. |
| 184 | + |
| 185 | +[az-aks-create]: /cli/azure/aks#az-aks-create |
| 186 | +[az aks install-cli]: /cli/azure/aks#az-aks-install-cli |
| 187 | +[az aks get-credentials]: /cli/azure/aks#az-aks-get-credentials |
| 188 | +[az aks update]: /cli/azure/aks#az-aks-update |
| 189 | +[az-group-delete]: /cli/azure/group#az-group-delete |
| 190 | + |
| 191 | +[kubectl]: https://kubernetes.io/docs/user-guide/kubectl |
| 192 | +[keda]: https://keda.sh/ |
| 193 | +[keda-scalers]: https://keda.sh/docs/scalers/ |
| 194 | +[keda-sample]: https://github.com/kedacore/sample-dotnet-worker-servicebus-queue |
| 195 | + |
0 commit comments