简体   繁体   English

如何在k8s中转储每个命名空间的资源(CPU,内存)使用情况?

[英]How to dump the resource (CPU, memory) usage per namespace in k8s?

I have a list of namespaces created under the same k8s cluster and I'd like to find out the resource (CPU, memory) usage per namespace. 我有一个在同一个k8s集群下创建的命名空间列表,我想找出每个命名空间的资源(CPU,内存)使用情况。 Is there any command I can use? 我可以使用任何命令吗?

Yes. 是。 You can use 您可以使用

$ kubectl -n <nampespace> top pod

For example: 例如:

$ kubectl top pod -n kube-system
NAME                                                                 CPU(cores)   MEMORY(bytes)
calico-node-xxxxx                                                    17m          166Mi
coredns-xxxxxxxxxx-xxxxx                                             2m           11Mi
coredns-xxxxxxxxxx-xxxxx                                             3m           11Mi
etcd-ip-x-x-x-x.us-west-2.compute.internal                           19m          149Mi
kube-apiserver-ip-x-x-x-x.us-west-2.compute.internal                 39m          754Mi
kube-controller-manager-ip-x-x-x-x.us-west-2.compute.internal        20m          138Mi
kube-proxy-xxxxx                                                     5m           12Mi
kube-scheduler-ip-x-x-x-x.us-west-2.compute.internal                 6m           17Mi
metrics-server-xxxxxxxxxx-xxxxx                                      0m           15Mi

You need to add up all the entries on the CPU and MEMORY columns if you want the total. 如果需要总计,则需要在CPU和MEMORY列上添加所有条目。

Note that for kubectl top to work you need to have the metrics-server set up and configured appropriately. 请注意, kubectl top工作,您需要设置和配置适当的metrics-server (Older clusters use the heapster ) (较旧的群集使用heapster

Thanks Rico, the answer is good but just as an addition: 谢谢Rico,答案很好但只是作为补充:

You can specify resource quotas and then view them as specified here . 您可以指定资源配额,然后按照此处的指定查看它们。 Other than that, there are external monitoring tools like Prometheus. 除此之外,还有像普罗米修斯这样的外部监测工具。 Also, there is a Resource Explorer which can: 此外,还有一个资源浏览器 ,它可以:

Display historical statistical resource usage from StackDriver. 显示StackDriver的历史统计资源使用情况。

https://github.com/kubernetes/kubernetes/issues/55046 https://github.com/kubernetes/kubernetes/issues/55046

List resource QoS allocation to pods in a cluster. 列出群集中pod的资源QoS分配。 Inspired by: 灵感来自:

https://github.com/kubernetes/kubernetes/issues/1751 https://github.com/kubernetes/kubernetes/issues/1751

The case is still open on GitHub , but it seems there should be some changes eventually as one of the contributors states there is a plan to remove kubectl top and using some native solutions so I advise to follow this thread. 这个案例在GitHub上仍然是开放的,但似乎最终应该有一些变化,因为其中一个贡献者指出有一个计划要删除kubectl top并使用一些原生解决方案,所以我建议遵循这个主题。

Write a shell script to get all namespaces in the cluster. 编写shell脚本以获取集群中的所有名称空间。 Iterate through each namespace. 遍历每个命名空间。 Run kubectl top pod. 运行kubectl top pod。 Add up the cpu and memory of all pods in the name space. 在名称空间中添加所有pod的cpu和内存。

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

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