Skip to content

Commit 8d1beb0

Browse files
committed
feat(k8s): add a horizontal pod autoscaler
this scales up when the average CPU utilization is at 95% of the requested CPU. We should remove the replicas key from the deployment, otherwise any time we deploy it will overwrite the HPA (source: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#migrating-deployments-and-statefulsets-to-horizontal-autoscaling) Behaviour: - every 15 seconds - The HPA controller checks the value of the metric used every 15 seconds per pod. - every 3 minutes - The HPA scales up pods if the metric threshold has been continually exceeded for 3 mins. - every 5 minutes - The HPA scales down pods if the metric threshold has not been exceeded for 5 mins. Further info: - https://user-guide.cloud-platform.service.justice.gov.uk/documentation/concepts/deploying.html#horizontal-pod-autoscaling-hpa - https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale
1 parent dcce071 commit 8d1beb0

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.github/workflows/reusable-push-and-deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ jobs:
118118

119119
run: |
120120
cat deployments/templates/deployment.yml | envsubst > deployments/deployment.yml
121+
cat deployments/templates/hpa.yml | envsubst > deployments/hpa.yml
121122
cat deployments/templates/ingress.yml | envsubst > deployments/ingress.yml
122123
cat deployments/templates/service.yml | envsubst > deployments/service.yml
123124
cat deployments/templates/secrets.yml | envsubst > deployments/secrets.yml

deployments/templates/deployment.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ metadata:
55
labels:
66
app: find-moj-data
77
spec:
8-
replicas: 2
98
strategy:
109
type: RollingUpdate
1110
rollingUpdate:

deployments/templates/hpa.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: autoscaling/v2
2+
kind: HorizontalPodAutoscaler
3+
metadata:
4+
name: find-moj-data
5+
namespace: ${NAMESPACE}
6+
spec:
7+
scaleTargetRef:
8+
apiVersion: apps/v1
9+
kind: Deployment
10+
name: find-moj-data
11+
minReplicas: 1
12+
maxReplicas: 5
13+
metrics:
14+
- type: Resource
15+
resource:
16+
name: cpu
17+
target:
18+
type: Utilization
19+
averageUtilization: 95

0 commit comments

Comments
 (0)