Sobes.tech
Middle

How to check memory consumption in Linux and Kubernetes?

sobes.tech AI

Answer from AI

In Linux, several commands can be used to check memory usage:

  • free -m — shows total, used, and free memory in megabytes.
  • top or htop — interactive utilities for monitoring processes and their memory consumption.
  • ps aux --sort=-%mem — displays processes sorted by memory usage.
  • smem — provides a more accurate analysis of memory usage considering shared memory.

In Kubernetes, to monitor container and pod memory:

  • kubectl top nodes — shows resource usage at the node level.
  • kubectl top pods — shows resource usage at the pod level.

For more detailed monitoring, systems like Prometheus with cAdvisor exporter are typically used, which collect data on resource consumption by containers.

Example command to view pod memory:

kubectl top pod <pod-name> --namespace=<namespace>

Thus, for quick analysis, built-in commands can be used, and for long-term monitoring, specialized tools are recommended.