Scale on queue length with KEDA
The keda add-on scales workloads on events, and on the length of your {{product}} queues with no key in the cluster.
Replace my-cluster with your cluster's name or id and orders with one of your queues.
The keda add-on runs KEDA: a ScaledObject scales a Deployment (to zero, too) on an event source,
a ScaledJob starts Jobs. For your Deutsche Cloud queues, list them in the add-on's queues: KEDA then
reads their length as the IAM service account eks-keda-<cluster id>, whose only permission is
queue:GetQueueAttributes on those queues. It gets temporary credentials for its own
service-account token, so no key is stored in the cluster. Every other KEDA scaler works with your
own TriggerAuthentication.
The listed queues' lengths (never their messages) are readable by every ScaledObject in the cluster.
Prerequisites
- Permission for
eks:CreateAddonon the cluster andqueue:GetQueueAttributeson each queue. In the console, alsoeks:DescribeClusterto open the cluster.
Install the add-on
- Open Kubernetes, open the cluster, then choose Add-ons.
- Choose Add an add-on, then Event autoscaling (KEDA).
- Add the queues whose length should drive scaling.
- Choose Install.
dcloud eks addons create my-cluster --name keda --config 'queues=["orders"]'POST /eks/api/clusters/my-cluster/addons
{ "name": "keda", "config": { "queues": ["orders"] } }resource "dcloud_eks_addon" "keda" {
cluster_id = dcloud_eks_cluster.main.id
name = "keda"
config = jsonencode({ queues = ["orders"] })
}Scale a worker on its queue
The queue's URL is on the queue's page and in dcloud queue queues get.
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata: { name: ews-queues, namespace: shop }
spec:
podIdentity: { provider: aws }
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata: { name: worker, namespace: shop }
spec:
scaleTargetRef: { name: worker }
minReplicaCount: 0
maxReplicaCount: 20
triggers:
- type: aws-sqs-queue
authenticationRef: { name: ews-queues }
metadata:
queueURL: https://sqs.example/123/orders
queueLength: '10'
awsRegion: de1The worker runs one replica per ten waiting messages, and none while the queue is empty.