follow the guide to install metrics-server on your kubernetes cluster
git clone https://github.com/cheferrari/hpa
kubectl create ns test
kubectl apply -f web-deploy.yaml
kubectl apply -f web-svc.yaml
kubectl apply -f web-hpa.yaml
# kubectl get hpa -owide -w
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
web-hpa Deployment/web 0%/50% 2 8 3 3m21s
#install hey
go get -u github.com/rakyll/hey
#do 10K requests
hey -n 10000 -q 10 -c 5 http://<WEB_SVC_IP>:80/
kubectl apply -f hpa-load.yaml
# kubectl describe hpa
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulRescale 29m horizontal-pod-autoscaler New size: 5; reason: cpu resource utilization (percentage of request) above target
Normal SuccessfulRescale 28m horizontal-pod-autoscaler New size: 8; reason: cpu resource utilization (percentage of request) above target
monitor the hpa:
# kubectl get hpa -owide -w
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
web-hpa Deployment/web 0%/50% 2 8 3 3m21s
web-hpa Deployment/web 80%/50% 2 8 3 5m45s
web-hpa Deployment/web 80%/50% 2 8 5 6m
web-hpa Deployment/web 76%/50% 2 8 5 6m16s
web-hpa Deployment/web 82%/50% 2 8 5 6m46s
web-hpa Deployment/web 82%/50% 2 8 8 7m1s
web-hpa Deployment/web 78%/50% 2 8 8 7m17s
web-hpa Deployment/web 77%/50% 2 8 8 7m47s
kubectl delete -f hpa-load.yaml
monitor the HPA events:
# kubectl describe hpa web-hpa
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulRescale 29m horizontal-pod-autoscaler New size: 5; reason: cpu resource utilization (percentage of request) above target
Normal SuccessfulRescale 28m horizontal-pod-autoscaler New size: 8; reason: cpu resource utilization (percentage of request) above target
Normal SuccessfulRescale 5m28s horizontal-pod-autoscaler New size: 4; reason: All metrics below target
Normal SuccessfulRescale 4m57s horizontal-pod-autoscaler New size: 2; reason: All metrics below target