<p>I am trying to create hpa for memory based metric, so I provided the annotations in my service according to docs.</p>
<pre><code>apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/class: &quot;hpa.autoscaling.knative.dev&quot;
        autoscaling.knative.dev/metric: &quot;memory&quot;
</code></pre>
<p><a href="https://knative.dev/docs/serving/autoscaling/autoscaling-metrics/#setting-metrics-per-revision" rel="nofollow noreferrer">https://knative.dev/docs/serving/autoscaling/autoscaling-metrics/#setting-metrics-per-revision</a></p>
<p>HPA -&gt;
<img src="https://i.stack.imgur.com/H0YVE.png" alt="HPA" />
as you can see, metric type is only CPU, I have also checked yaml output, but it always create a <strong>hpa</strong> with <strong>cpu</strong> metrics only, I don't have much experience with this autoscaling.</p>
<p>And the annotations are added to my hpa from service.
<img src="https://i.stack.imgur.com/s3uhH.png" alt="Annotations in HPA" /></p>
<p>Any suggestions on this, or what I am doing wrong.</p>

Parneet Raghuvanshi
<p>finally after some research and expermients</p>
<h3>Explanation:</h3>
<p>To make the HPA work for knative service, we also need to specify the target as annotations, as we can see here:</p>
<p><a href="https://i.stack.imgur.com/kUjPW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kUjPW.png" alt="enter image description here" /></a></p>
<p>This <strong>if</strong> condition for hpa will only work, if we specify some target for metric.
<a href="https://github.com/knative/serving/blob/91ac3b335131565cb9304ed9f6259c959f71b996/pkg/reconciler/autoscaling/hpa/resources/hpa.go#L62" rel="nofollow noreferrer">https://github.com/knative/serving/blob/91ac3b335131565cb9304ed9f6259c959f71b996/pkg/reconciler/autoscaling/hpa/resources/hpa.go#L62</a></p>
<h3>Solution:</h3>
<p>now it works by adding one more annotation:</p>
<pre><code>apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/class: &quot;hpa.autoscaling.knative.dev&quot;
        autoscaling.knative.dev/metric: &quot;memory&quot;
        autoscaling.knative.dev/target: &quot;75&quot;
</code></pre>
<p>now the <strong>hpa</strong> will be of metric type = memory
<a href="https://i.stack.imgur.com/WW1sb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WW1sb.png" alt="enter image description here" /></a></p>
