Skip to content

Common commands for finding pods with high resource use

Primary commands used to identify pods consuming excessive resources.

To effectively troubleshoot high resource use, you must distinguish between live usage (what the pod is consuming right now) and resource reservations (what the pod has requested from the scheduler).

1. Monitoring Live Usage (kubectl top)

The standard method for checking real-time resource consumption is kubectl top. This command queries the Metrics API (served by the Metrics Server add-on) to retrieve CPU and memory usage data,.

Basic usage: To view the resource usage of pods in the default namespace:

bash
kubectl top pods

This displays the current CPU (in cores/millicores) and Memory (in bytes) consumption.

Sorting by resource consumption: To quickly identify the heaviest consumers, you can sort the output. This is essential in namespaces with many pods.

bash
# Find the pods using the most CPU
kubectl top pods --sort-by=cpu

# Find the pods using the most Memory
kubectl top pods --sort-by=memory

Drilling down to containers: If a pod contains multiple containers (e.g., a service mesh sidecar or a log forwarder), the pod-level metric might hide which specific container is the culprit. You can inspect individual containers within a specific pod:

bash
kubectl top pod <pod-name> --containers

Note: This command requires the Metrics Server to be installed and running in your cluster.

Checking Swap Usage: If your nodes and kubelet are configured to allow swap memory, you can view swap usage statistics to see if a pod is utilizing swap space:

bash
kubectl top pods --show-swap

This outputs a SWAP(bytes) column alongside CPU and Memory.

2. Auditing Resource Allocations (kubectl describe)

Sometimes "high resource use" isn't about active consumption, but about requests blocking other pods from scheduling. A pod requesting 10GB of RAM blocks that capacity even if it is currently using only 100MB.

To find pods that are reserving high amounts of resources on a specific node:

bash
kubectl describe node <node-name>

Look for the "Non-terminated Pods" section in the output. It lists every pod on that node along with its CPU and Memory Requests and Limits, and the percentage of the node's total capacity they consume,.

Example Output Analysis:

text
Non-terminated Pods:
  Namespace    Name           CPU Requests  CPU Limits  Memory Requests  Memory Limits
  ---------    ----           ------------  ----------  ---------------  -------------
  default      high-req-pod   500m (25%)    500m (25%)  128Mi (6%)       128Mi (6%)

This allows you to identify pods that are "greedy" with their reservations, potentially causing cluster inefficiency.

3. Advanced Filtering with JSONPath

If you need to audit all pods across the entire cluster to find those with specific limit configurations (e.g., finding all pods with a memory limit greater than 1Gi), you can use kubectl get with custom formatting.

List pods with their resource limits:

bash
kubectl get pods --all-namespaces -o custom-columns="POD:.metadata.name,NAMESPACE:.metadata.namespace,CPU_LIMIT:.spec.containers[*].resources.limits.cpu,MEM_LIMIT:.spec.containers[*].resources.limits.memory"

This provides a static view of the configuration (limits) rather than live usage, which is critical for capacity planning audits.

Summary of Commands

GoalCommandData Source
Find active CPU hogskubectl top pods --sort-by=cpuMetrics API
Find active Memory hogskubectl top pods --sort-by=memoryMetrics API
Inspect specific pod usagekubectl top pod <name> --containersMetrics API
Check Swap usagekubectl top pods --show-swapKubelet/Summary API
Find high Reservationskubectl describe node <node-name>API Server / Scheduler