I would like to develop a simple webservice, which returns kubernetes metrics like node / pod CPU and RAM usage in percentage.
In CLI there are commands like kubectl top node or kubectl describe node with all the metrics i need. However i am unable find such metrics in kubernetes REST api endpoints. The closest one i got is /apis/metrics.k8s.io/v1beta1/nodes endpoint, which shows CPU and RAM usage but no in percentage.
Is there such an endpoint which show the same information as in top or describe commands or, perhaps, there are better way than metrics.k8s.io addon.
When you issue
kubectl top node, kubectl makes multiple HTTP requests to multiple endpoints. You can see exact endpoints by adding--v=9flag tokubectl.For example, in my case
(there are a lot more, those two are important to answer your question)
First request return
.usage.cpuand.usage.memoryshow used CPU and memory respectively.Second request return (truncated, the response is huge)
.status.allocatable.cpuand.status.allocatable.memoryshow how much CPU and memory can be allocated to running pods.As you can see, there is no endpoint that return usage in percentage, kubectl does the calculation on the fly, to output the result in human friendly format