<p>I'm trying to understand helm and I wonder if someone could ELI5 to me something or help me with something.</p>

<p>So i did run below:</p>

<pre><code>helm repo add coreos https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/
</code></pre>

<p>Then I installed kube-prometheus by using below: </p>

<pre><code>helm install coreos/kube-prometheus --name kube-prometheus -f values.yaml --namespace monitoringtest
</code></pre>

<p>Everything works fine but I'm trying to add some custom dashboards from json files and I'm struggling to understand how to do it.</p>

<p>I was following this: <code>https://blogcodevalue.wordpress.com/2018/09/16/automate-grafana-dashboard-import-process/</code></p>

<p>In my values.yaml I added below</p>

<pre><code>serverDashboardConfigmaps:
  - example-dashboards
</code></pre>

<p>I understand that if I do:</p>

<pre><code>helm upgrade --install kube-prometheus -f values.yaml --namespace monitoringtest coreos/kube-prometheus
</code></pre>

<p>That should cause grafana to pickup a below configmap called <code>example-dashboards</code> and load *.json files from <code>custom-dashboards</code> folder. </p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: example-dashboards
data:
{{ (.Files.Glob "custom-dashboards/*.json").AsConfig | indent 2 }}

# Or
# 
# data:
#   custom-dashboard.json: |-
# {{ (.Files.Get "custom.json") | indent 4 }}
#
# The filename (and consequently the key under data) must be in the format `xxx-dashboard.json` or `xxx-datasource.json`
# for them to be picked up.
</code></pre>

<p>Now two questions:</p>

<p>How do I add above configmap to this helm release?</p>

<p>Where is this <code>custom-dashboards</code> folder located? Is it on my laptop and then is send to grafana?</p>

<p>Do I need to copy all of <code>https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/</code> onto my laptop?</p>

<p>Sorry for explaining everything but I'm just trying to understand this.</p>

<p>You can find a good example of how to do this in the charts for prometheus-operator here:</p>
<p><a href="https://github.com/helm/charts/tree/master/stable/prometheus-operator/templates/grafana" rel="noreferrer">https://github.com/helm/charts/tree/master/stable/prometheus-operator/templates/grafana</a></p>
<p>It is a ConfigMapList that gets all JSONs from a given directory and stores them into ConfigMaps which are read by Grafana.</p>
<pre><code>{{- $files := .Files.Glob &quot;dashboards/*.json&quot; }}
{{- if $files }}
apiVersion: v1
kind: ConfigMapList
items:
{{- range $path, $fileContents := $files }}
{{- $dashboardName := regexReplaceAll &quot;(^.*/)(.*)\\.json$&quot; $path &quot;${2}&quot; }}
- apiVersion: v1
  kind: ConfigMap
  metadata:
    name: {{ printf &quot;%s-%s&quot; (include &quot;prometheus-operator.fullname&quot; $) $dashboardName | trunc 63 | trimSuffix &quot;-&quot; }}
    namespace: {{ template &quot;prometheus-operator.namespace&quot; . }}
    labels:
      {{- if $.Values.grafana.sidecar.dashboards.label }}
      {{ $.Values.grafana.sidecar.dashboards.label }}: &quot;1&quot;
      {{- end }}
      app: {{ template &quot;prometheus-operator.name&quot; $ }}-grafana
{{ include &quot;prometheus-operator.labels&quot; $ | indent 6 }}
  data:
    {{ $dashboardName }}.json: {{ $.Files.Get $path | toJson }}
{{- end }}
{{- end }}
</code></pre>
<p>Mind that the size of a ConfigMap might be limited:
<a href="https://stackoverflow.com/a/53015758/4252480">https://stackoverflow.com/a/53015758/4252480</a></p>
