Watch all our Tutorials and Training Videos for Free on our Youtube Channel, Get Online Web Tools for Free on

Search Suggest

Understanding and Implementing Horizontal Pod Autoscaler on Amazon EKS

Understanding and Implementing Horizontal Pod Autoscaler on Amazon EKS, what is Horizontal Pod Autoscaler, Horizontal Pod Autoscaler in eks
Understanding and Implementing Horizontal Pod Autoscaler on Amazon EKS

If you're running containerized workloads on Amazon Elastic Kubernetes Service (EKS), you may have experienced the need to scale your pods up or down based on the workload demands. In such cases, the Horizontal Pod Autoscaler (HPA) is a useful tool that automatically adjusts the number of replicas in a Kubernetes deployment based on resource utilization metrics.

In this article, we'll explore how to configure and use the HPA on Amazon EKS, including the necessary prerequisites, commands, and step-by-step instructions.


Before we dive into the setup and configuration of the HPA, ensure that you have the following prerequisites in place:

  • An active Amazon EKS cluster
  • Kubernetes CLI tool (kubectl) installed and configured
  • A running Kubernetes deployment with at least one replica

Configuring Horizontal Pod Autoscaler on Amazon EKS

Follow the below steps to configure HPA on your Amazon EKS cluster:

  1. Create a Kubernetes deployment

Create a Kubernetes deployment with the desired number of replicas. You can use the following command to create a simple deployment with a single replica:
kubectl create deployment nginx --image=nginx

  1. Expose the deployment

Expose the deployment using a Kubernetes service to make it accessible from outside the cluster:
kubectl expose deployment nginx --port=80 --type=LoadBalancer

  1. Check the deployment and service

Verify that the deployment and service are running correctly using the following commands:
kubectl get deployments
kubectl get services

  1. Create a Horizontal Pod Autoscaler

Create an HPA for your deployment using the following command:
kubectl autoscale deployment nginx --cpu-percent=50 --min=1 --max=10

This command creates an HPA that targets the deployment named "nginx," scales up when the CPU utilization of the pods in the deployment exceeds 50%, and scales down when the CPU utilization goes below 50%. The minimum and maximum number of replicas are set to 1 and 10, respectively.

  1. Check the HPA

Check the status of the HPA using the following command:
kubectl get hpa

You should see the HPA you just created in the output.

Testing the Horizontal Pod Autoscaler

To test the HPA, we need to simulate high resource utilization by running a stress test. You can use the following command to simulate high CPU usage:

kubectl run -i --tty load-generator --image=busybox /bin/sh
while true; do wget -q -O- http://nginx; done

This command creates a busybox pod that continuously sends requests to the Nginx deployment we created earlier.

To monitor the HPA, open a new terminal window and run the following command:

watch kubectl get hpa

This command will update the HPA status every two seconds. You should see the number of replicas increase as the CPU utilization exceeds the threshold.

In this article, we explored how to configure and use the Horizontal Pod Autoscaler on Amazon EKS. With HPA, you can automatically scale your Kubernetes deployments based on resource utilization metrics, making it easier to manage and optimize your containerized workloads.

Related Searches and Questions asked:

  • Kube-Green Explained with Examples
  • Understanding Horizontal Pod Autoscaler in Kubernetes
  • How to Install Docker on Linux Mint
  • Understanding Vertical Pod Autoscaler in Kubernetes
  • That's it for this post. Keep practicing and have fun. Leave your comments if any.