diff --git a/templates/_resources.tpl b/templates/_resources.tpl new file mode 100644 index 00000000..edf473a0 --- /dev/null +++ b/templates/_resources.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} + +{{/* +Return a resource request/limit object based on a given preset. +These presets are for basic testing and not meant to be used in production +{{ include "release.resources.preset" (dict "type" "nano") -}} +*/}} +{{- define "release.resources.preset" -}} +{{/* The limits are as per the documentation. The requests are limits reduced by approximately 150% and rounded.*/}} +{{- $presets := dict + "nano" (dict + "requests" (dict "cpu" "500m" "memory" "1Gi") + "limits" (dict "cpu" "1.0" "memory" "2Gi") + ) + "micro" (dict + "requests" (dict "cpu" "1.0" "memory" "2Gi") + "limits" (dict "cpu" "2.0" "memory" "4Gi") + ) + "small" (dict + "requests" (dict "cpu" "2.0" "memory" "5Gi") + "limits" (dict "cpu" "4.0" "memory" "8Gi") + ) + "medium" (dict + "requests" (dict "cpu" "5.0" "memory" "10Gi") + "limits" (dict "cpu" "8.0" "memory" "16Gi") + ) + "large" (dict + "requests" (dict "cpu" "10.0" "memory" "21Gi") + "limits" (dict "cpu" "16.0" "memory" "32Gi") + ) + "xlarge" (dict + "requests" (dict "cpu" "21.0" "memory" "42Gi") + "limits" (dict "cpu" "32.0" "memory" "64Gi") + ) + "2xlarge" (dict + "requests" (dict "cpu" "42.0" "memory" "85Gi") + "limits" (dict "cpu" "64.0" "memory" "128Gi") + ) + }} +{{- if hasKey $presets .type -}} +{{- index $presets .type | toYaml -}} +{{- else -}} +{{- printf "ERROR: Preset key '%s' invalid. Allowed values are %s" .type (join "," (keys $presets)) | fail -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/templates/release-statefulset.yaml b/templates/release-statefulset.yaml index 58ab1040..2a2a9477 100644 --- a/templates/release-statefulset.yaml +++ b/templates/release-statefulset.yaml @@ -102,6 +102,9 @@ spec: value: {{ include "postgresql.subchart" . }} - name: POSTGRESQL_PORT value: {{ (include "release.postgresql.service.port" .) | quote }} + {{- if .Values.defaultInitContainers.resources }} + resources: {{- toYaml .Values.defaultInitContainers.resources | nindent 12 }} + {{- end }} {{- end }} {{- if and (not .Values.external.mq.enabled) .Values.rabbitmq.install }} - name: wait-for-rabbitmq @@ -120,6 +123,9 @@ spec: value: {{ include "rabbitmq.subchart" . }} - name: RABBITMQ_PORT value: {{ .Values.rabbitmq.service.ports.amqp | quote }} + {{- if .Values.defaultInitContainers.resources }} + resources: {{- toYaml .Values.defaultInitContainers.resources | nindent 12 }} + {{- end }} {{- end }} {{- end }} {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }} @@ -364,6 +370,8 @@ spec: {{- end }} {{- if .Values.resources }} resources: {{- toYaml .Values.resources | nindent 12 }} + {{- else if ne .Values.resourcesPreset "none" }} + resources: {{- include "release.resources.preset" (dict "type" .Values.resourcesPreset) | nindent 12 }} {{- end }} volumeMounts: {{- range $k, $v := .Values.configuration }} diff --git a/values.yaml b/values.yaml index 50dc6792..5b264fda 100644 --- a/values.yaml +++ b/values.yaml @@ -1273,27 +1273,27 @@ containerSecurityContext: runAsNonRoot: true ## Release containers' resource requests and limits -## ref: https://kubernetes.io/docs/user-guide/compute-resources/ +## ref: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ ## 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 ## lines, adjust them as necessary, and remove the curly braces after 'resources:'. +## @param resourcesPreset Set container resources according to one common preset (allowed values: none, nano, micro, small, medium, large, xlarge, 2xlarge). This is ignored if resources is set (resources is recommended for production). +## +resourcesPreset: "micro" +## @param resources Set container requests and limits for different resources like CPU or memory (essential for production workloads) ## @param resources.limits The resources limits for Release containers ## @param resources.requests The requested resources for Release containers +## Example: +## resources: +## limits: +## cpu: 1000m +## memory: 2Gi +## requests: +## cpu: 1000m +## memory: 2Gi ## -resources: - ## Example: - ## limits: - ## cpu: 1000m - ## memory: 2Gi - ## - limits: {} - ## Examples: - ## requests: - ## cpu: 1000m - ## memory: 2Gi - ## - requests: {} +resources: {} ## Configure containers' extra options for liveness and readiness probe ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#configure-probes @@ -1310,6 +1310,17 @@ health: probesLivenessTimeout: 60 probesReadinessTimeout: 60 +## @param defaultInitContainers Default init containers for the Release pod +defaultInitContainers: + ## @param defaultInitContainers.resources Set default init container requests and limits for different resources like CPU or memory (essential for production workloads) + ## + resources: + limits: + cpu: "150m" + memory: "192Mi" + requests: + cpu: "100m" + memory: "128Mi" ## @param initContainers Add init containers to the Release pod ## Example: ## initContainers: @@ -1319,6 +1330,7 @@ health: ## ports: ## - name: portname ## containerPort: 1234 +## resources: {} ## initContainers: [] ## @param sidecars Add sidecar containers to the Release pod @@ -1330,6 +1342,7 @@ initContainers: [] ## ports: ## - name: portname ## containerPort: 1234 +## resources: {} ## sidecars: [] @@ -1376,28 +1389,17 @@ volumePermissions: find "${path}" -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | \ xargs -r chown -R "{{ .Values.containerSecurityContext.runAsUser }}:{{ .Values.podSecurityContext.fsGroup }}" done - ## Init Container resource requests and limits - ## ref: https://kubernetes.io/docs/user-guide/compute-resources/ - ## 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 - ## lines, adjust them as necessary, and remove the curly braces after 'resources:'. + ## @param volumePermissions.resources Set container requests and limits for different resources like CPU or memory (essential for production workloads) ## @param volumePermissions.resources.limits Init container volume-permissions resource limits ## @param volumePermissions.resources.requests Init container volume-permissions resource requests ## resources: - ## Example: - ## limits: - ## cpu: 100m - ## memory: 128Mi - ## - limits: {} - ## Examples: - ## requests: - ## cpu: 100m - ## memory: 128Mi - ## - requests: {} + limits: + cpu: "150m" + memory: "192Mi" + requests: + cpu: "100m" + memory: "128Mi" ## Init container' Security Context ## Note: the chown of the data folder is done to containerSecurityContext.runAsUser ## and not the below volumePermissions.containerSecurityContext.runAsUser