Monitoring memory usage allows you to identify pods and nodes that are consuming excessive resources. By doing so, you can take corrective actions, such as optimizing the resource allocation, scaling your applications, or troubleshooting potential memory leaks. This proactive approach helps ensure that your Kubernetes cluster runs efficiently and avoids unexpected downtimes.

This guide provides instructions on how to monitor memory usage in Kubernetes pods and nodes using the kubectl top command. Make sure that the metrics server is enabled in your Kubernetes cluster.

Verifying Pod Memory Usage

Command to Check Pod Memory Usage

kubectl top pods

Example Output:

NAME           CPU(cores)   MEMORY(bytes)  
nextgen-gw-0   48m          1375Mi

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

Verifying Node Memory Usage

Command to Check Node Memory Usage

kubectl top nodes

Example Output:

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

  • CPU (cores): The amount of CPU being used by the node.
  • CPU%: The percentage of CPU capacity being utilized by the node.
  • MEMORY (bytes): The amount of memory being used by the node.
  • MEMORY%: The percentage of memory capacity being utilized by the node.