Hit count for kubernetes services object

8/20/2018

I am writing a custom Kubernetes controller and resource to keep track of the number of times a service object is called. The idea behind this is to add a "hitcount" field to the resource and update it every time a service is invoked. (Meaning update the count every time a request is made to the pod that is part of the service)

Is this possible? Does the kubernetes API have an option to do this?

-- Jilpansi
go
kubernetes

1 Answer

8/20/2018

it sounds like you're in fact trying to implement a metric inside kubernetes api. It's hardly a controller though. In a nutshell, controller is piece of software that continuously realizes an intent stated in kubernetes API in a real world.

Semantics aside, status object in kubernetes API is defined in it's type. For Pod, at the moment of writing of this answer it's here and it's not an extensible one. So you can't really put your metric into the Pod object.

The question that this naturally poses is why not use something that is expected for metrics collection and visualization like prometheus/grafana ?

All of that aside, you also have an issue of how will you expose/collect that metric. Istio could help here, or the software in pod it self could expose it's metrics (which, if possible, is the best route to take imo)

-- Radek 'Goblin' Pieczonka
Source: StackOverflow