Kubernetes Horizontal Pod Autoscaler

Luca Berton
4 min readOct 30, 2024

This is a Kubernetes YAML configuration file for a HorizontalPodAutoscaler (HPA). It defines how a Kubernetes deployment should scale based on the CPU utilization of the pods.

Explanation of the YAML:

  • apiVersion: autoscaling/v2:
  • This specifies the version of the HPA API, where v2 allows more advanced autoscaling features, including custom metrics.
  • kind: HorizontalPodAutoscaler:
  • This specifies that the object being created is an HPA, which will automatically adjust the number of pod replicas based on observed metrics.
  • metadata:
  • name: nginx-hpa:
  • This gives the HPA a name, nginx-hpa, for identification.

spec:

scaleTargetRef:

  • apiVersion: apps/v1: Specifies the API version of the deployment resource that the HPA will control.
  • kind: Deployment: Indicates that the HPA is scaling a Kubernetes deployment.
  • name: nginx-deployment: The name of the deployment to scale.

minReplicas: 2:

  • This ensures that at least 2 replicas (pods) will always be running, regardless of CPU utilization.

--

--

Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday