Kubernetes: Horizontal Pod Autoscaler using Minikube

Clone git repository

https://github.com/itsmetommy/minikube-hpa

Enable heapster & metrics-server

Heapster is resource usage analysis and monitoring tool which collects compute resource usage.

minikube addons enable heapster
minikube addons enable metrics-server

View cAdvisor web UI

minikube addons open heapster

Create

kubectl create -f .

View website

minikube service autoscale-example

Watch

Open two terminal windows and watch hpa and pods.

watch kubectl describe hpa
watch kubectl get pods

Add load

I ran three load-generators in three different terminal windows in order to trigger the autoscale faster.

You can also note the targetCPUUtilizationPercentage  within autoscaler.yaml is set to 10 also to trigger the autoscale faster.

Terminal window 1

kubectl run -it --rm --restart=Never load-generator1 --image=busybox \
-- sh -c "while true; do wget -q -O- http://autoscale-example.default.svc.cluster.local:31001; done"

Terminal window 2

kubectl run -it --rm --restart=Never load-generator2 --image=busybox \
-- sh -c "while true; do wget -q -O- http://autoscale-example.default.svc.cluster.local:31001; done"

Terminal window 3

kubectl run -it --rm --restart=Never load-generator3 --image=busybox \
-- sh -c "while true; do wget -q -O- http://autoscale-example.default.svc.cluster.local:31001; done"

After you’ve added load to the service, you should see a few pods created automatically to handle the load.

Clean up

kubectl delete -f .