How can I retrieve the memory utilization of a pod in kubernetes via kubectl?

2/25/2019

Inside a namespace, I have created a pod with its specs consisting of memory limit and memory requests parameters. Once up a and running, I would like to know how can I get the memory utilization of the pod in order to figure out if the memory utilization is within the specified limit or not. "kubectl top" command returns back with a services related error.

-- Vinodh Nagarajaiah
kubernetes
kubernetes-pod

4 Answers

2/9/2020

kubectl top pod <pod-name> -n <fed-name> --containers

FYI, this is on v1.16.2

-- Umakant
Source: StackOverflow

2/27/2019

Instead of building ad-hoc metric snapshots, a much better way is to install and work with 3rd party data collector programs which if managed well gives you a great solution for monitoring systems and a neat Grafana UI (or likewise) you can play with. One of them is Prometheus and which comes highly recommended.

using such PnP systems, you can not only create a robust monitoring pipeline but also the consumption and hence the reaction to the problem is well managed and executed compared to only relying on TOP

-- Raunak Jhawar
Source: StackOverflow

2/26/2019

kubectl top pod POD_NAME --containers

shows metrics for a given pod and its containers. If you want to see graphs of memory and cpu utilization then you can see them through the kubernetes dashboard. A better solution would be to install a metrics server alongwith prometheus and grafana in your cluster. Prometheus will scrap the metrics which can be used by grafana for displaying as graphs. This might be useful.

-- Anshul Prakash
Source: StackOverflow

2/26/2019

You need to install metrics server to get the metrics. Follow the below thread

Error from server (NotFound): podmetrics.metrics.k8s.io "mem-example/memory-demo" not found

-- P Ekambaram
Source: StackOverflow