Auto-scaling
For CKAD, you need to know how to manually scale Pods using kubectl scale etc.
In real clusters, Pods are often automatically scaled based on resource usage properties that are collected by the Metrics Server.
The Horizontal Pod Autoscaler observes usage statistics and after passing a threshold, will add additional replicas. Setting up AutoScaling is NOT required of CKAD, but as it is so important in real clusters you’ll find a demo how to do it.
This demo requires the use of Metrics Server, which is set up easily in Minikube. Setting up Metrics Server in other cluster types is covered in CKA.
Setting up Autoscaling
- Resources are in the course Git repository at GitHub - sandervanvugt/ckad
$ cd ckad/autoscaling
$ docker build -t php-apache .
$ kubectl apply -f hpa.yaml # using the image from the Dockerfile as provided by the image registry
$ kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
$ kubectl get hpa
# From another terminal: kubectl run -it load-generator --rm -- image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -0- [<http://php-apache>](<http://php-apache/>); done"
# Back to the original terminal: sleep 60; kubectl get hpa
$ minikube addons enable metrics-server
$ kubectl get hpa
$ kubectl get deploy php-apache
$ kubectl delete pod load-generator
$ kubectl get hpa
$ kubectl get deploy php-apache