How to autoscale Kubernetes Pods based on average memory usage in EKS?

5/25/2020

I am running an EKS cluster and I have a HorizontalPodAutoscaler created for autoscaling number of pods based on average CPU utilisation.

How to do the same for Average memory utilization?

Suppose all of the pods running in an EKS clusters, have used average of 70% of memory they are allocated (using resources), then the deployment should be autoscaled.

How to do this? Is creating a custom metric in CloudWatch the only way?

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

-- Yash Gurav
amazon-cloudwatch
amazon-eks
autoscaling
hpa
kubernetes

1 Answer

5/25/2020

Please try the below HPA configuration object.

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

and apply the object using kubectl apply

-- nischay goyal
Source: StackOverflow