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
- Inspect CPU request for the
rabbitpod - Troubleshoot and fix the OOMKilled
elephantpod - Cleanup (optional)
References
1) Inspect CPU request for the rabbit pod
Describe the rabbit pod to view its resource requests and limits:
Limits and Requests sections. For example:
rabbit pod is 1 CPU.
When the lab asks you to remove the rabbit pod, delete it with:
2) Troubleshoot the elephant pod (OOMKilled)
First, list pods to inspect the elephant pod status:
elephant pod to surface the failure reason and resource settings:
- 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. TheLast StateshowsOOMKilled.
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 runkubectl 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:
- Save the edited YAML (kubectl may save it to a temp file like
/tmp/kubectl-edit-XXXXX.yaml). - Replace the pod by forcing a replacement (this deletes and recreates the pod using the updated manifest):
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 theelephant pod after verification:
Quick reference — useful commands
Links and references
- Kubernetes: Configure CPU and memory for containers
- Kubernetes: Pods are ephemeral — updating pods
- kubectl reference
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.