davidB / kubectl-view-allocations

kubectl plugin to list allocations (cpu, memory, gpu,... X utilization, requested, limit, allocatable,...)

Home Page:https://crates.io/crates/kubectl-view-allocations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make it work within a service account

jaimehrubiks opened this issue · comments

I cannot get this software to work within a kubernetes pod.

I first run it without permissions, and I got specific errors such as "cannot list pods ....", and so I added a custom ClusterRole, and then, instead of seeing those types of errors I just see:

[2020-05-11T17:51:38Z ERROR kubectl_view_allocations] failed 
    cli: CliOpts { namespace: None, show_zero: false, resource_name: ["gpu"], group_by: [resource, node, pod] }
    error: failed to load kubectl config
    
    Caused by:
        0: failed to load kubeconfig
        1: Error loading kube config: No such file or directory (os error 2)

I even tried adding the "cluster-admin" ClusterRole to the ServiceAccount, without luck. And it is weird because I can run every single kubectl command with this serviceaccount within the pod, but kubectl-view-allocations does not provide more information about the error

Is it that it just needs a kubeconfig file? I thought it was just using kubectl as-is

The tool doesn't call kubectl (except for a check at start). but it uses libs to handle communication with kube api server. (Maybe it could used kubectl cli as a fallback if the libs can not connect).

The cli was thought to run on a user desktop with a kubeconfig file (not found, from your error), so never tested inside a pod. What is the purpose to use it inside a pod (the current output of the tools is not machine friendly) ?

I actually knew this tool was meant to run on a desktop and that I was doing kind of a "fix" by running it inside a pod.

My idea was to develop a web app that would let my team know the usage of the resources very easily. I was about to develop it myself by calling the api, but found your software to be very good, so just calling it would remove the need.

If I think about it, running it inside a pod is a very weird use case (even more knowing that as you say the output is not machine friendly), and I don't expect more people doing it, so if fixing it is not straight forward, I'd reject this proposal. But thanks anyway for the software, it is very useful

In the past, I thought I could provide some kind of json/yaml or csv output, I didn't agree with myself on what would be useful (mainly because I don't have use cases).

I'll not have time until 8 or 9 days to work on this project. If it's not too long for you then I could include the fallback to use kubectl to request server api, and maybe after provide a more machine friendly output (if you have some kind of spec) ;-)

But if you already run an app inside the target cluster, maybe calling the server api is a better choice for you (api already defined,...). The 2 "tricky" points are :

  • how to aggregate ressources
  • reading + sum of quantities provided in different units eg (MB + KiB)

If you always have the need,

Since May, the lib used to connect to the cluster evolve and now support using some environment variables including "API Access from a Pod", and the plugin itself, also evolve to provide output as csv to be more machine friendly. I guess both evolution should match your use case.

Feel free to comment if it works or not, Thanks