Reputation: 11387
Is there a way to get the memory consumption per namespace on Kubernetes?
Upvotes: 4
Views: 4707
Reputation: 1500
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
Upvotes: 3
Reputation: 1405
It's possible creating a resourcequota object like this:
apiVersion: v1
kind: ResourceQuota
metadata:
name: mem-cpu-demo
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi
However there are some pre requisites in order to check the pods consumption:
Pod example template
apiVersion: v1
kind: Pod
metadata:
name: quota-mem-cpu-demo
spec:
containers:
- name: quota-mem-cpu-demo-ctr
image: nginx
resources:
limits:
memory: "800Mi"
cpu: "800m"
requests:
memory: "600Mi"
cpu: "400m"
To check the resource consumption use the following command:
kubectl --context <cluster_context> describe resourcequota -n my-namespace
Source: https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/
Upvotes: 0
Reputation: 3551
On high level we can get this from kubectl
$ kubectl describe resourcequota -n my-namespace
Name: compute-resources
Namespace: default
Resource Used Hard
-------- ---- ----
limits.cpu 12 48
limits.memory 1024M 120Gi
requests.cpu 250m 24
requests.memory 512M 60Gi
Note : will work only if your create resourcequota.
Upvotes: 3