Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking kubernetes pod CPU and memory

Tags:

kubernetes

I am trying to see how much memory and CPU is utilized by a kubernetes pod. I ran the following command for this:

kubectl top pod podname --namespace=default 

I am getting the following error:

W0205 15:14:47.248366    2767 top_pod.go:190] Metrics not available for pod default/podname, age: 190h57m1.248339485s error: Metrics not available for pod default/podname, age: 190h57m1.248339485s 
  1. What do I do about this error? Is there any other way to get CPU and memory usage of the pod?
  2. I saw the sample output of this command which shows CPU as 250m. How is this to be interpreted?

  3. Do we get the same output if we enter the pod and run the linux top command?

like image 844
aniztar Avatar asked Feb 05 '19 09:02

aniztar


People also ask

How do you check memory utilization of a pod?

Check Memory Usage of Kubernetes P To check the memory usage in Kubernetes pods, you have to log in to the root user in Ubuntu 20.04 system. After that, you have to launch the command line terminal. You can launch it by using the application search bar or by using the shortcut key of “Ctrl+Alt+T”.

Which tool can be used to measure pod CPU and memory utilization in Kubernetes?

Metrics Server is a cluster-wide aggregator of resource usage data and collects basic metrics like CPU and memory usage for Kubernetes nodes, pods, and containers. It's used by Horizontal Pod Autoscaler and the Kubernetes dashboard itself, and users can access these metrics directly by using the kubectl top command.

How much memory is a pod using?

Both containers are defined with a request for 0.25 CPU and 64MiB (226 bytes) of memory. Each container has a limit of 0.5 CPU and 128MiB of memory. You can say the Pod has a request of 0.5 CPU and 128 MiB of memory, and a limit of 1 CPU and 256MiB of memory.


2 Answers

CHECK WITHOUT METRICS SERVER


If you want to check pods cpu/memory usage without installing any third party tool then you can get memory and cpu usage of pod from cgroup.

  1. Go to pod's exec mode kubectl exec pod_name -- /bin/bash
  2. Go to cd /sys/fs/cgroup/cpu for cpu usage run cat cpuacct.usage
  3. Go to cd /sys/fs/cgroup/memory for memory usage run cat memory.usage_in_bytes

Make Sure you have added the resources section (requests and limits) to deployment so that it can calculate the usage based on cgroup and container will respect the limits set on pod level

NOTE: This usage is in bytes. This can vary upon pod usage and these values changes frequently.

like image 121
Dashrath Mundkar Avatar answered Oct 07 '22 00:10

Dashrath Mundkar


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

FYI, this is on v1.16.2

like image 23
Umakant Avatar answered Oct 06 '22 23:10

Umakant