From a5d69d24af02e052b543545ded49cd6121cd4a7f Mon Sep 17 00:00:00 2001 From: Andy Verberne Date: Wed, 14 Apr 2021 19:32:15 +0200 Subject: [PATCH] Fixes #3. Move some items back from secret to configMap. Make worker pod scalable. --- .../templates/configmap.yaml | 4 --- .../templates/deployment.yaml | 4 ++- charts/open-notificaties/templates/hpa.yaml | 29 +++++++++++++++++++ .../open-notificaties/templates/secret.yaml | 4 +++ charts/open-notificaties/values.yaml | 11 ++++++- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/charts/open-notificaties/templates/configmap.yaml b/charts/open-notificaties/templates/configmap.yaml index 488570f..5cb3d35 100644 --- a/charts/open-notificaties/templates/configmap.yaml +++ b/charts/open-notificaties/templates/configmap.yaml @@ -8,9 +8,6 @@ data: ALLOWED_HOSTS: "{{ include "open-notificaties.fullname" . }},{{ .Values.settings.allowedHosts | toString }}" CACHE_AXES: {{ .Values.settings.cache.axes | toString | quote }} CACHE_DEFAULT: {{ .Values.settings.cache.default | toString | quote }} - {{ $rabbitmq_connection := printf "amqp://%s:%s@%s:5672" .Values.rabbitmq.auth.username .Values.rabbitmq.auth.password .Values.settings.messageBroker.host -}} - CELERY_BROKER_URL: {{ print $rabbitmq_connection "//" | quote }} - CELERY_RESULT_BACKEND: {{ print $rabbitmq_connection "//" | quote }} DB_NAME: {{ .Values.settings.database.name | toString | quote }} DB_HOST: {{ .Values.settings.database.host | toString | quote }} DB_PORT: {{ .Values.settings.database.port | toString | quote }} @@ -24,5 +21,4 @@ data: EMAIL_USE_TLS: "True" {{- end }} IS_HTTPS: {{ if .Values.settings.isHttps }}"True"{{ else }}"False"{{ end }} - PUBLISHER_BROKER_URL: {{ print $rabbitmq_connection "/%2F" | quote }} RABBITMQ_HOST: {{ .Values.settings.messageBroker.host }} \ No newline at end of file diff --git a/charts/open-notificaties/templates/deployment.yaml b/charts/open-notificaties/templates/deployment.yaml index 12dab59..a1d869d 100644 --- a/charts/open-notificaties/templates/deployment.yaml +++ b/charts/open-notificaties/templates/deployment.yaml @@ -93,7 +93,9 @@ metadata: labels: {{- include "open-notificaties.workerLabels" . | nindent 4 }} spec: - replicas: 1 + {{- if not .Values.worker.autoscaling.enabled }} + replicas: {{ .Values.worker.replicaCount }} + {{- end }} selector: matchLabels: {{- include "open-notificaties.workerSelectorLabels" . | nindent 6 }} diff --git a/charts/open-notificaties/templates/hpa.yaml b/charts/open-notificaties/templates/hpa.yaml index 6d56af1..044a370 100644 --- a/charts/open-notificaties/templates/hpa.yaml +++ b/charts/open-notificaties/templates/hpa.yaml @@ -26,3 +26,32 @@ spec: targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} {{- end }} {{- end }} +--- +{{- if .Values.worker.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "open-notificaties.workerFullname" . }} + labels: + {{- include "open-notificaties.workerLabels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "open-notificaties.workerFullname" . }} + minReplicas: {{ .Values.worker.autoscaling.minReplicas }} + maxReplicas: {{ .Values.worker.autoscaling.maxReplicas }} + metrics: + {{- if .Values.worker.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.worker.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/open-notificaties/templates/secret.yaml b/charts/open-notificaties/templates/secret.yaml index 3cf7698..f16dec0 100644 --- a/charts/open-notificaties/templates/secret.yaml +++ b/charts/open-notificaties/templates/secret.yaml @@ -6,10 +6,14 @@ metadata: {{- include "open-notificaties.labels" . | nindent 4 }} type: Opaque data: + {{ $rabbitmq_url := printf "amqp://%s:%s@%s:5672" .Values.rabbitmq.auth.username .Values.rabbitmq.auth.password .Values.settings.messageBroker.host -}} + CELERY_BROKER_URL: {{ print $rabbitmq_url "//" | b64enc | quote }} + CELERY_RESULT_BACKEND: {{ print $rabbitmq_url "//" | b64enc | quote }} DB_PASSWORD: {{ .Values.settings.database.password | toString | b64enc | quote }} {{- if .Values.settings.email.password }} EMAIL_PASSWORD: {{ .Values.settings.email.password | toString | b64enc | quote }} {{- end }} + PUBLISHER_BROKER_URL: {{ print $rabbitmq_url "/%2F" | b64enc | quote }} SECRET_KEY: {{ .Values.settings.secretKey | toString | b64enc | quote }} {{- if .Values.settings.sentry.dsn }} SENTRY_DSN: {{ .Values.settings.sentry.dsn | toString | b64enc | quote }} diff --git a/charts/open-notificaties/values.yaml b/charts/open-notificaties/values.yaml index 1a7b0e1..4c7b32a 100644 --- a/charts/open-notificaties/values.yaml +++ b/charts/open-notificaties/values.yaml @@ -63,7 +63,6 @@ ingress: # - chart-example.local resources: {} -workerResources: {} # We usually recommend not to specify default resources and to leave this as a conscious # choice for the user. This also increases chances charts run on environments with little # resources, such as Minikube. If you do want to specify resources, uncomment the following @@ -93,6 +92,16 @@ persistence: size: 1Gi existingClaim: null +worker: + replicaCount: 1 + resources: {} + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + settings: allowedHosts: open-notificaties.gemeente.nl