Skip to content

Commit

Permalink
feat(helm-charts): helm-chart 支持自动扩缩容 #7051
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhw8 authored and iSecloud committed Sep 23, 2024
1 parent 4b044ca commit b8bd055
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 49 deletions.
6 changes: 3 additions & 3 deletions helm-charts/bk-dbm/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
version: 7.9.8
- name: dbm
repository: file://charts/dbm
version: 0.1.41
version: 0.1.42
- name: dbconfig
repository: file://charts/dbconfig
version: 0.1.13
Expand Down Expand Up @@ -65,5 +65,5 @@ dependencies:
- name: db-dbha
repository: file://charts/db-dbha
version: 0.1.0
digest: sha256:505dce199e12c74e5852a426b8997b2c527c43c5cba321aebc58ef1040b43ff6
generated: "2024-08-28T19:45:11.596886126+08:00"
digest: sha256:a0cc97116fc4c063d525b75adb4dab479456c1509f975700b887cc19517d1348
generated: "2024-09-23T12:17:47.539237+08:00"
2 changes: 1 addition & 1 deletion helm-charts/bk-dbm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
- condition: dbm.enabled
name: dbm
repository: file://charts/dbm
version: 0.1.41
version: 0.1.42
- condition: dbconfig.enabled
name: dbconfig
repository: file://charts/dbconfig
Expand Down
2 changes: 1 addition & 1 deletion helm-charts/bk-dbm/charts/dbm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ appVersion: 1.5.0-alpha.535
description: A Helm chart for dbm
name: dbm
type: application
version: 0.1.41
version: 0.1.42
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.enabled -}}
{{- if .Values.saas.backendApi.enabled | default .Values.enabled -}}
{{- $fullName := ( include "dbm.backend-api.fullname" .) -}}
apiVersion: apps/v1
kind: Deployment
Expand All @@ -7,8 +7,8 @@ metadata:
labels:
{{- include "dbm.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.saas.api.replicaCount }}
{{- if not .Values.saas.backendApi.autoscaling.enabled }}
replicas: {{ .Values.saas.backendApi.replicaCount }}
{{- end }}
selector:
matchLabels:
Expand Down Expand Up @@ -41,7 +41,7 @@ spec:
- /bin/bash
- -c
args:
- export SERVICE_ONLY=true && gunicorn wsgi -w {{ .Values.saas.api.gunicornWorker }} -b :8000 --access-logfile - --error-logfile - --access-logformat '[%(h)s] %({request_id}i)s %(u)s %(t)s "%(r)s" %(s)s %(D)s %(b)s "%(f)s" "%(a)s"'
- export SERVICE_ONLY=true && gunicorn wsgi -w {{ .Values.saas.backendApi.gunicornWorker }} -b :8000 --access-logfile - --error-logfile - --access-logformat '[%(h)s] %({request_id}i)s %(u)s %(t)s "%(r)s" %(s)s %(D)s %(b)s "%(f)s" "%(a)s"'
ports:
- name: http
containerPort: 8000
Expand All @@ -66,7 +66,7 @@ spec:
failureThreshold: {{ .Values.readinessProbe.failureThreshold | default 3}}
{{- include "dbm.container_env" . | nindent 10 }}
resources:
{{- toYaml .Values.saas.api.resources | nindent 12 }}
{{- toYaml .Values.saas.backendApi.resources | nindent 12 }}
{{- include "dbm.initContainersWaitForMigrate" . | nindent 6 }}
{{- with .Values.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.enabled -}}
{{- if .Values.saas.backendApi.enabled | default .Values.enabled -}}
{{- $fullName := ( include "dbm.backend-api.fullname" .) -}}
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ metadata:
labels:
{{- include "dbm.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.saas.celeryBeat.replicaCount | default 1}}
{{- end }}
selector:
matchLabels:
{{- include "dbm.selectorLabels" . | nindent 6 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
labels:
{{- include "dbm.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
{{- if not .Values.saas.celeryWorker.autoscaling.enabled }}
replicas: {{ .Values.saas.celeryWorker.replicaCount }}
{{- end }}
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
labels:
{{- include "dbm.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
{{- if not .Values.saas.pipelineWorker.autoscaling.enabled }}
replicas: {{ .Values.saas.pipelineWorker.replicaCount }}
{{- end }}
selector:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.enabled -}}
{{- if .Values.saas.api.enabled | default .Values.enabled -}}
{{- $fullName := ( include "dbm.saas-api.fullname" .) -}}
apiVersion: apps/v1
kind: Deployment
Expand All @@ -7,7 +7,7 @@ metadata:
labels:
{{- include "dbm.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
{{- if not .Values.saas.api.autoscaling.enabled }}
replicas: {{ .Values.saas.api.replicaCount }}
{{- end }}
selector:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.enabled -}}
{{- if .Values.saas.api.enabled | default .Values.enabled -}}
{{- $fullName := ( include "dbm.saas-api.fullname" .) -}}
apiVersion: v1
kind: Service
Expand Down
28 changes: 0 additions & 28 deletions helm-charts/bk-dbm/charts/dbm/templates/hpa.yaml

This file was deleted.

28 changes: 28 additions & 0 deletions helm-charts/bk-dbm/charts/dbm/templates/hpas/backend-api-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.saas.backendApi.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "dbm.backend-api.fullname" . }}
labels:
{{- include "bk-dbm.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "dbm.backend-api.fullname" . }}
minReplicas: {{ .Values.saas.backendApi.autoscaling.minReplicas }}
maxReplicas: {{ .Values.saas.backendApi.autoscaling.maxReplicas }}
metrics:
{{- if .Values.saas.backendApi.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.saas.backendApi.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.saas.backendApi.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.saas.backendApi.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.saas.celeryWorker.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "dbm.celery-worker.fullname" . }}
labels:
{{- include "bk-dbm.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "dbm.celery-worker.fullname" . }}
minReplicas: {{ .Values.saas.celeryWorker.autoscaling.minReplicas }}
maxReplicas: {{ .Values.saas.celeryWorker.autoscaling.maxReplicas }}
metrics:
{{- if .Values.saas.celeryWorker.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.saas.celeryWorker.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.saas.celeryWorker.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.saas.celeryWorker.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.saas.pipelineWorker.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "dbm.pipeline-worker.fullname" . }}
labels:
{{- include "bk-dbm.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "dbm.pipeline-worker.fullname" . }}
minReplicas: {{ .Values.saas.pipelineWorker.autoscaling.minReplicas }}
maxReplicas: {{ .Values.saas.pipelineWorker.autoscaling.maxReplicas }}
metrics:
{{- if .Values.saas.pipelineWorker.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.saas.pipelineWorker.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.saas.pipelineWorker.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.saas.pipelineWorker.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
28 changes: 28 additions & 0 deletions helm-charts/bk-dbm/charts/dbm/templates/hpas/saas-api-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.saas.api.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "bk-dbm.fullname" . }}
labels:
{{- include "bk-dbm.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "bk-dbm.fullname" . }}
minReplicas: {{ .Values.saas.api.autoscaling.minReplicas }}
maxReplicas: {{ .Values.saas.api.autoscaling.maxReplicas }}
metrics:
{{- if .Values.saas.api.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.saas.api.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.saas.api.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.saas.api.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
31 changes: 30 additions & 1 deletion helm-charts/bk-dbm/charts/dbm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,44 @@ saas:
resources: {}
replicaCount: 1
gunicornWorker: 8
celeryBeat:
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
backendApi:
enabled: true
resources: {}
replicaCount: 1
gunicornWorker: 8
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
celeryWorker:
enabled: true
resources: {}
replicaCount: 1
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
pipelineWorker:
enabled: true
resources: {}
replicaCount: 1
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
celeryBeat:
enabled: true
resources: {}
replicaCount: 1
18 changes: 16 additions & 2 deletions helm-charts/bk-dbm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,22 @@ dbm:
pathType: ImplementationSpecific
tls: []

autoscaling:
enabled: false
saas:
api:
enabled: true
replicaCount: 1
backendApi:
enabled: true
replicaCount: 1
celeryBeat:
enabled: true
replicaCount: 1
celeryWorker:
enabled: true
replicaCount: 1
pipelineWorker:
enabled: true
replicaCount: 1

migration:
images:
Expand Down

0 comments on commit b8bd055

Please sign in to comment.