HPA means `Horizontal Pod Autoscaler`. It automatically scales the number of pods in a replication controller, deployment or replica set based on observed CPU utilization (or, with custom metrics support, on some other application-provided metrics).
Let's see an HPA in action. This exemple is inspired by [the official Kubernetes documentation](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/).
To see it in action, we need to have a workload that consumes some CPU. We'll use an image that is CPU intensive: https://hub.docker.com/r/googlecontainer/hpa-example.
This image computes the square root of numbers:
```php
<?php
$x = 0.0001;
for ($i = 0; $i <= 1000000; $i++) {
$x += sqrt($x);
}
echo "OK!";
?>
```
First, you need to active the [`metric-server`](https://github.com/kubernetes-incubator/metrics-server/) on minikube:
```sh
minikube addons enable metrics-server
```
Review and apply the file [01-hpa.yml](./01-hpa.yml).
Now let's generate some load on our service:
```sh
kubectl run -i --tty load-generator --image=busybox /bin/sh
```
Then run in this terminal:
```sh
while true; do wget -q -O- http://hpa-example; done
```
In another terminal look at the state of the pods and the hpa, remember the `-w` flag on `kubectl`.
Wait a bit and see how it changes the pods and the hpa.
Stop the load generator, again, wait a bit and see how it changes the pods and the hpa.
## VPA
VPA means `Vertical Pod Autoscaler`. It automatically find the right resources for pods in a replication controller, deployment or replica set based on observed CPU utilization.
1. Install the [vpa](https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler):
```sh
cd vertical-pod-autoscaler && ./hack/vpa-up.sh
```
1. Try the exemple from the [vpa github repo](https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler#test-your-installation):
```sh
kubectl apply -f examples/hamster.yaml
```
Look at the file [hamster.yaml](https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler/examples). It contains the VPA definition: