Last Updated on May 10, 2019
Update: This blog inspired a new project which is far better than what I created. I’ll leave this blog here for posterity, but recommend you check out this Github repo and associated Helm chart.
Ever wanted to know what versions of software are running on your Kubernetes cluster? Now, assuming you’re using Helm to install everything, you can.
Install the kubedex-exporter on your cluster, and if you have Prometheus already setup, you’ll start receiving metrics.
1 2 3 |
helm repo add kubedex https://kubedex.github.io/charts helm repo update helm install kubedex/kubedex-exporter |
Ultimately, you will end up with a table like this on your Grafana dashboard. This table will dynamically update as you add and remove helm charts or upgrade versions. Many companies are moving towards using Helm for packaging up their micro-services so this chart should help confirm what versions of services are running where.
Maybe you want to test this out first. Or, perhaps you want to learn more about Prometheus. Here’s a step by step guide to setting up Prometheus on minikube locally. Then we’ll show you how to install the kubedex-exporter helm chart and setup the dashboard.
You can find the installation instructions here: https://kubernetes.io/docs/tasks/tools/install-minikube/
I’d recommend installing VirtualBox if you’re trying this out on OSX.
Once you’ve installed minikube you can start a new cluster with rbac support.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ minikube start --extra-config=apiserver.authorization-mode=RBAC Starting local Kubernetes v1.10.0 cluster... Starting VM... Downloading Minikube ISO 160.27 MB / 160.27 MB [============================================] 100.00% 0s Getting VM IP address... Moving files into cluster... Downloading kubeadm v1.10.0 Downloading kubelet v1.10.0 Finished Downloading kubelet v1.10.0 Finished Downloading kubeadm v1.10.0 Setting up certs... Connecting to cluster... Setting up kubeconfig... Starting cluster components... Kubectl is now configured to use the cluster. Loading cached images from config file. |
Now you have a local Kubernetes cluster running on version 1.10. Time to setup some applications to run on it.
Follow the instructions here: https://docs.helm.sh/using_helm/#installing-helm
We’ll use Helm to install Prometheus, Grafana and Kubedex-Exporter charts.
We’re just doing a demo here so we’ll install Prometheus into its own namespace and disable persistent volumes. If you’re doing this for real in future you’ll want to configure proper storage so you don’t lose all of the data when the containers restart.
1 |
helm install stable/prometheus --namespace prometheus --set alertmanager.persistentVolume.enabled=false,server.persistentVolume.enabled=false |
Once Prometheus is installed let’s check the targets are all up and green. Open a port to the Prometheus instance so you can see the targets page in the UI.
1 |
kubectl port-forward $(kubectl get pod --selector app=prometheus,component=server -o jsonpath={.items..metadata.name} -n prometheus) -n prometheus 9090:9090 |
Now open a browser to http://localhost:9090/graph
Everything should be up and green.
Now lets install the Kubedex-exporter and see if it pops up in this target list.
Add the kubedex chart repository and install the chart as follows.
1 2 3 |
helm repo add kubedex https://kubedex.github.io/charts helm repo update helm install kubedex/kubedex-exporter |
This will start a pod in the default namespace. You can also specify –namespace whatever on the helm install line to put it somewhere else.
Now lets have a look at the targets page again and confirm that the kubedex exporter is being scraped.
I added the red box around the part you’re looking for. You should see a pod being scraped on port 9484 and the state should be up. You may need to manually refresh the targets page to get this to show up.
Now you have metrics coming in you’ll want to see pretty graphs. Setting up Grafana is another simple helm command.
1 |
helm install stable/grafana --namespace grafana |
Once installed grab the password from the secrets store so you can login.
1 |
kubectl get secret --namespace grafana $(kubectl get pod --selector app=grafana -o jsonpath={.items[0].spec.containers[0].env[0].valueFrom.secretKeyRef.name} -n grafana) -o jsonpath="{.data.admin-password}" | base64 --decode ; echo |
Then open a port to the Grafana web UI.
1 |
kubectl port-forward $(kubectl get pod --selector app=grafana -o jsonpath={.items..metadata.name} -n grafana) -n grafana 3000:3000 |
Now open a browser to http://localhost:3000
Login with username admin and the password you got from above. Once logged in we’ll need to setup a data source to Prometheus.
We need to tell Grafana how to connect to the Prometheus server instance so lets find out the endpoint.
1 2 3 4 5 6 7 |
$ kubectl get ep -n prometheus NAME ENDPOINTS AGE loitering-horse-prometheus-alertmanager 172.17.0.6:9093 51m loitering-horse-prometheus-kube-state-metrics 172.17.0.7:8080 51m loitering-horse-prometheus-node-exporter 10.0.2.15:9100 51m loitering-horse-prometheus-pushgateway 172.17.0.8:9091 51m loitering-horse-prometheus-server 172.17.0.5:9090 51m |
In our case we’re looking at the bottom endpoint that ends prometheus-server and listens on port 9090.
Copy and paste that into the Grafana data source. Here’s what my one looks like:
On a proper cluster you’d have DNS setup properly and use a better URL.
As you saw from above you get quite a lot of default targets when you install Prometheus. Importing dashboards is quite simple. From the top dropdown menu click ‘import dashboard’. Then paste in this dashboard reference: 6417
You should see a nice pretty dashboard.
Not bad for a few commands and 5 minutes work. Lets make our own dashboard next and select the table panel so we can display our kubedex-exporter Helm chart versions.
In the table panel properties use this query.
You can see the metric is called helm_chart_info and we’re getting the name and version labels.
For those who prefer to copy and paste here’s the query.
1 |
avg(helm_chart_info) by (name, version) |
Be sure to tick the instant checkbox at the bottom right. You’ll also need to go into the Column Styles tab and add an entry for the Time and Value fields separately, and set them to hidden.
That’s it! Now you get the table shown at the beginning of this article.
This is only version 1 of the kubedex-exporter. I’m planning on adding another label to the helm_chart_info metric that displays current latest chart version. Then we can create another table showing out of date charts.
If you want to contribute to the exporter you can find it here: https://github.com/Kubedex/exporter
Tell us about a new Kubernetes application
Never miss a thing! Sign up for our newsletter to stay updated.
Discover and learn about everything Kubernetes