Last week I was in New York, giving a talk at O’Reilly Velocity on the topic of troubleshooting Kubernetes apps and as a follow-up, motivated by the positive feedback and a number of great discussions on the topic, I revisited the space in terms of tooling. Turns out that besides kubernetes-incubator/spartakus and kubernetes/kube-state-metrics we don’t really have many lightweight tooling available at our hands to collect resource stats such as number of pods or services in a namespace. So I sat down on my way home and started coding on a little tool—creatively named krs which is short for Kubernetes Resource Stats—that allows you to gather these stats.

You can use mhausenblas/krs in two ways:

Directly from the command line (binaries for Linux, Windows, and macOS are available)

In-cluster, as a deployment, using the launch.sh script, which creates the appropriate RBAC permissions on the fly.

Mind you, it’s very early days, that is heavily WIP but so far, the 0.1 release of krs sports the following features:

On a per-namespace basis, periodically gathers resource stats (supporting pods, deployments, and services).

Exposes these stats as metrics in the OpenMetrics format.

Usage directly via binaries or in a containerized setup with all dependencies included.

In the current form and because I’m a lazy ass, I’m assuming that you’ve got kubectl installed and configured in order for krs to work. In other words, in order to gather the stats, krs relies on a kubectl get all command to be executed. On the other hand, who’s using Kubernetes and hasn’t got kubectl installed? ;)

It’s super simple to use krs … simply download the binary for your platform and execute it like this:

$ krs thenamespacetowatch

# HELP pods Number of pods in any state, for example running

# TYPE pods gauge

pods{namespace="thenamespacetowatch"} 13

# HELP deployments Number of deployments

# TYPE deployments gauge

deployments{namespace="thenamespacetowatch"} 6

# HELP services Number of services

# TYPE services gauge

services{namespace="thenamespacetowatch"} 4

Above will launch krs in the foreground, gathering resource stats from the namespace thenamespacetowatch and outputting them respectively in the OpenMetrics format on stdout for you to further process.

But Michael, you may ask, why not doing something useful (such as storing ’em in S3) with the metrics. Because Unix philosophy.