From 02ae2ff78ad95739b1095a5c5ba5e29d852f33ea Mon Sep 17 00:00:00 2001 From: Tero Keski-Valkama Date: Sat, 10 Dec 2022 16:45:55 +0100 Subject: [PATCH 1/2] Added memory requests to be more realistic. This makes Kubernetes make better choices about where to schedule the pods, and communicates to the administrators about the minimum sensible resource requirements. On a single user Mastodon instance on a three node Kubernetes after a week of so use we get these memory uses per pod: ``` tero@arcones:~$ kubectl top pods -n mastodon NAME CPU(cores) MEMORY(bytes) mastodon-elasticsearch-coordinating-0 6m 403Mi mastodon-elasticsearch-coordinating-1 28m 189Mi mastodon-elasticsearch-data-0 10m 1432Mi mastodon-elasticsearch-data-1 5m 1513Mi mastodon-elasticsearch-ingest-0 6m 418Mi mastodon-elasticsearch-ingest-1 6m 396Mi mastodon-elasticsearch-master-0 24m 466Mi mastodon-elasticsearch-master-1 10m 221Mi mastodon-postgresql-0 12m 276Mi mastodon-redis-master-0 16m 37Mi mastodon-redis-replicas-0 7m 34Mi mastodon-sidekiq-all-queues-549b4bb7b4-zvj2m 266m 499Mi mastodon-streaming-78465f778d-6xfg2 1m 96Mi mastodon-web-774c5c94f9-f5bhz 22m 418Mi ``` Hence we make the following adjustments to Bitnami defaults: - `mastodon-elasticsearch-coordinating`: `256Mi->512Mi` - `mastodon-elasticsearch-data`: The default `2048Mi` is ok. - `mastodon-elasticsearch-master`: `256Mi->512Mi` - `mastodon-redis-master`: `0->56Mi` - `mastodon-redis-replicas`: `0->56Mi` - `mastodon-postgresql`: `256->384Mi` And for Mastodon defaults: - `mastodon-sidekiq-all-queues`: `0->512Mi` - `mastodon-streaming`: `0->128Mi` - `mastodon-web`: `0->512Mi` The original idea of keeping these requests zero is a good default when minimal requirements are unknown. However, from a single user node we get minimal requirements and having the limits as zero only leads to trouble for people. Of course the system requirements will change over time, but they are chiefly expected to go upwards. --- values.yaml | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/values.yaml b/values.yaml index 711f0007..f35c9a76 100644 --- a/values.yaml +++ b/values.yaml @@ -85,15 +85,15 @@ mastodon: # -- (Sidekiq Container) Security Context for all Pods, overwrites .Values.securityContext securityContext: {} # -- Resources for all Sidekiq Deployments unless overwritten - resources: {} - # -- Affinity for all Sidekiq Deployments unless overwritten, overwrites .Values.affinity - affinity: {} + resources: + requests: + cpu: 250m + memory: 512Mi # limits: # cpu: "1" # memory: 768Mi - # requests: - # cpu: 250m - # memory: 512Mi + # -- Affinity for all Sidekiq Deployments unless overwritten, overwrites .Values.affinity + affinity: {} workers: - name: all-queues # -- Number of threads / parallel sidekiq jobs that are executed per Pod @@ -165,13 +165,13 @@ mastodon: # -- (Streaming Container) Security Context for Streaming Pods, overwrites .Values.securityContext securityContext: {} # -- (Streaming Container) Resources for Streaming Pods, overwrites .Values.resources - resources: {} + resources: + requests: + cpu: 250m + memory: 128Mi # limits: # cpu: "500m" # memory: 512Mi - # requests: - # cpu: 250m - # memory: 128Mi web: port: 3000 # -- Number of Web Pods running @@ -183,13 +183,13 @@ mastodon: # -- (Web Container) Security Context for Web Pods, overwrites .Values.securityContext securityContext: {} # -- (Web Container) Resources for Web Pods, overwrites .Values.resources - resources: {} + resources: + requests: + cpu: 250m + memory: 512Mi # limits: # cpu: "1" # memory: 1280Mi - # requests: - # cpu: 250m - # memory: 768Mi # -- Puma-specific options. Below values are based on default behavior in # config/puma.rb when no custom values are provided. minThreads: "5" @@ -243,6 +243,18 @@ elasticsearch: # @ignored image: tag: 7 + coordinating: + resources: + requests: + memory: 512Mi + ingest: + resources: + requests: + memory: 512Mi + master: + resources: + requests: + memory: 512Mi # https://github.com/bitnami/charts/tree/master/bitnami/postgresql#parameters postgresql: @@ -265,6 +277,10 @@ postgresql: # you can also specify the name of an existing Secret # with a key of password set to the password you want existingSecret: "" + primary: + resources: + requests: + memory: 384Mi # https://github.com/bitnami/charts/tree/master/bitnami/redis#parameters redis: @@ -280,6 +296,14 @@ redis: # you can also specify the name of an existing Secret # with a key of redis-password set to the password you want # existingSecret: "" + master: + resources: + requests: + memory: 56Mi + replica: + resources: + requests: + memory: 56Mi # @ignored service: From a7419b5eb3cb6115bba6c225591bf42c83371718 Mon Sep 17 00:00:00 2001 From: Tero Keski-Valkama Date: Sat, 17 Dec 2022 11:47:09 +0100 Subject: [PATCH 2/2] Removed the default values as they are now ineffective with proper defaults set for each pod type separately. --- templates/deployment-sidekiq.yaml | 2 +- templates/deployment-streaming.yaml | 2 +- templates/deployment-web.yaml | 2 +- values.yaml | 13 ------------- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/templates/deployment-sidekiq.yaml b/templates/deployment-sidekiq.yaml index 8a0e9e8c..f25c46ab 100644 --- a/templates/deployment-sidekiq.yaml +++ b/templates/deployment-sidekiq.yaml @@ -122,7 +122,7 @@ spec: mountPath: /opt/mastodon/public/system {{- end }} resources: - {{- toYaml (default (default $context.Values.resources $context.Values.mastodon.sidekiq.resources) .resources) | nindent 12 }} + {{- toYaml (default $context.Values.mastodon.sidekiq.resources .resources) | nindent 12 }} {{- with $context.Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/templates/deployment-streaming.yaml b/templates/deployment-streaming.yaml index dd804044..0a805302 100644 --- a/templates/deployment-streaming.yaml +++ b/templates/deployment-streaming.yaml @@ -70,7 +70,7 @@ spec: httpGet: path: /api/v1/streaming/health port: streaming - {{- with (default .Values.resources .Values.mastodon.streaming.resources) }} + {{- with .Values.mastodon.streaming.resources }} resources: {{- toYaml . | nindent 12 }} {{- end }} diff --git a/templates/deployment-web.yaml b/templates/deployment-web.yaml index 30308e28..ce06650f 100644 --- a/templates/deployment-web.yaml +++ b/templates/deployment-web.yaml @@ -126,7 +126,7 @@ spec: port: http failureThreshold: 30 periodSeconds: 5 - {{- with (default .Values.resources .Values.mastodon.web.resources) }} + {{- with .Values.mastodon.web.resources }} resources: {{- toYaml . | nindent 12 }} {{- end }} diff --git a/values.yaml b/values.yaml index f35c9a76..b58d263f 100644 --- a/values.yaml +++ b/values.yaml @@ -443,19 +443,6 @@ revisionPodAnnotation: true # The annotations set with jobAnnotations will be added to all job pods. jobAnnotations: {} -# -- Default resources for all Deployments and jobs unless overwritten -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:'. - # limits: - # cpu: 100m - # memory: 128Mi - # requests: - # cpu: 100m - # memory: 128Mi - # @ignored nodeSelector: {}