Horizontal Pod Autoscaler

It increases/ decreases no. of replicas in deployment ( control’s no. of replicas ) based on cpu utilisation, RAM..

image.png

Horizontal Scaling : Adding more pods to cluster

Vertical Scaling : Increase size of machines ( 4 core → 8 core ). Pods will have access to more resources.

Architecture

An infinite control loop constantly checks cpu utilisation in pods.

Tracking metrics in K8s Cluster

View resource usage with the Kubernetes Metrics Server - Amazon EKS

Step 1 : Create a K8s Cluster

eksctl create cluster --name hpa-cluster --region ap-south-1 --nodes 3 --node-type t2.medium

Step 2 : Add metricsServer to your K8s Cluster

kubectl apply -f <https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml>

Step 3 : Clean re-install

Your cluster already had a metrics-server Deployment installed earlier (maybe via EKS addons or Helm), and kubectl apply is trying to patch it, which is failing because:

  1. Duplicate port name https → The Deployment manifest you applied has two container ports both named https.
  2. Selector is immutable → Kubernetes doesn’t allow you to change .spec.selector after a Deployment is created. Since the one you applied differs from the existing one, it errors out.