Kubernetes: Horizontal Pod Autoscaler using Minikube


Clone git repository

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

Enable heapster & metrics-server

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

View minikube addons.

minikube addons list
addon-manager: enabled
coredns: disabled
dashboard: enabled
default-storageclass: enabled
efk: disabled
freshpod: disabled
heapster: enabled
ingress: disabled
kube-dns: enabled
metrics-server: enabled
nvidia-driver-installer: disabled
nvidia-gpu-device-plugin: disabled
registry: disabled
registry-creds: disabled
storage-provisioner: enabled

Heapster and metrics-server should be enabled by default, but if they are disabled, enable them.

minikube addons enable heapster
minikube addons enable metrics-server

View Grafana web UI

minikube addons open heapster

Create namespace

kubectl create -n itsmetommy

Create namespace

kubectl create -n itsmetommy

Create

kubectl create -f .

View website

minikube service -n itsmetommy hpa-example

Watch

Open two terminal windows and watch hpa and pods.

watch kubectl -n itsmetommy get all -l app=hpa-example

Get nodePort info

This is more of an FYI and how to view the nodePort. Get the nodePort of the service. In my case, the nodePort is 30512.

minikube service -n itsmetommy hpa-example --url
http://192.168.99.100:30512

Add load

I ran three while loops in three different terminal windows.

You can also note the targetAverageUtilization within hpa.yaml is set to 10 also to trigger the autoscale faster.

Terminal window 1

service=$(minikube service -n itsmetommy hpa-example --url)
while true; do curl $service; done

Terminal window 2

service=$(minikube service -n itsmetommy hpa-example --url)
while true; do curl $service; done

Terminal window 3

service=$(minikube service -n itsmetommy hpa-example --url)
while true; do curl $service; done

After you’ve added load to the service, you should see a second hpa-example pod created automatically to handle the load. Feel free to add additional load.

Also, check out the Grafana metrics for each pod.

Stop load

In each terminal, terminate the while loop by typing control + C.

You should eventually see the additinal pods terminating.

Clean up

kubectl delete -f .
,