[//]: # (Confidential document)
[//]: # (01/05/2025)
[//]: # (v 1.7.3)

# Kubernetes  labs v1.7.3
##  Scalability : Horizontal Pod Autoscaler  HPA

HorizontalPodAutoscaler automatically updates a workload resource (such as a Deployment or StatefulSet), with the aim of automatically scaling the workload to match demand.
Horizontal scaling means that the response to increased load is to deploy more Pods. This is different from vertical scaling, which for Kubernetes would mean assigning more resources (for example: memory or CPU) to the Pods that are already running for the workload.
If the load decreases, and the number of Pods is above the configured minimum, the HorizontalPodAutoscaler instructs the workload resource (the Deployment, StatefulSet, or other similar resource) to scale back down.
Horizontal pod autoscaling does not apply to objects that can't be scaled (for example: a DaemonSet.)

The HorizontalPodAutoscaler is implemented as a Kubernetes API resource and a controller. The resource determines the behavior of the controller. The horizontal pod autoscaling controller, running within the Kubernetes control plane, periodically adjusts the desired scale of its target (for example, a Deployment) to match observed metrics such as average CPU utilization, average memory utilization, or any other custom metric you specify.


## lab 1 : HPA

 - Enable the addon Metric server.
 - Apply the Deployment and Service manifest
 - list pods
 - Create Horizontal Pod Autoscaler
 - Check the current status of autoscaler
 - Increase load
 - Within a minute or so, --> higher CPU load
 - list pods
 - Stop load

```
minikube addons enable metrics-server

kubectl create -f manifests/php-apache-deploy.yaml
kubectl get po 

kubectl create -f manifests/php-apache-hpa.yaml
kubectl get hpa
kubectl run  -it --rm load-generator --image=busybox /bin/sh
# while true; do wget -q -O- http://php-apache.default.svc.cluster.local; done

kubectl get hpa
kubectl get deployment php-apache

kubectl get hpa
kubectl get deployment php-apache
```

## Clean up

```shell
kubectl delete deploy php-apache
kubectl delete svc php-apache
kubectl delete hpa php-apache
kubectl delete pod load-generator
```