使用kubectl描述节点,我能够获得节点的资源容量(内存、cpu(。我想通过go客户端或kube API(如果可用(获得相同的功能。有人能帮我吗?我使用的是minikube版本:v1.7.2kubectl版本:客户端:GitVersion:"v1.16.3"服务器:GitVersion:"v1.16.2"我正在使用metric服务器访问kubernetes资源。预期结果:资源容量应可通过go程序或kube API 访问
没有任何API调用可以用来获取kubectl describe nodes
,这是因为该命令正在生成所有输出。
Kubectl
检索节点上所有相关的pod(每个没有失败或成功的pod(,并总结它们的所有资源定义。
您可以查看代码,并在此处找到负责生成节点信息的函数。
收集pod的所有请求和限制也是如此,这里有功能,它被称为getPodsTotalRequestsAndLimits
最后,把所有这些放在一起的函数可以在这里看到。
有一篇关于Kubernetes API的非常好的文章:可分配节点资源?作者所做的正是您所要求的,但使用的是Python。
Kubernetes客户端库是您需要查看的库https://kubernetes.io/docs/reference/using-api/client-libraries/#officially-支持的kubernetes客户端库
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