0
0
Kubernetesdevops~30 mins

Horizontal Pod Autoscaler in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Horizontal Pod Autoscaler
📖 Scenario: You manage a web application running on Kubernetes. To handle varying user traffic, you want to automatically adjust the number of pods based on CPU usage.
🎯 Goal: Learn how to create a Horizontal Pod Autoscaler (HPA) in Kubernetes that scales the number of pods of a deployment based on CPU usage.
📋 What You'll Learn
Create a deployment named webapp with 2 replicas
Add resource requests for CPU in the deployment
Create a Horizontal Pod Autoscaler targeting the webapp deployment
Set the CPU utilization target to 50%
Verify the HPA configuration
💡 Why This Matters
🌍 Real World
Horizontal Pod Autoscaler helps keep applications responsive by automatically adjusting the number of pods based on CPU load, just like how a car adjusts speed based on traffic.
💼 Career
Understanding HPA is essential for Kubernetes administrators and DevOps engineers to ensure applications scale efficiently and cost-effectively.
Progress0 / 4 steps
1
Create a deployment named webapp with 2 replicas
Write a Kubernetes deployment YAML named webapp-deployment.yaml that creates a deployment called webapp with 2 replicas running the image nginx. Include container port 80.
Kubernetes
Need a hint?

Use kind: Deployment, set replicas: 2, and specify image: nginx with port 80.

2
Add CPU resource requests to the deployment
In the webapp-deployment.yaml, add CPU resource requests of 100m under resources.requests.cpu for the container named nginx.
Kubernetes
Need a hint?

Under the container, add resources: then requests: with cpu: 100m.

3
Create a Horizontal Pod Autoscaler targeting the webapp deployment
Write a YAML file named webapp-hpa.yaml that creates a Horizontal Pod Autoscaler targeting the deployment webapp. Set the minimum replicas to 2, maximum replicas to 5, and target average CPU utilization to 50%.
Kubernetes
Need a hint?

Use kind: HorizontalPodAutoscaler, set scaleTargetRef to deployment webapp, and set CPU target to 50%.

4
Display the Horizontal Pod Autoscaler status
Write the exact command to display the status of the Horizontal Pod Autoscaler named webapp-hpa in the default namespace.
Kubernetes
Need a hint?

Use kubectl get hpa webapp-hpa to see the autoscaler status.