Investigate KEDA to automatically scale consumer pods based on queue depth
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- helm, java, kubernetes, rabbitmq
- Domain
- distributed-systems, infrastructure
Research direction
Start by inspecting the repository's Helm chart and consumer Deployment templates, then compare the work needed to enable the Kubernetes Metrics API with installing KEDA. The issue does not name chart paths or queue details, so first identify how the consumer and RabbitMQ are configured. Done means documenting which approach is simpler and, if KEDA is chosen, outlining the chart and cluster changes required.
Written by the indexing model from the issue text.
Description
At the time of writing, the NCEAS K8s clusters do not have the Kubernetes Metrics Server available, so the standard Kubernetes Horizontal Pod Autoscaler (HPA) won't work because it relies on the Metrics API (CPU/memory metrics).
KEDA (Kubernetes Event-driven Autoscaling - website | GitHub) could be used to automatically scale consumer pods based on RabbitMQ queue depth, without relying on the Metrics API. This looks pretty simple (Google Gemini instructions below. Add salt). Worth doing only if this is simpler/quicker than making the Metrics API available.
Google Gemini
To automatically scale your Helm chart's consumer pods based on RabbitMQ queue depth without relying on the Kubernetes Metrics Server, the standard Kubernetes Horizontal Pod Autoscaler (HPA) won't work out of the box because it relies on the Metrics API (CPU/memory metrics).
Instead, the standard solution in the Kubernetes ecosystem is to use KEDA (Kubernetes Event-driven Autoscaling). KEDA acts as the Control Loop described in the article:
- Desired state: Target queue depth per pod (e.g., 5 messages per consumer).
- Sensor: KEDA checking RabbitMQ's API directly via its built-in RabbitMQ scaler.
- Control Element: Adjusting your Deployment's
spec.replicas.
Here is the straightforward step-by-step way to apply this concept to your existing Helm chart:
Step 1: Install KEDA on your Cluster
Since KEDA queries RabbitMQ directly, it does not require the Kubernetes Metrics Server API. Install KEDA once in your cluster using Helm:
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm install keda kedacore/keda --namespace keda --create-namespace
Step 2: Define a ScaledObject in Your Helm Chart
In your Helm chart's templates/ folder, add a new file named scaledobject.yaml. This resource tells KEDA how to monitor your RabbitMQ queue and control your consumer deployment.
templates/scaledobject.yaml:
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: {{ include "mychart.fullname" . }}-autoscaler
labels:
{{- include "mychart.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "mychart.fullname" . }}-consumer # Name of your consumer Deployment
minReplicaCount: {{ .Values.autoscaling.minReplicas | default 1 }}
maxReplicaCount: {{ .Values.autoscaling.maxReplicas | default 10 }}
cooldownPeriod: 300 # Seconds to wait before scaling down to 0 or minReplicas
triggers:
- type: rabbitmq
metadata:
protocol: amqp
queueName: {{ .Values.rabbitmq.queueName | quote }}
mode: QueueLength # Triggers on total unprocessed messages in the queue
value: {{ .Values.autoscaling.targetQueueLength | quote }} # Target messages per pod
authenticationRef:
name: keda-rabbitmq-auth
Step 3: Configure Authentication for KEDA
KEDA needs credentials to inspect your RabbitMQ queue length via the RabbitMQ API/AMQP protocol. Add a trigger authentication object alongside your ScaledObject:
templates/keda-auth.yaml:
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: keda-rabbitmq-auth
spec:
secretTargetRef:
- parameter: host
name: {{ .Values.rabbitmq.secretName }} # Name of your existing Kubernetes Secret
key: {{ .Values.rabbitmq.secretHostKey | default "RABBITMQ_URI" }} # e.g., amqp://user:[email protected]:5672/vhost
Step 4: Configure values.yaml
Update your chart's values.yaml to make the scaling behavior configurable:
autoscaling:
enabled: true
minReplicas: 1
maxReplicaCount: 10
targetQueueLength: "5" # ScaledObject will aim for 1 pod per 5 queued messages
rabbitmq:
queueName: "task_queue"
secretName: "rabbitmq-credentials"
secretHostKey: "AMQP_URL"
Step 5: Update Your Deployment Template
Ensure your consumer Deployment template (templates/deployment.yaml) does not hardcode a replicas count if autoscaling is enabled, or allow KEDA to take over replica management.
In templates/deployment.yaml:
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
...
How the Control Loop Operates in Practice
Once deployed, KEDA executes the loop continuously:
- Observe (Sensor): KEDA periodically checks RabbitMQ for
queueName. If 25 messages are sitting in the queue andtargetQueueLengthis5, it calculates that 5 pods are required ($25 / 5 = 5$). - Compare with Desired State: If you currently have 1 pod running, the state is out of balance.
- Act (Control Element): KEDA updates
spec.replicason your consumer Deployment to5. - Scale to Zero (Optional): If
minReplicaCountis set to0, KEDA will spin down all pods when the queue drops to 0 messages, saving cluster resources entirely until a new message arrives.
- Dominant language
- Java
- Stars
- 0
- Forks
- 2
- Avg merge
- 6d 6h
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DataONEorg/dataone-indexer
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
DataONEorg/dataone-indexer#390 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
DataONEorg/dataone-indexer#378 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
DataONEorg/dataone-indexer#362 · 8 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
DataONEorg/dataone-indexer#357 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
DataONEorg/dataone-indexer#348 ·
All issues in DataONEorg/dataone-indexer
Similar issues
-
enhancement good first issue storege-module
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
sdlc-pro/spring-lens#647 ·
Maintainers usually reply within 1 day
-
lang-java needs-triage package:jni package:jni_flutter package:jnigen
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
valkey-io/valkey-glide#7975 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
constellation-app/constellation#2613 ·
Maintainers usually reply within 2 days