通过值配置数据源

Configure datasource via values

正如标题所示,我正在尝试使用带有数据源的 helmfile 通过值设置 grafana。

我可以找到文档 here,但遗憾的是我的知识太有限,无法实现它。

我的 helmfile 的相关部分在这里

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

我偶然发现了 this,似乎我也可以通过环境变量来做到这一点,但我似乎找不到在我的 helmfile 中设置此类的简单方法。

如果有人对 helmfile、json 等有更好的了解,可以向我展示或指导我正确的方向,我将不胜感激。

更新:感谢@WindyFields 我的最终解决方案如下

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

回答

只需将以下片段直接添加到 values.yaml 中:

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

详情

Helm渲染模板后,会生成如下配置图:

# 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 

Helms 安装图表后,k8s 将从 config.yaml 获取数据源配置 datatsources.yaml 并通过以下路径 /etc/grafana/provisioning/datasources/datasources.yaml 挂载它,Grafana 应用程序将在此处获取它。

参见 Grafana datasources provisioning doc

提示: 查看渲染的 Helm 模板使用 helm template <path_to_chart>