kubernetes 如何为数据源创建grafana configmap?

gcmastyq  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(2)|浏览(127)

我尝试使用Kube-Prometheus-Stack helm chart https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack中的Grafana示例为Grafana数据源创建配置Map
我知道对于 Jmeter 板,您可以使用以下答案中列出的命令从json文件创建configmap:stable/prometheus-operator - adding persistent grafana dashboards

wget https://raw.githubusercontent.com/percona/grafana-dashboards/master/dashboards/MongoDB_Overview.json
kubectl -n monitoring create cm grafana-mongodb-overview --from-file=MongoDB_Overview.json
kubectl -n monitoring label cm grafana-mongodb-overview grafana_dashboard=mongodb-overview

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

data:
      datasource-PRF1-Prometheus.yaml: |-
        apiVersion: 1
        datasources:
          - name: Test-Prometheus
            type: prometheus
            url: https://prometheus.url.net/
            access: Server
            isDefault: true
            basicAuth: true
            basicAuthPassword: password
            basicAuthUser: admin


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

m3eecexj

m3eecexj1#

要想通过grafana服务器组件加载数据,需要在元数据字段grafana_datasource: "1"中设置此选项。
对于配置Map:

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

m1m5dgzv

m1m5dgzv2#

我有一个ConfigMap的grafana与prometheus数据源,刮Flink任务管理器。文件(https://github.com/felipegutierrez/explore-flink/blob/master/k8s/grafana-configuration-configmap.yaml)太大,无法粘贴到此处,但主要部分如下。

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 pod中调用它,如下所示:

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/


完整的工作示例如下:https://github.com/felipegutierrez/explore-flink/blob/master/k8s/grafana-deployment.yaml

相关问题