Kubernetes: pod memory usage
• 152 words • 1 min • updated
Problem statement: Given a pod in Kubernetes, check its memory (RAM) usage.
shell
kubectl top pod -n {namespace} {pod name} [--containers]--containers=false:
If present, print usage of containers within a pod.This only works if metrics server is installed (it should be!).
There’s an alternative:
shell
kubectl describe PodMetrics {pod name}It must be PodMetrics. PodMetric does not work (ugh!1):
shell
% kubectl get PodMetric
error: the server doesn't have a resource type "PodMetric"If metrics server is not available for some reason, then one needs to dive into the container:
shell
kubectl exec -it {pod name} -n {namespace} -- /bin/sh…which won’t always work; not every container has /bin/sh. Then read the
contents of /sys/fs/cgroup/memory/memory.usage_in_bytes.
-
Who designed this? Is it so hard to achieve consistency? Both
kubectl get podandkubectl get podswork. Why can’t it be the same withPodMetric? And, no,PodMetricsesdoes not work either. ↩︎