Overview

Monitoring memory usage in your Kubernetes cluster helps identify pods and nodes that are consuming excessive resources. This enables proactive actions such as:

  • Optimizing resource allocation
  • Scaling workloads
  • Detecting and mitigating memory leaks

Proactive monitoring ensures cluster stability and reduces the risk of unexpected downtime.

Verifying Pod Memory Usage

Check Memory Usage for All Pods

Run the following command to view memory and CPU usage of all pods:

kubectl top pods

Sample Response:

NAME                         CPU(cores)   MEMORY(bytes)   
nextgen-gw-0                    48m          1375Mi 
nextgen-gw-redis-master-0       14m          11Mi 

  • CPU (cores): The amount of CPU being used by the pod.
  • MEMORY (bytes): The amount of memory being used by the pod.

Check Memory Usage per Container Within Pods

Use the following command to get memory and CPU usage per container within each pod:

kubectl top pods –containers 

Sample Response:

POD                          NAME        CPU(cores)  MEMORY(bytes) 
nextgen-gw-0               nativebridge    0m          5Mi     
nextgen-gw-0               postgres        4m          77Mi        
nextgen-gw-0               vprobe          29m         541Mi        
nextgen-gw-redis-master-0  redis           11m         10Mi 

  • POD: Name of the pod
  • NAME: Name of the container within the pod
  • CPU (cores): CPU usage by the container
  • MEMORY (bytes): Memory usage by the container

Verifying Node Memory Usage

To view the memory and CPU usage across cluster nodes, run:

kubectl top nodes 

Sample Response:

NAME              CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
nextgen-gateway   189m         9%     3969Mi          49% 

  • CPU (cores): CPU usage by the node
  • CPU%: Percentage of CPU capacity in use
  • MEMORY (bytes): Memory usage by the node
  • MEMORY%: Percentage of memory capacity in use