Skip to content

Commit

Permalink
feat: add horizontal pod autoscaler (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Feb 15, 2024
1 parent 902a5de commit 63593f7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
@@ -1,6 +1,6 @@
ARG PYTHON_VERSION=3.10-slim-bullseye
ARG PYTHON_VERSION=3.10-slim-bookworm

FROM node:18-bullseye-slim as client-builder
FROM node:18-bookworm-slim as client-builder

ARG APP_HOME=/app
WORKDIR ${APP_HOME}
Expand Down
7 changes: 6 additions & 1 deletion deploy/charts/mycarehub-backend/templates/deployment.yaml
Expand Up @@ -37,7 +37,12 @@ spec:
containerPort: {{ .Values.service.port }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
limits:
cpu: {{ .Values.app.resources.limits.cpu }}
memory: {{ .Values.app.resources.limits.memory }}
requests:
cpu: {{ .Values.app.resources.requests.cpu }}
memory: {{ .Values.app.resources.requests.memory }}

env:
- name: GOOGLE_CLOUD_PROJECT
Expand Down
32 changes: 32 additions & 0 deletions deploy/charts/mycarehub-backend/templates/hpa.yaml
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "mycarehub-backend.fullname" . }}
labels:
{{- include "mycarehub-backend.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "mycarehub-backend.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
34 changes: 21 additions & 13 deletions deploy/charts/mycarehub-backend/values.yaml
Expand Up @@ -5,15 +5,23 @@
replicaCount: 1

app:
replicaCount: 1
container:
imagePullPolicy: "Always"
port: 8080
env:
googleApplicationCredentialsSecret:
name: "mycarehub-backend-service-account"
filePath: "/secrets/gcp/key.json"
mountPath: "/secrets/gcp"
resources:
limits:
cpu: 700m
memory: 1024Mi
requests:
cpu: 500m
memory: 768Mi

replicaCount: 1
container:
imagePullPolicy: "Always"
port: 8080
env:
googleApplicationCredentialsSecret:
name: "mycarehub-backend-service-account"
filePath: "/secrets/gcp/key.json"
mountPath: "/secrets/gcp"

service:
type: NodePort
Expand All @@ -38,8 +46,8 @@ ingress:
# - chart-example.local

autoscaling:
enabled: false
enabled: true
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80
maxReplicas: 20
targetCPUUtilizationPercentage: 90
targetMemoryUtilizationPercentage: 90

0 comments on commit 63593f7

Please sign in to comment.