I have this use case:
When there is much load on a specific queue in RabbitMQ, i want to start more replicas. Let's say, my app can handle 5 messages ( = tasks) simultaneously and they all take 1 min to complete. When there are more than 10 "ready" messages in the rabbitmq Queue, i want the HPA to start a new replica. When there are 20 "ready" messages, start 2, at 30 "ready" messages start 3 etc.
I used this helm chart for install prometheus-adapter:
https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-adapter
And in my helm values yaml i added:
rules:
default: true
custom:
- seriesQuery: '{__name__=~"rabbitmq_detailed_queue_messages_ready"}'
name:
matches: "^(.*)"
as: "open_tasks"
resources:
overrides:
kubernetes_namespace: { resource: "namespace" }
kubernetes_name: { resource: "service" }
metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>,queue="my-task-queue"}) by (<<.GroupBy>>)
Now, this should be exposed, but it isn't:
$ kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 | jq . | grep open_tasks
Now this is my main question. After that i could deploy an HPA for my app task-processor
like this:
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2
metadata:
name: task-processor-autoscaler
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: task-processor
minReplicas: 1
maxReplicas: 10
metrics:
- type: Object
object:
metric:
name: open_tasks
describedObject:
apiVersion: "/v1"
kind: Service
name: open_tasks
target:
type: Value
value: 10
Now my questions:
- Why is the metric not exposed in the raw query?
- Is my yaml for the HPA correct? I have the feeling that i'm missing some essential stuff here, but i'm not able to get my head around that.