简体   繁体   English

是否有任何 API 或 Go 编程逻辑来获取 kubernetes 集群中的节点容量?

[英]Is there any API or go programming logic to get capacity of node in a kubernetes cluster?

Using kubectl describe nodes, i am able to get the capacity of resources(memory,cpu) of a node.使用 kubectl describe 节点,我可以获得节点的资源(内存,cpu)容量。 I want to get the same via go client or kube API (if available).我想通过 go client 或 kube API(如果可用)获得相同的结果。 Can anyone help me out?谁能帮我吗? i am using minikube version: v1.7.2 kubectl version : Client : GitVersion:"v1.16.3" Server : GitVersion:"v1.16.2" I am using metric-server to access the kubernetes resource.我正在使用 minikube 版本:v1.7.2 kubectl 版本:客户端:GitVersion:"v1.16.3" 服务器:GitVersion:"v1.16.2" 我正在使用 metric-server 访问 kubernetes 资源。 Expected result: Capacity of resources should be accessible through go program or kube API预期结果:资源容量应该可以通过 go 程序或 kube API 访问

Kubernetes Client libraries are the ones you need to look at https://kubernetes.io/docs/reference/using-api/client-libraries/#officially-supported-kubernetes-client-libraries Kubernetes 客户端库是您需要查看的库https://kubernetes.io/docs/reference/using-api/client-libraries/#officially-supported-kubernetes-client-libraries

The following client libraries are officially maintained by Kubernetes SIG API Machinery.

Language    Client Library
Go          github.com/kubernetes/client-go/    
Python      github.com/kubernetes-client/python/
Java        github.com/kubernetes-client/java   
dotnet      github.com/kubernetes-client/csharp 
JavaScript  github.com/kubernetes-client/javascript 
Haskell     github.com/kubernetes-client/haskell    


Community-maintained client libraries
The following Kubernetes API client libraries are provided and maintained by their authors, not the Kubernetes team.

Language                Client Library
Clojure                 github.com/yanatan16/clj-kubernetes-api
Go                      github.com/ericchiang/k8s
Java (OSGi)             bitbucket.org/amdatulabs/amdatu-kubernetes
Java (Fabric8, OSGi)    github.com/fabric8io/kubernetes-client
Lisp                    github.com/brendandburns/cl-k8s
Lisp                    github.com/xh4/cube
Node.js (TypeScript)    github.com/Goyoo/node-k8s-client
Node.js                 github.com/tenxcloud/node-kubernetes-client
Node.js                 github.com/godaddy/kubernetes-client
Node.js                 github.com/ajpauwels/easy-k8s
Perl                    metacpan.org/pod/Net::Kubernetes
PHP                     github.com/maclof/kubernetes-client
PHP                     github.com/allansun/kubernetes-php-client
PHP                     github.com/travisghansen/kubernetes-client-php
Python                  github.com/eldarion-gondor/pykube
Python                  github.com/mnubo/kubernetes-py
Python                  github.com/tomplus/kubernetes_asyncio
Ruby                    github.com/Ch00k/kuber
Ruby                    github.com/abonas/kubeclient
Ruby                    github.com/kontena/k8s-client
Rust                    github.com/clux/kube-rs
Rust                    github.com/ynqa/kubernetes-rust
Scala                   github.com/doriordan/skuber
dotNet                  github.com/tonnyeremin/kubernetes_gen
DotNet (RestSharp)      github.com/masroorhasan/Kubernetes.DotNet
Elixir                  github.com/obmarg/kazan
Elixir                  github.com/coryodaniel/k8s
Haskell                 github.com/kubernetes-client/haskell

There isn't any API call you could use to get kubectl describe nodes this is because this command is generating all the output.没有任何 API 调用可用于获取kubectl describe nodes这是因为此命令正在生成所有输出。

Kubectl retrieves all relevant pods (every pod that isn't failed or succeeded) on a node and sums up all their resource definitions. Kubectl检索节点上的所有相关 pod(每个未失败或成功的 pod)并总结它们的所有资源定义。

You can look into the code and find the function responsible for generating information about node here .您可以查看代码并在此处找到负责生成有关节点信息的函数。

Same for collecting all requests and limits for pods, function is available here and it's called getPodsTotalRequestsAndLimits收集 pod 的所有请求和限制也是如此,函数在这里可用,它被称为getPodsTotalRequestsAndLimits

Lastly the function what puts all that together can be seen here .最后,可以在此处看到将所有这些组合在一起的功能。

There is a really nice article about Kubernetes API: Allocatable Node Resources?有一篇关于Kubernetes API的非常好的文章:可分配的节点资源? The author is doing exactly what you are asking for but using Python.作者正在按照您的要求做,但使用的是 Python。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM