Checking kubernetes pod CPU and memory

2/5/2019

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?

-- aniztar
kubernetes

4 Answers

2/5/2019

you need to deploy heapster or metric server to see the cpu and memory usage of the pods

-- P Ekambaram
Source: StackOverflow

2/5/2019
  1. As described in the docs, you should install metrics-server

  2. 250m means 250 milliCPU, The CPU resource is measured in CPU units, in Kubernetes, is equivalent to:

    • 1 AWS vCPU
    • 1 GCP Core
    • 1 Azure vCore
    • 1 Hyperthread on a bare-metal Intel processor with Hyperthreading

    Fractional values are allowed. A Container that requests 0.5 CPU is guaranteed half as much CPU as a Container that requests 1 CPU. You can use the suffix m to mean milli. For example 100m CPU, 100 milliCPU, and 0.1 CPU are all the same. Precision finer than 1m is not allowed.

    CPU is always requested as an absolute quantity, never as a relative quantity; 0.1 is the same amount of CPU on a single-core, dual-core, or 48-core machine.

  3. No, kubectl top pod podname shows metrics for a given pod, Linux top and free runs inside a Container and report metrics based on Linux system reporting based on the information stored in the virtual filesystem /proc/, they are not aware of the cgroup where it runs.

    There are more details on these links:

-- Diego Mendes
Source: StackOverflow

2/9/2020

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

FYI, this is on v1.16.2

-- Umakant
Source: StackOverflow

2/5/2019

As heapster is deprecated and will not be releasing any future releases, you should go with installing metrics-server

You can install metrics-server in following way:

  1. Clone the metrics-server github repo: git clone https://github.com/kubernetes-incubator/metrics-server.git

Edit the deploy/1.8+/metrics-server-deployment.yaml file and add following section just after command section:

- command:
     - /metrics-server
     - --metric-resolution=30s
     - --kubelet-insecure-tls
     - --kubelet-preferred-address-types=InternalIP
  1. Run the following command: kubectl apply -f deploy/1.8+

It will install all the requirements you need for metrics server.

For more info, please have a look at my following answer:

How to Enable KubeAPI server for HPA Autoscaling Metrics

-- Prafull Ladha
Source: StackOverflow