Kubernetes OOMKilled
A container was killed by Kubernetes because it exceeded its memory limit.
Explanation
OOMKilled (Out of Memory Killed) occurs when a Kubernetes container exceeds its configured memory limit and the kernel kills the process to protect the system. Kubernetes sets memory limits per container and monitors consumption. When a container uses more memory than allowed, it's immediately terminated with an OOMKilled exit code (137). Common causes include memory leaks, insufficient memory limits for the workload, Java/Node.js applications not respecting container memory limits, and traffic spikes causing memory surges.
Common Causes
- Memory limit too low for workload
- Memory leak in application
- Java/Node.js not respecting container limits
- Traffic spike causing memory surge
- Unbounded caching or data processing
Solution
Check the container's memory usage and limits: kubectl top pod and review resource limits in the deployment YAML. Increase memory limits if the workload legitimately needs more: resources.limits.memory. Fix memory leaks in the application code. Configure Java to respect container memory: -XX:MaxRAMPercentage=75.0. Set Node.js --max-old-space-size to 75% of container limit. Use Horizontal Pod Autoscaler to scale based on memory usage. Implement memory profiling to identify leaks. Check for OOMKilled in pod events: kubectl describe pod pod-name.
Code Example
# Check pod status and OOMKilled
kubectl get pods
kubectl describe pod myapp-pod-xyz
# Look for: Last State: Terminated, Reason: OOMKilled
# Check current memory usage
kubectl top pod myapp-pod-xyz
# Increase memory limits in deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
template:
spec:
containers:
- name: myapp
resources:
limits:
memory: "512Mi" # increase this
requests:
memory: "256Mi"
# Java: respect container memory limits
# -XX:MaxRAMPercentage=75.0
# -XX:+UseContainerSupport
# Node.js: set memory limit
# node --max-old-space-size=384 app.js (75% of 512Mi)
# Monitor OOM events
kubectl get events --field-selector reason=OOMKilling
# Horizontal scaling based on memory
kubectl autoscale deployment myapp --cpu-percent=80 --min=2 --max=10
Error Information
Language
bash
Framework
kubernetes
Difficulty
Intermediate
Views
15
Related Errors
DevOps
Terraform State Locked
Another Terraform operation is already running and has locked the state file.
DevOps
Laravel Schedule Task Failure
A scheduled task failed to execute or completed with errors.
ENOTFOUND
DevOps
Node.js ENOTFOUND
DNS lookup failed because the hostname could not be resolved.
DevOps
Container Name Already in Use
A Docker container with the specified name already exists.