<p>I have an application that will start Jobs in different K8S cluster/cloud provider depending of different criteria, including the current availability of the cluster.
In other word, my application will loop over acceptable K8S clusters, and if a cluster is currently full, the job can be launched in a different cluster.</p>
<p>My problem is, how to determine that the Job will fit or not in the cluster.
My first idea was to loop over all nodes, and see how many have enough resources (Mem/CPU) to run my job.</p>
<p>While doable, it seems there is no native API to get used resources for one specific node. I can code that, but this gives me the feeling this is not the right solution, as it seems to be redoing part of the kube scheduler, and I am sure there are lot of edge case to be taken in account.</p>
<p>Maybe I am overthinking this, and this totally the right path, but I wanted to check if there was not cleaner solution.</p>

Djoby
<p>You can use <a href="https://github.com/kubernetes/kube-state-metrics" rel="nofollow noreferrer">kube-state-metrics</a> which exposes a metrics api that you could query.</p>
<p>With that you have <a href="https://github.com/kubernetes/kube-state-metrics/blob/master/docs/node-metrics.md" rel="nofollow noreferrer">node metrics</a> like <code>kube_node_status_allocatable</code> or <code>kube_node_status_capacity</code> and <a href="https://github.com/kubernetes/kube-state-metrics/blob/master/docs/pod-metrics.md" rel="nofollow noreferrer">pod metrics</a> like <code>kube_pod_container_resource_requests</code> or <code>kube_pod_container_resource_limits</code>.</p>
