Keda Add-on¶
This add-on installs Keda Kubernetes-based Event Driven Autoscaling.
KEDA allows for fine-grained autoscaling (including to/from zero) for event driven Kubernetes workloads. KEDA serves as a Kubernetes Metrics Server and allows users to define autoscaling rules using a dedicated Kubernetes custom resource definition.
Usage¶
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import * as blueprints from '@aws-quickstart/eks-blueprints';
const app = new cdk.App();
# Normal Usage
# const addOn = new blueprints.addons.KedaAddOn();
# In case of AWS SQS, there is a workaround required when initializing keda (Please refer https://github.com/kedacore/keda/issues/837#issuecomment-789037326 )
const kedaParams = {
podSecurityContextFsGroup: 1001,
securityContextRunAsGroup: 1001,
securityContextRunAsUser: 1001,
irsaRoles: ["CloudWatchFullAccess", "AmazonSQSFullAccess"]
}
const addOn = new blueprints.addons.KedaAddOn(kedaParams)
const blueprint = blueprints.EksBlueprint.builder()
.version("auto")
.addOns(addOn)
.build(app, 'my-stack-name');
Configuration Options¶
version
: Version fo the Helm Chart to be used to install KedakedaOperatorName
: Name of the KEDA operatorcreateServiceAccount
: Specifies whether a service account should be created by Keda.kedaServiceAccountName
: The name of the service account to use. If not set and create is true, a name is generated.podSecurityContextFsGroup
: PodSecurityContext holds pod-level security attributes and common container settings. fsGroup is a special supplemental group that applies to all containers in a pod. This is an optional attribute, exposed directly in order to make KedaScalar workaroud - https://github.com/kedacore/keda/issues/837#issuecomment-789037326securityContextRunAsUser
: SecurityContext holds security configuration that will be applied to a container. runAsUser is the UID to run the entrypoint of the container process. This is an optional attribute, exposed directly in order to make KedaScalar workaroud - https://github.com/kedacore/keda/issues/837#issuecomment-789037326securityContextRunAsGroup
: SecurityContext holds security configuration that will be applied to a container. runAsGroup is the GID to run the entrypoint of the container process. This is an optional attribute, exposed directly in order to make KedaScalar workaroud - https://github.com/kedacore/keda/issues/837#issuecomment-789037326irsaRoles
- An array of Managed IAM Policies which Service Account needs for IRSA Eg: irsaRoles:["CloudWatchFullAccess","AmazonSQSFullAccess"]. If not empty the Service Account will be created by the CDK with IAM Roles Mapped (IRSA). In case if its empty, Keda will create the Service Account with out IAM Rolesvalues
: Arbitrary values to pass to the chart. Refer to the Keda Helm Chart documentation for additional details
Validation¶
To validate that Keda is installed properly in the cluster, check that the Keda deployments, services and stateful sets are running.
kubectl get deployments -n keda
kubectl get pods -n keda
kubectl describe pods keda-operator-8c5967bcd-vlhpd -n keda | grep -i aws
kubectl get sa -n keda
kubectl describe sa keda-operator -n keda
Testing¶
We will test AWS SQS Scalar here 1) Create SQS Queue in desired region Replace ${AWS_REGION} with your target region
aws sqs create-queue --queue-name keda-test --region ${AWS_REGION} --output json
kubectl create ns sqs-consumer
kubectl create deployment sqs-consumer --image nginx -n sqs-consumer
---
apiVersion: keda.sh/v1alpha1 # https://keda.sh/docs/2.0/concepts/scaling-deployments/
kind: ScaledObject
metadata:
name: sqs-consumer-keda-scaler
namespace: sqs-consumer
labels:
app: sqs-consumer
deploymentName: sqs-consumer
spec:
scaleTargetRef:
kind: Deployment
name: sqs-consumer
minReplicaCount: 1
maxReplicaCount: 50
pollingInterval: 10
cooldownPeriod: 500
triggers:
- type: aws-sqs-queue
metadata:
queueURL: https://sqs.${AWS_REGION}.amazonaws.com/ACCOUNT_NUMBER/sqs-consumer
queueLength: "5"
awsRegion: "${AWS_REGION}"
identityOwner: operator
---
kubectl apply -f keda-scalar.yaml
kubectl get hpa -n sqs-consumer
x=10
a=0
while [ $a -lt $x ]
do
aws sqs send-message --region ${AWS_REGION} --endpoint-url https://sqs.${AWS_REGION}.amazonaws.com/ --queue-url https://sqs.${AWS_REGION}.amazonaws.com/ACCOUNT_NUMBER/sqs-consumer --message-body '{"key": "value"}'
a=`expr $a + 1`
done
kubectl get pods -n sqs-consumer
aws sqs purge-queue --queue-url "https://sqs.${AWS_REGION}.amazonaws.com/CCOUNT_NUMBER/sqs-consumer"
kubectl get pods -n sqs-consumer
Functionality¶
- Installs keda in the cluster
- Sets up IRSA so that Pods can interact with AWS Services
- Supports standard helm configuration options.