I want to limit a specific namespace to never leave less then a full cpu for my other namespaces (using a resources quota) and i have to problems in the way.: a. Today i find the total amount of cpus using kubectl top nodes
and divide the nominal cpu usage in the usage percentages, this is not accurate enough, is there a way to get my cluster total available cpu? b. I would like to dynamically adjust to changes in the cluster (specifically added or removed nodes), a cronjob works fine but I'm looking for a way to hook major nodes changes, is there a known way to do that?
Number of nodes CPUs is under .status.capacity.cpu
in node object. You can print them e.g. with kubectl get nodes -o custom-columns=NAME:.metadata.name,CPU:.status.capacity.cpu
.
Dynamicaly adding/removing nodes can be achieved using autoscaler.
Not directly. You can set namespace level quotas easily enough but to make it that kind of dynamic thing you would need to make an operator or similar. A simple version would be a script running as a cron job which updates the Quota object.