Skip to main content
This lab covers Kubernetes resource requests and limits, how to inspect them on a pod, and how to troubleshoot and fix an OOMKilled container by increasing its memory limit. You’ll inspect the rabbit pod’s CPU request, diagnose why the elephant pod is being OOMKilled, and recreate the elephant pod with a higher memory limit. Key concepts: Kubernetes resource requests, resource limits, OOMKilled, kubectl describe, editing and recreating pods, and using kubectl replace --force for pod recreation.

Table of contents

  1. Inspect CPU request for the rabbit pod
  2. Troubleshoot and fix the OOMKilled elephant pod
  3. Cleanup (optional)
    References

1) Inspect CPU request for the rabbit pod

Describe the rabbit pod to view its resource requests and limits:
In the container status, look for the Limits and Requests sections. For example:
Answer: the CPU request for the rabbit pod is 1 CPU. When the lab asks you to remove the rabbit pod, delete it with:
Expected output:

2) Troubleshoot the elephant pod (OOMKilled)

First, list pods to inspect the elephant pod status:
Example output:
Describe the elephant pod to surface the failure reason and resource settings:
Relevant excerpt from the description:
Explanation:
  • The container runs stress --vm 1 --vm-bytes 15M, attempting to allocate roughly 15Mi of memory.
  • The pod’s memory limit is 10Mi, so the container exceeds the limit and is terminated by the OOM killer. The Last State shows OOMKilled.
Task: increase the memory limit for the elephant pod to 20Mi.

Why you can’t edit resource limits on a running pod

Pod specs (including many resource fields) are effectively immutable after creation. You cannot reliably change resource limits on an existing pod in-place — you must update the pod manifest and recreate the pod (or let a controller like a Deployment handle updates).
You cannot change resource limits of an existing pod in-place. Update the pod manifest and recreate the pod (or use a higher-level controller such as a Deployment to manage rolling updates).

Edit the pod manifest and recreate the pod

If you run kubectl edit pod elephant, kubectl opens the current manifest in your editor. Update the container resources block to increase the memory limit to 20Mi. Example manifest:
Because changing a pod’s resource limits requires recreating the pod, an easy approach is:
  1. Save the edited YAML (kubectl may save it to a temp file like /tmp/kubectl-edit-XXXXX.yaml).
  2. Replace the pod by forcing a replacement (this deletes and recreates the pod using the updated manifest):
Example output:
Verify the pod is running:
Example output:
Confirm the updated memory limit with:
You should see the resource section updated:
Using kubectl replace --force deletes the existing pod immediately and recreates it. This causes a brief downtime for that pod. Prefer using a Deployment for controlled rolling updates if you need zero-downtime updates.

3) Cleanup (optional)

If instructed to remove the elephant pod after verification:
Expected output:

Quick reference — useful commands



You have now inspected CPU requests, diagnosed an OOMKilled pod, updated the pod memory limit to 20Mi by recreating the pod, and verified the change.

Watch Video