我目前已经在我的K8s集群中安装并运行了指标服务器。
利用kubernetes python库,我可以发出以下请求来获取pod指标:
from kubernetes import client
api_client = client.ApiClient()
ret_metrics = api_client.call_api(
'/apis/metrics.k8s.io/v1beta1/namespaces/' + 'default' + '/pods', 'GET',
auth_settings=['BearerToken'], response_type='json', _preload_content=False)
response = ret_metrics[0].data.decode('utf-8')
print('RESP', json.loads(response))在响应中,将列出每个pod的所有容器及其cpu和内存使用情况:
'containers': [{'name': 'elasticsearch', 'usage': {'cpu': '14122272n', 'memory': '826100Ki'}}]}现在我的问题是,如何获得pod本身而不是其容器的这些指标?如果可能的话,我宁愿不必对每个容器的指标进行汇总。有没有办法用metrics-server做到这一点?
发布于 2019-10-16 14:35:07
根据official repository,您可以查询kubelet统计数据端点:
$ curl --insecure https://<node url>:10250/stats/summary这将返回完整pod的统计信息。如果您想查看pod/容器本身的指标,请键入:
$ curl --insecure https://<node url>:10250/{namespace}/{podName}/{uid}/{containerName}让我们来看一个例子:
{ "podRef":
{ "name": "py588590",
"namespace": "myapp",
"uid": "e0056f1a"
},
"startTime": "2019-10-16T03:57:47Z",
"containers":
[
{ "name": "py588590",
"startTime": "2019-10-16T03:57:50Z"
}
]
}这些请求将起作用:
http://localhost:10255/stats/myapp/py588590/e0056f1a/py588590您还可以查找此article。我希望它能对你有所帮助。
https://stackoverflow.com/questions/58403810
复制相似问题