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
I saw the sample output of this command which shows CPU as 250m. How is this to be interpreted?
Do we get the same output if we enter the pod and run the linux top
command?
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”.
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.
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.
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.
kubectl exec pod_name -- /bin/bash
cd /sys/fs/cgroup/cpu
for cpu usage run cat cpuacct.usage
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.
kubectl top pod <pod-name> -n <fed-name> --containers
FYI, this is on v1.16.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With