Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes -> Memory consumption per namespace

Is there a way to get the memory consumption per namespace on Kubernetes?

like image 462
Leonardo Avatar asked Sep 06 '25 03:09

Leonardo


1 Answers

No need for a ResourceQuota to get this metric. However it is not provided by an ad-hoc kubectl command. We need to compute the sum ourselves.

Here is a one-liner to get total CPU & RAM usage for a given namespace:

kubectl top pods -n <namespace> | awk 'BEGIN {mem=0; cpu=0} {mem += int($3); cpu += int($2);} END {print "Mem
ory: " mem "Mi" "\n" "Cpu: " cpu "m"}'

Example output:

Memory: 717Mi
Cpu: 257m
like image 86
adamency Avatar answered Sep 08 '25 17:09

adamency