From 54dd16bf5ef21394d73247c679ec148e72b465a3 Mon Sep 17 00:00:00 2001 From: "teodor.spiridonescu" Date: Mon, 3 Jun 2024 14:51:21 +0300 Subject: [PATCH 1/4] Transition from deployments to statefulsets --- charts/app-mendix/Chart.yaml | 2 +- charts/app-mendix/templates/autoscale.yaml | 17 -- .../templates/deployment-slave.yaml | 145 ------------------ ...eployment-leader.yaml => statefulset.yaml} | 32 +--- charts/app-mendix/values.yaml | 21 +-- 5 files changed, 10 insertions(+), 207 deletions(-) delete mode 100644 charts/app-mendix/templates/autoscale.yaml delete mode 100644 charts/app-mendix/templates/deployment-slave.yaml rename charts/app-mendix/templates/{deployment-leader.yaml => statefulset.yaml} (87%) diff --git a/charts/app-mendix/Chart.yaml b/charts/app-mendix/Chart.yaml index 63104e8..1afd20e 100644 --- a/charts/app-mendix/Chart.yaml +++ b/charts/app-mendix/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: app-mendix -version: 2.3.0 +version: 3.0.0 description: Mendix Application Chart. icon: https://cinaq.github.io/helm-charts/icons/mendix-logo.png maintainers: diff --git a/charts/app-mendix/templates/autoscale.yaml b/charts/app-mendix/templates/autoscale.yaml deleted file mode 100644 index 17e6101..0000000 --- a/charts/app-mendix/templates/autoscale.yaml +++ /dev/null @@ -1,17 +0,0 @@ -{{- if .Values.autoscale.enabled -}} -{{- $serviceName := include "app-mendix.fullname" . -}} -apiVersion: autoscaling/v1 -kind: HorizontalPodAutoscaler -metadata: - name: {{ template "app-mendix.fullname" . }} - labels: - {{- include "app-mendix.labels" . | nindent 4 }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ template "app-mendix.fullname" . }}-slave - minReplicas: {{ .Values.autoscale.minSlaveReplicas }} - maxReplicas: {{ .Values.autoscale.maxSlaveReplicas }} - targetCPUUtilizationPercentage: {{ .Values.autoscale.targetCPUUtilizationPercentage }} -{{- end }} diff --git a/charts/app-mendix/templates/deployment-slave.yaml b/charts/app-mendix/templates/deployment-slave.yaml deleted file mode 100644 index 7162949..0000000 --- a/charts/app-mendix/templates/deployment-slave.yaml +++ /dev/null @@ -1,145 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ template "app-mendix.fullname" . }}-slave - labels: - {{- include "app-mendix.labels" . | nindent 4 }} -spec: -{{- if .Values.autoscale.enabled }} - replicas: {{ .Values.autoscale.minSlaveReplicas }} -{{- else if (eq (int .Values.replicaCount) 0)}} - replicas: 0 -{{- else }} - replicas: {{ (sub (int .Values.replicaCount) 1) }} -{{- end }} - selector: - matchLabels: - {{- include "app-mendix.selectorLabels" . | nindent 6 }} - {{- if .Values.strategy.enabled }} - strategy: - type: {{ .Values.strategy.type }} - {{- if eq "RollingUpdate" .Values.strategy.type }} - rollingUpdate: - maxSurge: {{ .Values.strategy.rollingUpdate.maxSurge }} - maxUnavailable: {{ .Values.strategy.rollingUpdate.maxUnavailable }} - {{- end }} - {{- end }} - template: - metadata: - labels: - {{- include "app-mendix.labels" . | nindent 8 }} - {{- with .Values.annotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - spec: - containers: - - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - ports: - - containerPort: {{ .Values.service.internalPort }} - name: app - {{- if .Values.metrics.enabled }} - - containerPort: {{ add (int .Values.service.internalPort) 2 }} - name: metrics - - containerPort: 9273 - name: metrics-mendix - {{- end }} - env: - - name: NON_MENDIX_PUBLIC_CLOUD - value: "true" - - name: CF_INSTANCE_INDEX - value: "1" - - name: MXRUNTIME_Metrics_Registries - value: '[{"type": "prometheus", "settings": {"step": "5m"}}]' - - name: RUNTIME_LOGIN_METRICS_ENABLED - value: {{ .Values.metrics.runtimeLoginMetricsEnabled | quote }} - - name: TRENDS_FORWARDER_URL - value: {{ .Values.metrics.trendsForwarderUrl | quote }} - {{- if .Values.licenseId }} - - name: LICENSE_ID - value: {{ .Values.licenseId }} - {{- end }} - {{- if .Values.licenseKey }} - - name: LICENSE_KEY - value: {{ .Values.licenseKey }} - {{- end }} - {{- range .Values.env }} - - name: {{ .name | quote}} - value: {{ .value | quote}} - {{- end }} - {{- if .Values.secretName }} - envFrom: - - secretRef: - name: {{ .Values.secretName }} - {{- end }} - {{- if .Values.readinessProbe.enabled }} - readinessProbe: - {{- if eq "httpGet" .Values.readinessProbe.type }} - httpGet: - path: {{ .Values.readinessProbe.httpGet.path }} - port: {{ .Values.readinessProbe.httpGet.port }} - {{- else if eq "exec" .Values.readinessProbe.type }} - exec: - command: - {{- range .Values.readinessProbe.exec.command }} - - {{ . }} - {{- end }} - {{- else if eq "tcpSocket" .Values.readinessProbe.type }} - tcpSocket: - port: {{ .Values.readinessProbe.tcpSocket.port }} - {{- end }} - initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }} - periodSeconds: {{ .Values.readinessProbe.periodSeconds }} - failureThreshold: {{ .Values.readinessProbe.failureThreshold }} - timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} - successThreshold: {{ .Values.readinessProbe.successThreshold }} - {{- end }} - {{- if .Values.livenessProbe.enabled }} - livenessProbe: - {{- if eq "httpGet" .Values.livenessProbe.type }} - httpGet: - path: {{ .Values.livenessProbe.httpGet.path }} - port: {{ .Values.livenessProbe.httpGet.port }} - {{- else if eq "exec" .Values.livenessProbe.type }} - exec: - command: - {{- range .Values.livenessProbe.exec.command }} - - {{ . }} - {{- end }} - {{- else if eq "tcpSocket" .Values.livenessProbe.type }} - tcpSocket: - port: {{ .Values.livenessProbe.tcpSocket.port }} - {{- end }} - initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} - periodSeconds: {{ .Values.livenessProbe.periodSeconds }} - failureThreshold: {{ .Values.livenessProbe.failureThreshold }} - timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} - successThreshold: {{ .Values.livenessProbe.successThreshold }} - {{- end }} - {{- if .Values.lifecycle.prestop.enabled }} - lifecycle: - preStop: - exec: - command: [{{ .Values.lifecycle.prestop.command }}] - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/charts/app-mendix/templates/deployment-leader.yaml b/charts/app-mendix/templates/statefulset.yaml similarity index 87% rename from charts/app-mendix/templates/deployment-leader.yaml rename to charts/app-mendix/templates/statefulset.yaml index 50f676c..c416e8c 100644 --- a/charts/app-mendix/templates/deployment-leader.yaml +++ b/charts/app-mendix/templates/statefulset.yaml @@ -1,21 +1,19 @@ --- apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: - name: {{ template "app-mendix.fullname" . }}-leader + name: {{ template "app-mendix.fullname" . }}-statefulset labels: {{- include "app-mendix.labels" . | nindent 4 }} spec: -{{- if (ge (int .Values.replicaCount) 1) }} - replicas: 1 -{{- else }} - replicas: 0 -{{- end }} + replicas: {{ default 2 .Values.replicaCount }} selector: matchLabels: {{- include "app-mendix.selectorLabels" . | nindent 6 }} - strategy: - type: Recreate + updateStrategy: + type: RollingUpdate + serviceName: {{ template "app-mendix.fullname" . }}-statefulset + minReadySeconds: 10 template: metadata: labels: @@ -118,19 +116,3 @@ spec: {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/charts/app-mendix/values.yaml b/charts/app-mendix/values.yaml index fa8ab35..f028c7d 100644 --- a/charts/app-mendix/values.yaml +++ b/charts/app-mendix/values.yaml @@ -1,8 +1,5 @@ -# initial replica, if: -# less than 1 => no leader or slaves -# equal 1 => 1 leader no slaves -# larger than 1 => 1 leader, rest slaves -replicaCount: 1 +# replicaCount: 2 | 1 leader, 1 slave +replicaCount: 2 image: repository: "cinaq/hackme" @@ -90,20 +87,6 @@ networkPolicy: enabled: true ingress: allowed: true -autoscale: - # only affects slave deployment - # If enabled, slave replicas starts with minSlaveReplicas - enabled: false - minSlaveReplicas: 1 - maxSlaveReplicas: 3 - targetCPUUtilizationPercentage: 70 - -strategy: - enabled: false - type: RollingUpdate - rollingUpdate: - maxSurge: 1 - maxUnavailable: 0 readinessProbe: enabled: true From 319675ee0789e5fa95856cba923ff42445a0407f Mon Sep 17 00:00:00 2001 From: "teodor.spiridonescu" Date: Mon, 3 Jun 2024 17:31:18 +0300 Subject: [PATCH 2/4] rm statefulsename and add imagepullsecrets --- charts/app-mendix/templates/statefulset.yaml | 24 ++++++++++++++++---- charts/app-mendix/values.yaml | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/charts/app-mendix/templates/statefulset.yaml b/charts/app-mendix/templates/statefulset.yaml index c416e8c..ff9fd56 100644 --- a/charts/app-mendix/templates/statefulset.yaml +++ b/charts/app-mendix/templates/statefulset.yaml @@ -2,17 +2,17 @@ apiVersion: apps/v1 kind: StatefulSet metadata: - name: {{ template "app-mendix.fullname" . }}-statefulset + name: {{ template "app-mendix.fullname" . }} labels: {{- include "app-mendix.labels" . | nindent 4 }} spec: - replicas: {{ default 2 .Values.replicaCount }} + replicas: {{ default 1 .Values.replicaCount }} selector: matchLabels: {{- include "app-mendix.selectorLabels" . | nindent 6 }} updateStrategy: type: RollingUpdate - serviceName: {{ template "app-mendix.fullname" . }}-statefulset + serviceName: {{ template "app-mendix.fullname" . }} minReadySeconds: 10 template: metadata: @@ -39,8 +39,6 @@ spec: env: - name: NON_MENDIX_PUBLIC_CLOUD value: "true" - - name: CF_INSTANCE_INDEX - value: "0" - name: MXRUNTIME_Metrics_Registries value: '[{"type": "prometheus", "settings": {"step": "5m"}}]' - name: RUNTIME_LOGIN_METRICS_ENABLED @@ -116,3 +114,19 @@ spec: {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/app-mendix/values.yaml b/charts/app-mendix/values.yaml index f028c7d..6254d2f 100644 --- a/charts/app-mendix/values.yaml +++ b/charts/app-mendix/values.yaml @@ -1,5 +1,5 @@ # replicaCount: 2 | 1 leader, 1 slave -replicaCount: 2 +replicaCount: 1 image: repository: "cinaq/hackme" From 1ec59f051a6bc0f33c5a1d0420c50b3641e7756e Mon Sep 17 00:00:00 2001 From: "teodor.spiridonescu" Date: Mon, 3 Jun 2024 17:57:03 +0300 Subject: [PATCH 3/4] readd autoscaler --- charts/app-mendix/templates/autoscale.yaml | 17 +++++++++++++++++ charts/app-mendix/values.yaml | 7 +++++++ 2 files changed, 24 insertions(+) create mode 100644 charts/app-mendix/templates/autoscale.yaml diff --git a/charts/app-mendix/templates/autoscale.yaml b/charts/app-mendix/templates/autoscale.yaml new file mode 100644 index 0000000..7ec6c04 --- /dev/null +++ b/charts/app-mendix/templates/autoscale.yaml @@ -0,0 +1,17 @@ +{{- if .Values.autoscale.enabled -}} +{{- $serviceName := include "app-mendix.fullname" . -}} +apiVersion: autoscaling/v1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "app-mendix.fullname" . }} + labels: + {{- include "app-mendix.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: StatefulSet + name: {{ template "app-mendix.fullname" . }} + minReplicas: {{ .Values.autoscale.minSlaveReplicas }} + maxReplicas: {{ .Values.autoscale.maxSlaveReplicas }} + targetCPUUtilizationPercentage: {{ .Values.autoscale.targetCPUUtilizationPercentage }} +{{- end }} diff --git a/charts/app-mendix/values.yaml b/charts/app-mendix/values.yaml index 6254d2f..4df5525 100644 --- a/charts/app-mendix/values.yaml +++ b/charts/app-mendix/values.yaml @@ -87,6 +87,13 @@ networkPolicy: enabled: true ingress: allowed: true +autoscale: + # only affects slave deployment + # If enabled, slave replicas starts with minSlaveReplicas + enabled: true + minSlaveReplicas: 1 + maxSlaveReplicas: 3 + targetCPUUtilizationPercentage: 70 readinessProbe: enabled: true From e5dabebe5a7c83dd90f224c37aaaa7d5d196ea6f Mon Sep 17 00:00:00 2001 From: "teodor.spiridonescu" Date: Mon, 3 Jun 2024 17:58:57 +0300 Subject: [PATCH 4/4] autoscale enabled false --- charts/app-mendix/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/app-mendix/values.yaml b/charts/app-mendix/values.yaml index 4df5525..f919c9e 100644 --- a/charts/app-mendix/values.yaml +++ b/charts/app-mendix/values.yaml @@ -90,7 +90,7 @@ networkPolicy: autoscale: # only affects slave deployment # If enabled, slave replicas starts with minSlaveReplicas - enabled: true + enabled: false minSlaveReplicas: 1 maxSlaveReplicas: 3 targetCPUUtilizationPercentage: 70