

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
Not enough gems
Cost: 6 gems
1: Top
incomplete
2: Vertical and Horizontal Scaling
incomplete
3: Resource Limits
incomplete
4: Limits - RAM
incomplete
5: Breaking the Limits
incomplete
6: Fix the Limits
incomplete
7: Horizontal Pod Autoscaling (HPA)
incomplete
8: HPA - Web
incomplete
9: HPA Fix
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
A Horizontal Pod Autoscaler can automatically scale the number of Pods in a Deployment based on observed CPU utilization or other custom metrics. It's very common in a Kubernetes environment to have a low number of pods in a deployment, and then scale up the number of pods automatically as CPU usage increases.
First, delete the replicas: 1 line from the synergychat-testcpu deployment. This will allow our new autoscaler to have full control over the number of pods.
Create a new file called testcpu-hpa.yaml. Add the following YAML to it:
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: testcpu-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: x
minReplicas: x
maxReplicas: x
targetCPUUtilizationPercentage: x
Set the following values:
name: The name of the synergychat-testcpu deploymentminReplicas: 1maxReplicas: 4targetCPUUtilizationPercentage: 50This hpa will monitor the CPU usage of the pods in the synergychat-testcpu deployment. Its goal is to scale up or down the number of pods in the deployment so that the average CPU usage of all pods is around 50%. As CPU usage increases, it will add more pods. As CPU usage decreases, it will remove pods. You can find the algorithm it uses here if you're interested.
Apply the hpa, then run the following commands every few seconds to watch as the number of pods scales up:
kubectl get pods
kubectl top pods
An hpa is just another resource, so you can also use kubectl get hpa to see the current state of the autoscaler.
If kubectl get hpa shows <unknown> for CPU after a reboot, make sure your local cluster and metrics server are running again before debugging the YAML.