0
0
Kubernetesdevops~10 mins

OOMKilled containers in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - OOMKilled containers
Container starts running
Container uses memory
Memory usage > limit?
NoContinue running
Yes
Kernel kills container (OOMKilled)
Container status set to OOMKilled
Pod restarts or fails
This flow shows how a container runs, uses memory, and if it exceeds its memory limit, the system kills it with OOMKilled status.
Execution Sample
Kubernetes
kubectl get pods
kubectl describe pod mypod
kubectl logs mypod
kubectl get events
Commands to check pod status, details, logs, and events to diagnose OOMKilled containers.
Process Table
StepActionMemory Usage (MiB)Memory Limit (MiB)ResultContainer Status
1Container starts0100RunningRunning
2Memory usage rises50100RunningRunning
3Memory usage rises90100RunningRunning
4Memory usage rises110100Exceeded limitOOMKilled
5Kernel kills containerN/A100Container killedOOMKilled
6Pod restarts or failsN/A100Restarting or FailedRunning
💡 Container memory usage exceeded limit, kernel killed container with OOMKilled status.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Memory Usage (MiB)05090110N/A
Container StatusRunningRunningRunningOOMKilledRunning
Key Moments - 3 Insights
Why does the container status change to OOMKilled even though the pod is still listed?
The container is killed by the system because it used more memory than allowed. The pod still exists but the container inside it has stopped with OOMKilled status, as shown in step 4 and 5 of the execution table.
What does 'Memory Limit' mean and why is it important?
Memory Limit is the maximum memory the container can use. If the container uses more than this, the system kills it to protect other containers. This is why in step 4, exceeding 100 MiB causes OOMKilled.
Can the pod restart automatically after OOMKilled?
Yes, depending on the pod's restart policy, it may restart the container after OOMKilled, as shown in step 6. But if it keeps exceeding memory, it may keep failing.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the container status at step 3?
APending
BRunning
COOMKilled
DFailed
💡 Hint
Check the 'Container Status' column at step 3 in the execution table.
At which step does the container exceed its memory limit?
AStep 4
BStep 2
CStep 3
DStep 5
💡 Hint
Look at the 'Memory Usage' and 'Memory Limit' columns to find when usage surpasses limit.
If the memory limit was increased to 120 MiB, what would change in the execution table?
AContainer would be killed at step 3
BContainer would be OOMKilled at step 4
CContainer would continue running past step 4
DNo change in container status
💡 Hint
Compare memory usage at step 4 (110 MiB) with new limit 120 MiB.
Concept Snapshot
OOMKilled containers happen when a container uses more memory than its limit.
The system kills the container to protect others.
Check pod status with 'kubectl describe pod' and events.
Adjust memory limits to prevent OOMKilled.
Pod may restart depending on restart policy.
Full Transcript
When a container runs in Kubernetes, it has a memory limit set. As it uses memory, if it stays below the limit, it runs fine. But if it uses more memory than allowed, the system kills it to protect other containers. This kill is called OOMKilled. You can see this status by describing the pod or checking events. The pod may restart the container depending on its restart policy. To avoid OOMKilled, increase memory limits or optimize container memory use.