How to calculate available free resources in a kubernetes node

1/23/2019

I am using official kubernetes java api for controlling a local kubernetes cluster. what is the best way to calculate the available resources for each node in the cluster. Is there any api method for V1Node which can do that for me? If not, then any suggestion to do this with java code will be really helpful.

node.getStatus().getAllocatable().get("cpu").getNumber()
node.getStatus().getCapacity().get("cpu").getNumber()

these two methods provide allocatable and total capacity of each node. However, not sure how to find the available resources. for me even even though few pod are running in my local cluster, "allocatable" and "capacity" are coming same.

-- psaha4
kubectl
kubernetes
kubernetes-apiserver

0 Answers