How to create grafana configmap for datasources?
For you to load the data by grafana server component, you would need to set this in your metadata field grafana_datasource: "1"
.
For a configmap:
apiVersion: v1kind: ConfigMapmetadata: name: example-grafana-datasource labels: grafana_datasource: "1" namespace: monitoringdata: datasource.yaml: |- apiVersion: 1 datasources: - access: proxy basicAuth: false editable: false isDefault: false jsonData: authType: credentials defaultRegion: us-west-2 name: CloudWatch type: cloudwatch
For a secret with the same label
apiVersion: v1kind: Secretmetadata: name: influx-grafana-datasource labels: grafana_datasource: "1" namespace: monitoringtype: OpaquestringData: 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
I have a ConfigMap
for grafana withe prometheus datasource that scrapes Flink Task Managers. The file (https://github.com/felipegutierrez/explore-flink/blob/master/k8s/grafana-configuration-configmap.yaml) is too big to paste here but the main sections are below.
apiVersion: v1kind: ConfigMapmetadata: name: grafana-config namespace: kafka labels: app: flinkdata: 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: |+ {...}
After having the ConfigMap
set you call it inside the grafana pod like this:
apiVersion: apps/v1kind: Deploymentmetadata: name: grafana-deployment namespace: kafkaspec: 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/
The full example working is here: https://github.com/felipegutierrez/explore-flink/blob/master/k8s/grafana-deployment.yaml