August 2, 2016 Leave a comment
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
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:
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.
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:
- name: GF_SERVER_ROOT_URL
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.