Enables automatic detection and update of Grafana dashboards and Datasources contained in Kubernetes configmaps.
By running this watcher in the same pod as Grafana, dashboards and datasources can be discovered as Grafana starts and while it's running. This has the benefit of removing the need for persistent storage, while ensuring that a re-scheduled pod will reload configured dashboards.
The typical workflow here is that the Grafana dashboards are treated as code and should be pushed through configmaps, rather than manually modified in Grafana itself.
Latest version of this image can be pulled from Docker Hub:
pierrevincent/k8s-grafana-watcher
-dashboardAnnotation
(defaults to envCONFIG_MAP_DASHBOARD_ANNOTATION
): Annotation to indicate configmaps containing Grafana Dashboards-datasourceAnnotation
(defaults to envCONFIG_MAP_DATASOURCE_ANNOTATION
): Annotation to indicate configmaps containing Grafana Datasource-grafanaUrl
(defaults to envGRAFANA_URL
): Grafana URL to POST updates-grafanaUsername
(defaults to envGRAFANA_USERNAME
): Username for Grafana API authentication-grafanaPassword
(defaults to envGRAFANA_PASSWORD
): Password for Grafana API authentication
Examples of config maps for Dashboards and Datasources can be found in example directory.
Note that dashboard JSON should specify "id": null
, to allow both creation and update.
This watcher is best run in the same pod as Grafana (you can run it outside too, but it is built with the life-cycle of the Grafana container in mind).
See deployment for an example of a Kubernetes deployment & service combining Grafana and the grafana-watcher.
Note that this watcher is a rough proof-of-concept, please be aware of the following if you decide to make use of it:
- Datasources can only be created at the moment
- Removing configmaps (or entries in configmaps) does not remove the corresponding Dashboards or Datasources
- Renaming Dashboards and Datasources won't remove the old ones
Feel free to create issues or pull requests if you see anything that can be improved.
This watcher was inspired by the work done on the Prometheus Rule Loader, kudos on the idea!
GNU GPLv3, see LICENSE