autoscaling metric type - memory, not working (always create cpu metric based hpa)

129 Views Asked by At

I am trying to create hpa for memory based metric, so I provided the annotations in my service according to docs.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
        autoscaling.knative.dev/metric: "memory"

https://knative.dev/docs/serving/autoscaling/autoscaling-metrics/#setting-metrics-per-revision

HPA -> HPA as you can see, metric type is only CPU, I have also checked yaml output, but it always create a hpa with cpu metrics only, I don't have much experience with this autoscaling.

And the annotations are added to my hpa from service. Annotations in HPA

Any suggestions on this, or what I am doing wrong.

1

There are 1 best solutions below

0
Parneet Raghuvanshi On BEST ANSWER

finally after some research and expermients

Explanation:

To make the HPA work for knative service, we also need to specify the target as annotations, as we can see here:

enter image description here

This if condition for hpa will only work, if we specify some target for metric. https://github.com/knative/serving/blob/91ac3b335131565cb9304ed9f6259c959f71b996/pkg/reconciler/autoscaling/hpa/resources/hpa.go#L62

Solution:

now it works by adding one more annotation:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
        autoscaling.knative.dev/metric: "memory"
        autoscaling.knative.dev/target: "75"

now the hpa will be of metric type = memory enter image description here