我已经在VIM中安装了minikube,并且拥有具有所有特权的服务帐户令牌。有没有来自kubernetes的API来获取资源使用情况(总体)。
要获取CPU和内存使用率,可以使用以下内容(取决于您喜欢的对象):
kubectl top pods
或kubectl top nodes
会告诉你
$ kubectl top pods
NAME CPU(cores) MEMORY(bytes)
nginx-1-5d4f8f66d9-xmhnh 0m 1Mi
api参考可能如下所示:
$ curl http://localhost:8080/apis/metrics.k8s.io/v1beta1/pods
...
{
"metadata": {
"name": "nginx-1-5d4f8f66d9-xmhnh",
"namespace": "default",
"selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods/nginx-1-5d4f8f66d9-xmhnh",
"creationTimestamp": "2019-07-29T11:48:13Z"
},
"timestamp": "2019-07-29T11:48:11Z",
"window": "30s",
"containers": [
{
"name": "nginx",
"usage": {
"cpu": "0",
"memory": "1952Ki"
}
}
]
}
...
至于API,几乎没有访问它的方法。
您可以通过运行使用代理kubectl proxy --port:8080 &
以下命令以充当反向代理的模式运行kubectl。它负责定位API服务器并进行身份验证。
有关更多详细信息,请参见kubectl代理。
然后,您可以使用curl,wget或浏览器浏览API,如下所示:
curl http://localhost:8080/api/
通过将身份验证令牌直接传递到API服务器,可以避免使用kubectl代理,如下所示:
使用
grep/cut
方法:
# Check all possible clusters, as you .KUBECONFIG may have multiple contexts:
kubectl config view -o jsonpath='{"Cluster name\tServer\n"}{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}'
# Select name of cluster you want to interact with from above output:
export CLUSTER_NAME="some_server_name"
# Point to the API server refering the cluster name
APISERVER=$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$CLUSTER_NAME\")].cluster.server}")
# Gets the token value
TOKEN=$(kubectl get secrets -o jsonpath="{.items[?(@.metadata.annotations['kubernetes\.io/service-account\.name']=='default')].data.token}"|base64 -d)
# Explore the API with TOKEN
curl -X GET $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句