Configure KEDA
When installed, KEDA creates several custom resources. One of those resources, a ScaledObject
, enables you to map an external event source to a Deployment or StatefulSet for scaling. In this lab, we'll create a ScaledObject
that targets the ui
Deployment and scales this workload based on the RequestCountPerTarget
metric in CloudWatch.
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: ui-hpa
namespace: ui
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ui
pollingInterval: 30
cooldownPeriod: 300
minReplicaCount: 1
maxReplicaCount: 10
triggers:
- type: aws-cloudwatch
metadata:
namespace: AWS/ApplicationELB
expression: SELECT COUNT(RequestCountPerTarget) FROM SCHEMA("AWS/ApplicationELB", LoadBalancer, TargetGroup) WHERE TargetGroup = '${TARGETGROUP_ID}' AND LoadBalancer = '${ALB_ID}'
metricStat: Sum
metricStatPeriod: "60"
metricUnit: Count
targetMetricValue: "100"
minMetricValue: "0"
awsRegion: "${AWS_REGION}"
identityOwner: operator
This is the resource KEDA will scale. The name
is the name of the deployment you are targeting and your ScaledObject
must be in the same namespace as the Deployment
The minimum number of replicas that KEDA will scale the deployment to
The maximum number of replicas that KEDA will scale the deployment to
The expression
uses CloudWatch Metrics Insights syntax to select your target metric. When the targetMetricValue
is exceeded, KEDA will scale out the workload to support the increased load. In our case, if the RequestCountPerTarget
is greater than 100, KEDA will scale the deployment.
More details on the AWS CloudWatch scaler can be found here.
First we need to gather some information about the Application Load Balancer (ALB) and Target Group that were created as part of the lab pre-requisites.
Now we can use those values to update the configuration of our ScaledObject
and create the resource in the cluster.