Photo by Shubham Dhage on Unsplash

Photo by Shubham Dhage on Unsplash

Here’s a ready-to-run “one-shot” demo workflow for Minikube that sets up a webserver deployment, exposes it, configures HPA, and generates load so you can see autoscaling in action immediately.

You can copy-paste these commands one after the other in your terminal.

Step 0: (Optional) Clean up old resources

kubectl delete deployment webserver --ignore-not-found
kubectl delete svc webserver --ignore-not-found
kubectl delete hpa webserver --ignore-not-found
kubectl delete pod load-generator --ignore-not-found

Step 1: Create the webserver deployment

kubectl create deployment webserver --image=gcr.io/google_containers/echoserver:1.10

Step 2: Expose the deployment as a NodePort service

kubectl expose deployment webserver –type=NodePort –port=8080

Check service:

kubectl get svc webserver

Step 3: Enable metrics-server if not already

minikube addons enable metrics-server

Step 4: Create Horizontal Pod Autoscaler

kubectl autoscale deployment webserver –cpu=20% –min=1 –max=5

Check HPA:

kubectl get hpa

Step 5: Launch load-generator pod

kubectl run -i –tty load-generator –image=busybox – /bin/sh

Inside the pod, generate heavy load:

while true; do wget -q -O- http://webserver:8080 & done

  • The & ensures requests run in parallel for higher CPU usage.
  • This will trigger the HPA to scale the webserver pods.

Step 6: Watch autoscaling in another terminal

kubectl get hpa -w
kubectl get pods -w

  • You will see replicas increase as CPU usage rises.
  • When you stop the load (Ctrl+C in the BusyBox pod), HPA will scale pods back down.

Step 7: Optional — test webserver from host

minikube service webserver

  • Opens your webserver in the browser.