Kubernetes Python Client read_node_status() doesn't provide accurate allocatable resources

6/22/2018

I'm using Kubernetes v1.7 and Python Client both 2.0 and 6.0. According to this V1NodeStatus, read_node_status() should return both capacity and allocatable resources of a node. I have several jobs and pods are running on a gpu machine. Also, there are some pending jobs that can't be scheduled for insufficient resources i.e. gpu. When I check the value of the node like this

api_response = v1.read_node_status(node)
print api_response.status.capacity

Output

{u'alpha.kubernetes.io/nvidia-gpu': '2', u'pods': '110', u'cpu': '40', u'memory': '65589120Ki'}

I see the right amount of the capacity of a node gets reported. However, when I print api_response.status.allocatable, it shows same as the capacity which is wrong. How can I get the accurate values of allocatable/available resources of a node?

-- Abu Shoeb
api
kubernetes
python

1 Answer

6/25/2018

v1.read_node_status(node) executes following request under the hood:

GET http://apiserver:port/api/v1/nodes/{name}/status

You can check source information using following commands:

kubectl proxy &

curl http://127.0.0.1:8001/api/v1/nodes/YOUR_NODE_NAME/status

If you see in the "allocatable" section the same values you've got from python client, your code is fine.

To investigate why you've got that status, it would be good to see some more data about pods, which use GPUs and pods that can't be scheduled. Perhaps it happened for some other reason, not because of GPU.

-- VAS
Source: StackOverflow