When a Kubernetes application has a performance problem, checking the Pod's resource configuration is usually one of the first things worth doing.
A Pod may have enough CPU but not enough memory. A container may be using much more CPU than expected. A request may be too low for accurate scheduling, or a limit may be restricting the workload during a traffic spike.
With Kubernetes 1.37, Pod-level resource configuration makes it even more important to understand the difference between the resources assigned to a Pod and the resources used by individual containers.
The good news is that Kubernetes already provides several commands for inspecting this information.
This article walks through the most useful commands, explains what each one tells you, and shows how to troubleshoot common resource problems.
Understanding Pod Resources First
Before checking resource usage, it helps to separate three concepts:
Resource request
Resource limit
Actual resource usage
They are related, but they are not the same thing.
For example:
resources:
requests:
cpu: "500m"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"
This configuration describes the requested and maximum resources for the workload.
Actual usage can be very different:
CPU request: 500m
CPU limit: 1
Actual CPU: 220m
The application is currently using less CPU than its request and limit.
Understanding this difference prevents a lot of confusion when reading Kubernetes output.
Check Running Pods
The first command to run is:
kubectl get pods
For a specific namespace:
kubectl get pods -n production
You may see output similar to:
NAME READY STATUS RESTARTS AGE
orders-api-6d7f9c7d8b-abc12 2/2 Running 0 2h
orders-api-6d7f9c7d8b-def34 2/2 Running 1 2h
This tells you whether the Pods are running, but it does not show resource usage.
For that, you need additional commands.
Check Pod Resource Requests and Limits
Use:
kubectl describe pod orders-api-6d7f9c7d8b-abc12
The output contains information about the Pod and its containers.
Look for the container sections and their resource configuration.
For a Pod with multiple containers, this is useful because you can see how the resource configuration is distributed.
You can also inspect the complete object:
kubectl get pod orders-api-6d7f9c7d8b-abc12 -o yaml
This is particularly useful when you need to verify exactly what Kubernetes accepted.
Why -o yaml Is Useful
The YAML output lets you inspect the actual Pod specification rather than relying on the configuration file stored locally.
For example:
kubectl get pod orders-api-6d7f9c7d8b-abc12 -o yaml
You can search the output for:
resources
requests
limits
This is useful when a Deployment has been modified several times and you want to confirm what is actually running.
The live Pod specification is the source you should inspect when troubleshooting the running workload.
Check Current Resource Usage
If the cluster has the Kubernetes Metrics API available, you can use:
kubectl top pod
For a specific namespace:
kubectl top pod -n production
Example output:
NAME CPU(cores) MEMORY(bytes)
orders-api-6d7f9c7d8b-abc12 320m 410Mi
orders-api-6d7f9c7d8b-def34 280m 395Mi
This gives you a snapshot of current usage.
It does not replace long-term monitoring.
Resource usage changes over time, so a single kubectl top command cannot tell you what happened during yesterday's traffic spike.
Check Individual Container Usage
A Pod can contain multiple containers.
For example:
orders-api Pod
|
+-- application
|
+-- metrics-agent
You may want to know which container is consuming the CPU.
Depending on the available metrics support, you can use:
kubectl top pod orders-api-6d7f9c7d8b-abc12 --containers
This helps separate the resource usage of the containers inside the Pod.
For example:
POD NAME CPU(cores) MEMORY(bytes)
orders-api-... application 280m 350Mi
orders-api-... metrics-agent 40m 60Mi
Now the resource problem is easier to understand.
The Pod may be using:
CPU: 320m
Memory: 410Mi
but most of the usage comes from the application container.
Check Pod-Level Resource Configuration
When using Pod-level resources, inspect the Pod specification directly.
For example:
kubectl get pod orders-api-6d7f9c7d8b-abc12 -o yaml
Look for the Pod specification's resource configuration.
A simplified configuration may look like:
spec:
resources:
requests:
cpu: "1"
memory: "512Mi"
limits:
cpu: "2"
memory: "1Gi"
This tells you the resource budget defined at the Pod level.
You should also inspect the individual containers because a Pod can contain additional container-level resource configuration.
Pod-Level Resources vs Actual Usage
Consider this configuration:
spec:
resources:
requests:
cpu: "1"
memory: "512Mi"
limits:
cpu: "2"
memory: "1Gi"
Now suppose:
Actual CPU: 650m
Actual memory: 620Mi
The CPU usage is below the configured CPU limit.
Memory usage is also below the configured memory limit.
However, memory is getting closer to the configured maximum.
That is worth monitoring.
A single measurement does not mean the Pod has a memory problem, but a sustained upward trend may require investigation.
Check Resource Usage Across a Namespace
For a quick view:
kubectl top pods -n production
This can help identify Pods using unusually high CPU or memory.
For example:
NAME CPU(cores) MEMORY(bytes)
api-1 100m 250Mi
api-2 120m 260Mi
worker-1 900m 800Mi
worker-2 850m 780Mi
The worker Pods are using considerably more resources than the API Pods.
That does not automatically mean something is wrong.
The worker may simply be doing more work.
The command gives you a starting point for investigation.
Check the Node Running the Pod
Pod resource problems can sometimes be related to node capacity.
First find the node:
kubectl get pod orders-api-6d7f9c7d8b-abc12 -o wide
You may see:
NAME READY STATUS NODE
orders-api 2/2 Running worker-node-01
Then inspect the node:
kubectl describe node worker-node-01
Look at:
Allocatable CPU
Allocatable memory
Requested resources
Resource limits
Conditions
Memory pressure
Disk pressure
This gives you information about the environment hosting the Pod.
Resource Requests and Scheduling
Suppose a Pod specifies:
requests:
cpu: "2"
memory: "1Gi"
Kubernetes needs to find a node capable of satisfying that request.
This is why requests should reflect realistic resource requirements.
If requests are set too high, the scheduler may have difficulty placing Pods even when actual application usage is low.
For example:
Actual usage: 200m CPU
Request: 2 CPU
Join the conversation! Your thoughts help the community grow.