I recently blogged about deploying kubernetes in Azure. After doing so, I wanted to keep an eye on usage of the instances and pods.
Kubernetes recommends Heapster as a cluster aggregator to monitor usage of nodes and pods. Very handy if you are deploying in Google Compute (GCE) as it has a pre-build dashboard to hook it to.
Heapster runs on each node, collects statistics of the system and pods which pipes to a storage backend of your choice. A very handy part of Heapster is that export user labels as part of metadata, which I believe can be used to create custom reports on services across nodes.
If you are not using GCE or just don’t want to use their dashboard, you can deploy a combo of InfluxDB and Grafana as a DIY solution. While this seems promising the documentation, as usual, is pretty short on details..
Start by using the “detailed” guide to deploy the add on, which basically consists of:
**wait! don’t run this yet until you finished reading article**
git clone https://github.com/kubernetes/heapster.git
cd heapster
kubectl create -f deploy/kube-config/influxdb/
These steps exposes Grafana and InfluxDB via the api proxy, you can see them in your deployment by doing:
kubectl cluster-info
This didn’t quite work for me, and while rummaging in the yamls, I found out that this is not really the recommended configuration for live deployments anyway…
So here is what I did:
- Remove env variables influxdb-grafana-controller.yaml
- Expose service as NodePort or LoadBalancer depends of your preference in grafana-service.yaml. E.g. Under spec section add: type: NodePort
- Now run >kubectl create -f deploy/kube-config/influxdb/
You can see the expose port for Grafana by running:
kubectl --namespace=kube-system describe service grafana-service
In this deployment, all the services, rc and pods are added under the kube-system namespace, so remember to add the –namespace flag to your kubectl commands.
Now you should be able to access Grafana on any external ip or dns on the port listed under NodePort. But I was not able to see any data.
Login to Grafana as admin (admin:admin by default), select DataSources>influxdb-datasource and test the connection. The connection is set up as http://monitoring-influxdb:8086, this failed for me.
Since InfluxDB and Grafana are both in the same pod, you can use localhost to access the service. So change the url to http://localhost:8086, save and test the connection again. This worked for me and a minute later I was getting realtime data from nodes and pods.
Proxying Grafana
I run an nginx proxy that terminates https requests for my domain and a created a https://mydomain/monitoring/ end point as part of it.
For some reason, Grafana needs to know the root-url format that is being accessed from to work properly. This is defined in a config file.. while you could change it and rebuild the image, I preferred to override it via an enviroment variable in the influxdb-grafana-controller.yaml kubernetes file. Just add to the Grafana container section:
env:
- name: GF_SERVER_ROOT_URL
value: "%(protocol)s://%(domain)s:%(http_port)s/monitoring"
You can do this with any of the Grafana config values, which allows you to reuse the official Grafana docker image straight from the main registry.
Calls such as http://monitoring-influxdb:8086 might have failed because you probably doesn’t have SkyDNS running.
That is a good point, but all other services worked. It might have been some miss configuration in my service file or something
Hi Victor, great post! Thank you very much. I have a Kubernetes cluster running on DigitalOcean and I’m trying to deploy Heapster+InfluxDB there (using NodePort). Can you please share your yaml files after perform the following changes: “Remove env variables influxdb-grafana-controller.yaml. Expose service as NodePort or LoadBalancer depends of your preference in grafana-service.yaml. E.g. Under spec section add: type: NodePort”. I have tried to apply such changes but still no success. Thank you very much in advance!
here you are: https://github.com/vtuson/heapster
to deploy, clone the repo and run kubectl create -f (folder)
Then check the nodeport on the service:
kubectl –namespace=kube-system describe service monitoring-grafana
and point your browser to it with http://yourip:nodeport
if you want to proxy it into a another path, make sure you modify the server root url for grafana
https://github.com/vtuson/heapster/blob/master/influxdb-grafana-controller.yaml#L29
Hi Victor,
Great, thank you very much for your info and files!
Great blog by the way!
Cheers!