prometheus-community / helm-charts

Prometheus community Helm charts
Apache License 2.0
4.99k stars 4.99k forks source link

[kube-prometheus-stack] How to set kube-prometheus-stack Grafana sidecar containers resource limit? #4766

Closed hongbo-miao closed 3 weeks ago

hongbo-miao commented 1 month ago

I deployed kube-prometheus-stack using it Helm Chart.

I am trying to set kube-prometheus-stack Grafana sidecar containers resource limit.

Here is original Helm chart values.yaml: https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml

Below is my custom values.yaml

grafana:
  resources:
    requests:
      cpu: 50m
      memory: 256Mi
    limits:
      cpu: 100m
      memory: 512Mi
  sidecar:
    dashboards:
      resources:
        requests:
          cpu: 50m
          memory: 256Mi
        limits:
          cpu: 100m
          memory: 512Mi
    datasources:
      resources:
        requests:
          cpu: 50m
          memory: 256Mi
        limits:
          cpu: 100m
          memory: 512Mi

However, when I use Goldilocks to check, you can see the Grafana container in this pod resource got limited, but two sidecar containers resource still didn't get limited.

image

How to set kube-prometheus-stack Grafana sidecar containers resource limit? Thanks!

zeritti commented 1 month ago

Resources for the two sidecars are set through the subchart's field sidecar.resources (values.yaml), i.e. grafana.sidecar.resources in the KPS chart's values.

hongbo-miao commented 3 weeks ago

Thanks @zeritti ! I missed this, I will test and lost back the result. 😃

hongbo-miao commented 3 weeks ago

Hi @zeritti I am a little lost. The one you mentioned is in Grafana Helm chart values.yaml. Hmm I know Grafana in this case is subchart. However, how could we set them in kube-prometheus-stack Helm chart values.yaml? I may miss some knowledge here. Thanks!

zeritti commented 3 weeks ago

A subchart remains a standalone chart with all of its supported values. The subchart's values gets inserted in the parent's values file underneath the field of its name, i.e. grafana in this case (this is how the chart's defaults get overriden). You are already doing it as shown above.

If you wish to insert a value for the grafana chart that is not present in the KPS values file underneath grafana, you have to look it up in that chart's values file, i.e. in the grafana chart's values file. You have to review this file before you deploy the stack (and this applies to all the subcharts) - the parent chart does not override/set all the relevant values, e.g. persistence, grafana.ini, etc. - the user must make a choice)

Grafana chart's values file is here. You see that it has sidecar resources for the two sidecars defined in sidecar.resources. Now, you take this field and insert it in your custom values file in the grafana field as grafana.sidecar.resources, e.g.

grafana:
  resources:
    requests:
      cpu: 50m
      memory: 256Mi
    limits:
      cpu: 100m
      memory: 512Mi
  sidecar:
    dashboards:
      resources:
        requests:
          cpu: 50m
          memory: 256Mi
        limits:
          cpu: 100m
          memory: 512Mi
    datasources:
      resources:
        requests:
          cpu: 50m
          memory: 256Mi
        limits:
          cpu: 100m
          memory: 512Mi
    ##
    ## here the inserted field
    ##
    resources:
      requests:
        cpu: 50m
        memory: 50Mi
      limits:
        cpu: 100m
        memory: 100Mi