Configure datasource via values

1/12/2019

As the title indicates I'm trying to setup grafana using helmfile with a datasource via values.

I can find the docs here but sadly my knowledge is too limited to make it work.

The relevant part of my helmfile is here

releases:
...
  - name: grafana
    namespace: grafana
    chart: stable/grafana
    values:
      - datasources:
        - name: Prometheus
          type: prometheus
          url: http://prometheus-server.prometheus.svc.cluster.local

I stumbled upon this and it seems I can also do it via an environment variable but I can't seem to find an easy way to set such in my helmfile.

It would be greatly appreciated if someone with a better understanding of helmfile, json and whatnot could either show me or guide me in the right direction.

Update: Thanks to @WindyFields my final solution is as follows

releases:
...
  - name: grafana
    namespace: grafana
    chart: stable/grafana
    values:
      - datasources:
          datasources.yaml:
            apiVersion: 1
            datasources:
              - name: Prometheus
                type: prometheus
                access: proxy
                url: http://prometheus-server.prometheus.svc.cluster.local
                isDefault: true
-- user672009
grafana
helmfile
kubernetes

1 Answer

1/12/2019

Answer

Just add the following snipped straight into values.yaml:

datasources:
  datasources.yaml:
    apiVersion: 1
    datasources:
    - name: Prometheus
      type: prometheus
      url: http://prometheus-server.prometheus.svc.cluster.local

Details

After Helm renders the template there will be the following configmap generated:

# Source: grafana/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-grafana
  labels:
    app: grafana
    chart: grafana-1.20.0
    release: RELEASE-NAME
    heritage: Tiller
data:
  grafana.ini: |
    ...
  datasources.yaml: |
    apiVersion: 1
    datasources:
    - name: Prometheus
      type: prometheus
      url: http://prometheus-server.prometheus.svc.cluster.local 

After Helms installs the chart, k8s will take datasources configuration datatsources.yaml from config.yaml and mount it by the following path /etc/grafana/provisioning/datasources/datasources.yaml, where it will be picked up by Grafana app.

See Grafana datasources provisioning doc.

Tip: to see rendered Helm template use helm template <path_to_chart>

-- WindyFields
Source: StackOverflow