Skip to content

Commit

Permalink
feat: ✨ HPA: Horizontal Pod Autoscaler
Browse files Browse the repository at this point in the history
Horizontal Pod Autoscaling (HPA) is a Kubernetes feature that automatically adjusts the number of running pods in a deployment or replica set based on real-time metrics such as CPU utilization or custom metrics. This ensures that your application can scale out to handle increased load and scale in when demand decreases, optimizing resource usage and performance. (Command to perform CPU tests: kubectl run -it fortio --rm --image=fortio/fortio -- load -qps 800 -t 120s -c 70 "http://go-http-app-service/healthz")
  • Loading branch information
kevencript committed Mar 18, 2023
1 parent 2dccdf5 commit 86887aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ create-kind-cluster:

deploy:
kubectl apply -f k8s
sleep 3
$(MAKE) port-forward

delete:
Expand All @@ -18,14 +17,14 @@ delete:
redeploy:
$(MAKE) delete
$(MAKE) deploy
sleep 3
$(MAKE) port-forward

port-forward:
sleep 4
kubectl port-forward svc/go-http-app-service 8000:80

install-metrics-components:
kubectl apply -f k8s/metrics-server.yaml
kubectl wait --namespace kube-system \
--for=condition=available deployment/metrics-server \
--timeout=200s
--timeout=60s
2 changes: 1 addition & 1 deletion k8s/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: go-http-app
image: wesleywillians/hello-go:v5.5 # Probe on port /healthz (+ readiness check: if app is up < 10s it will fail. This way, readiness will only be "ready" when the pod is healthy)
image: wesleywillians/hello-go:v9.6
resources:
requests:
cpu: "0.03"
Expand Down
18 changes: 18 additions & 0 deletions k8s/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: go-http-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: go-http-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 35

0 comments on commit 86887aa

Please sign in to comment.