Building kube-state-metrics from source

Today I had to build kube-state-metrics Kubernetes extra metrics exporter for Prometheus monitoring system. I wanted to build it for specific Linux (kernel) version (in my case it was Alpine Linux 3.4), and I also wanted to build a specific version of kube-state-metrics – latest stable, which is 1.3.1 currently.

I didn’t want to get latest version from master as I was not sure about it’s stability and I would have hard time re-creating the build since master would move on over time, so simply making “go get” wasn’t an option.

The process turned out to be a bit tricky – I wanted to use docker to have proper version of Go lang for Alpine Linux 3.4 while I’m on a macOS myself, but the makefile of kube-state-metrics also uses docker (for whatever silly reason that is), so I needed to build it using go build.

As it turned out, I had to do two things – install Go into Alpine 3.4 (which took some copypasting from https://github.com/docker-library/golang where they have Dockerfile for Alpine 3.7 – contents of which I used) and then get the paths right for GOPATH in order to build kube-state-metrics.

Here’s the resulting Dockerfile: Continue reading

Advertisements