Monitoring Resource Usage
You'll learn how to use kubectl top and metrics-server to see how much CPU and memory your Pods are actually consuming compared to their requests and limits.
Why Monitor Resource Usage?
You've learned to set CPU and memory requests and limits, but how do you know if those numbers are right? Without monitoring, you're flying blind—Pods might be throttled unnecessarily, or you might be wasting cluster resources. Monitoring actual consumption helps you tune your settings and prevent surprises like OOMKilled containers or CPU throttling.
The metrics-server Component
The metrics-server is a cluster-wide service that collects real-time resource usage data from all nodes. It polls each node's kubelet to gather current CPU and memory consumption, making this data available via the Kubernetes API.
Think of metrics-server as your cluster's fitness tracker—constantly checking the pulse of every Pod and Node.
Using kubectl top
Once metrics-server is installed (many managed clusters include it by default), you can query resource usage:
Check Node resource usage:
kubectl top nodes
Check Pod resource usage:
kubectl top pods
kubectl top pods -n my-namespace
These commands show current CPU (in millicores) and memory (in MiB) consumption—not the requests or limits you configured, but what's actually being used right now.
Comparing Usage to Requests and Limits
After running kubectl top, compare the actual numbers against your Pod's resource specifications. If a Pod consistently uses far less than its requests, you're overprovisioning. If it's hitting or exceeding limits, you may face throttling or OOM kills.
Key Takeaway: kubectl top with metrics-server provides real-time visibility into actual resource consumption, enabling you to validate and adjust your requests and limits based on observed behavior.