Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Is there any command I can use?

like image 815
injoy Avatar asked Jan 24 '19 22:01

injoy


People also ask

What is 500m CPU in Kubernetes?

For example, 500m CPU represents the roughly same amount of computing power whether that container runs on a single-core, dual-core, or 48-core machine. Note: Kubernetes doesn't allow you to specify CPU resources with a precision finer than 1m .


1 Answers

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.

Note that for kubectl top to work you need to have the metrics-server set up and configured appropriately. (Older clusters use the heapster)

like image 78
Rico Avatar answered Oct 10 '22 22:10

Rico