🎓 A1Learner
🔍
0 of 51 lessons completed

Kubernetes Project: Expose It, Scale It, Break It

This project finishes the three-tier app. It exposes the app, scales the API, updates the image, and then breaks the deploy on purpose.

Open the app

The tunnel or service command opens a local address. A browser can then reach the frontend.

minikube service three-tier-web -n three-tier

Scale the API with the autoscaler

The autoscaler watches the API CPU use. It adds pods when the load rises.

kubectl autoscale deployment three-tier-api -n three-tier --cpu-percent=50 --min=2 --max=6
kubectl get hpa three-tier-api -n three-tier

Roll to a new image

The update swaps the API pods to version 2. The app stays up during the swap.

kubectl set image deployment/three-tier-api api=three-tier-api:v2 -n three-tier
kubectl rollout status deployment/three-tier-api -n three-tier

Break it on purpose

Tag v99 does not exist, so the new pods cannot pull it. The four-move routine finds the fault.

kubectl set image deployment/three-tier-api api=three-tier-api:v99 -n three-tier
kubectl describe pod -l app=three-tier-api -n three-tier | grep -A 2 Failed

Example

kubectl set image deployment/three-tier-api api=three-tier-api:v99 -n three-tier
kubectl get pods -l app=three-tier-api -n three-tier
kubectl describe pod three-tier-api-7d9f4b6c8-x2k9m -n three-tier | grep -A 2 Failed
kubectl rollout undo deployment/three-tier-api -n three-tier
kubectl get pods -l app=three-tier-api -n three-tier

Key points

  • Expose the app through the Gateway, so a browser outside the cluster can reach the frontend
  • Use minikube service to open a Service on a local cluster when no Gateway is installed
  • Use the Horizontal Pod Autoscaler on the API, so load adds API pods
  • Use a rolling update to move the API to a new image without downtime
  • Use a deliberately broken image to practise the four-move debug routine from lesson 42
  • Use kubectl logs --previous to read the crash logs of the broken deploy
  • Use kubectl rollout undo to return to the working image

In this example, the first command points the API at the missing tag v99. The second command shows the pod in ImagePullBackOff. The third command reads the pod Events, which name the missing image. The fourth command rolls back to the working image. The fifth command shows the pod running again.

Note

The broken deploy is on purpose, so the fix proves the routine works.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

After a deliberately broken deploy, what is the correct order of the fix?