<p>I am running an <a href="https://aws.amazon.com/eks/" rel="nofollow noreferrer">EKS</a> cluster and I have a <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">HorizontalPodAutoscaler</a> created for autoscaling number of pods based on average CPU utilisation.</p>

<p>How to do the same for Average memory utilization?</p>

<p>Suppose all of the pods running in an EKS clusters, have used average of 70% of memory they are allocated (using <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/" rel="nofollow noreferrer">resources</a>), then the deployment should be autoscaled.</p>

<p>How to do this? Is creating a custom metric in <a href="https://aws.amazon.com/cloudwatch/" rel="nofollow noreferrer">CloudWatch</a> the only way?</p>

<p>Even if cloudWatch is the only way, how to do that? Is there a specific documentation or tutorial or blog that does this?</p>

Yash Gurav
<p>Please try the below <code>HPA</code> configuration object.</p>

<pre><code>apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: nginx-hpa
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: nginx
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: memory
      targetAverageUtilization: 70
</code></pre>

<p>and apply the object using <code>kubectl apply</code> </p>
