<p>I'm trying to understand how the Kubernetes <strong>HorizontalPodAutoscaler</strong> works.
Until now, I have used the following configuration:</p>
<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: my-deployment
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-deployment
  minReplicas: 1
  maxReplicas: 10
  targetCPUUtilizationPercentage: 50
</code></pre>
<p>This uses the <code>targetCPUUtilizationPercentage</code> parameter but I would like to use a metric for the memory percentage used, but I was not able to find any example.
Any hint?</p>
<p>I found also that there is this type of configuration to support multiple metrics, but the <strong>apiVersion</strong> is <code>autoscaling/v2alpha1</code>. Can this be used in a production environment?</p>
<pre><code>kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2alpha1
metadata:
  name: WebFrontend
spec:
  scaleTargetRef:
    kind: ReplicationController
    name: WebFrontend
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 80
  - type: Object
    object:
      target:
        kind: Service
        name: Frontend
      metricName: hits-per-second
      targetValue: 1k
</code></pre>

Salvatore Calla'
<p>Here is a manifest example for what you need, that includes <strong>Memory Metrics</strong>:</p>
<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: web-servers
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web-servers
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 20
  - type: Resource
    resource:
      name: memory
      target:
        type: AverageValue
        averageValue: 30Mi
</code></pre>
<p>An important thing to notice is that, as you can see, it uses the <strong>autoscaling/v2beta2 API version</strong>, so you need to follow all the previous instructions listed <a href="https://loft.sh/blog/kubernetes-horizontal-pod-autoscaling/" rel="nofollow noreferrer">here</a>.</p>
<p>Regarding the possibility to use the <strong>autoscaling/v2alpha1</strong>, yes, you can use it, as it includes support for scaling on memory and custom metrics as this <a href="https://unofficial-kubernetes.readthedocs.io/en/latest/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">URL</a> specifies, but keep in mind that alpha versions are released for testing, as they are not final versions.</p>
<p>For more <strong>autoscaling/v2beta2 YAML’s</strong> examples and a deeper look into memory metrics, you can take a look at this <a href="https://stackoverflow.com/questions/69184304/how-memory-metric-is-evaluated-by-kubernetes-hpa">thread</a>.</p>
