Kubernetes 如何为数据源创建grafana配置映射?

Kubernetes 如何为数据源创建grafana配置映射?,kubernetes,prometheus,grafana,prometheus-operator,Kubernetes,Prometheus,Grafana,Prometheus Operator,我正在尝试使用Kube Prometheus Stack helm图表中的Grafana实例为Grafana数据源创建configmap 我知道,对于仪表板,您可以使用以下回答中列出的命令从json文件创建configmap: 可以为grafana数据源做类似的事情吗?我目前有一个datasource.yaml,其中包含以下行: 数据: 数据源-PRF1-Prometheus.yaml:|- 版本:1 数据源: -名称:测试普罗米修斯 类型:普罗米修斯 网址:https://prometheus

我正在尝试使用Kube Prometheus Stack helm图表中的Grafana实例为Grafana数据源创建configmap

我知道,对于仪表板,您可以使用以下回答中列出的命令从json文件创建configmap:

可以为grafana数据源做类似的事情吗?我目前有一个datasource.yaml,其中包含以下行:

数据:
数据源-PRF1-Prometheus.yaml:|-
版本:1
数据源:
-名称:测试普罗米修斯
类型:普罗米修斯
网址:https://prometheus.url.net/
访问:服务器
isDefault:正确
巴斯考思:是的
基本密码:密码
基本用户:管理员

但是,我无法使用它导入数据源,即使它创建了一个configmap。

我有一个
configmap
用于grafana with e prometheus数据源,该数据源可以清除Flink任务管理器。文件()太大,无法粘贴到此处,但主要部分如下

apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-config
  namespace: kafka
  labels:
    app: flink
data:
  grafana.ini: |+ ...
  dashboards.yml: |+
    apiVersion: 1
 database
    deleteDatasources:
      - name: Prometheus
        orgId: 1
    datasources:
      - name: Prometheus
        type: prometheus
        access: proxy
        orgId: 1
        url: http://prometheus-service:9090
        password:
        user:
        database:
        basicAuth: false
        basicAuthUser:
        basicAuthPassword:
        withCredentials:
        isDefault: true
        jsonData:
          graphiteVersion: "1.1"
          tlsAuth: false
          tlsAuthWithCACert: false
        secureJsonData:
          tlsCACert: "..."
          tlsClientCert: "..."
          tlsClientKey: "..."
        version: 1
        editable: true
  dashboard.json: |+
    {...}
设置了
ConfigMap
后,您可以在grafana吊舱内这样调用它:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana-deployment
  namespace: kafka
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flink
      component: grafana
  template:
    metadata:
      labels:
        app: flink
        component: grafana
    spec:
      volumes:
      - name: grafana-config-volume
        configMap:
          name: grafana-config
          items:
          - key: grafana.ini
            path: grafana.ini
          - key: datasource.yml
            path: provisioning/datasources/datasource.yml
          - key: dashboards.yml
            path: provisioning/dashboards/dashboards.yml
          - key: dashboard.json
            path: dashboard.json
      containers:
      - name: grafana
        image: grafana/grafana
        imagePullPolicy: IfNotPresent # Always
        ports:
        - containerPort: 3000
          name: http
        volumeMounts:
          - name: grafana-config-volume
            mountPath: /etc/grafana/

完整的工作示例如下:

要通过grafana服务器组件加载数据,需要在元数据字段
grafana_数据源:“1”
中设置此项

对于configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: example-grafana-datasource
  labels:
     grafana_datasource: "1"
     namespace: monitoring
data:
  datasource.yaml: |-
    apiVersion: 1
    datasources:
    - access: proxy
      basicAuth: false
      editable: false
      isDefault: false
      jsonData:
        authType: credentials
        defaultRegion: us-west-2
      name: CloudWatch
      type: cloudwatch
为了一个标签相同的秘密

apiVersion: v1
kind: Secret
metadata:
  name: influx-grafana-datasource
  labels:
     grafana_datasource: "1"
     namespace: monitoring
type: Opaque
stringData:
  influxdatasource.yaml: |-
    # config file version
    apiVersion: 1
    datasources:
      - name: influxdb
        type: influxdb
        access: proxy
        database: metrics_db
        user: metrics_read_user
        url: http://influx.example.com:8086/
        jsonData:
          timeInterval: "15s"
        secureJsonData:
          password: yourinfluxpassword

谢谢你的回答!抱歉,我对Grafana还是新手,是否有一个命令可以用于通过CLI更新pod的yml文件并插入对configmap的调用?您可以使用相同的命令创建pod
kubectl apply-f file.yaml
,如果与以前的
文件.yaml
存在一些差异,它也会更新pod。但是,我不确定它是否适用于configMaps,因为部署吊舱是另一个吊舱。我想你必须重新启动格拉夫纳吊舱。类似这样的
kubectl-n服务卷展重新启动部署
grafana大师的另一个masterclass。
apiVersion: v1
kind: Secret
metadata:
  name: influx-grafana-datasource
  labels:
     grafana_datasource: "1"
     namespace: monitoring
type: Opaque
stringData:
  influxdatasource.yaml: |-
    # config file version
    apiVersion: 1
    datasources:
      - name: influxdb
        type: influxdb
        access: proxy
        database: metrics_db
        user: metrics_read_user
        url: http://influx.example.com:8086/
        jsonData:
          timeInterval: "15s"
        secureJsonData:
          password: yourinfluxpassword