https://drive.google.com/file/d/1l0bQJNRRjrxzuIn0dwAb4AMbM67MIgrp/view?usp=sharing

πŸ” YAML Breakdown

apiVersion: v1
kind: Pod
metadata:
  name: nnappone
  namespace: learning
  labels:
    app: nnappone
spec:
  containers:
    - name: crackone-app
      image: lovelearnlinux/stress:latest     # ← Special image with `stress` tool
      resources:
        requests:
          memory: "150Mi"   # Scheduler reserves 150Mi
        limits:
          memory: "250Mi"   # Hard ceiling = 250Mi
      command: ["stress"]
      args: ["--vm", "1", "--vm-bytes", "275M", "--vm-hang", "1"]

πŸ’₯ What the stress command does:

⚠️ Conflict:

Pod tries to use 275 MB > limit = 250 MiB β†’ Killed by OOM Killer!

πŸ” Note: 275M (Megabytes = 1000Β²) β‰ˆ 262 MiB (Mebibytes = 1024Β²) β†’ still > 250 MiB


πŸ“Œ What Happens at Runtime?

Phase What Occurs
1. Scheduling βœ… Success! Node has β‰₯150Mi free β†’ Pod starts
2. Container Runs stress allocates memory β†’ reaches ~262 MiB
3. Memory > 250MiB Container Runtime (containerd/docker) triggers OOM Killer
4. Pod Status Changes to OOMKilled β†’ restarts (if restartPolicy: Always)
5. Event Logged Exit Code 137 = 128 + 9 β†’ signal SIGKILL

πŸ’‘ Key Difference from CPU:


πŸ§ͺ Lab: Trigger & Diagnose OOMKilled

πŸ”§ Steps

# 1. Create namespace
kubectl create namespace learning

# 2. Apply the Pod
kubectl apply -f pod-with-memory-exceed.yml

# 3. Watch it crash
kubectl get pods -n learning -w

# βœ… You’ll see:
# nnappone   0/1   OOMKilled   1 (or more)   10s

# 4. Describe Pod β†’ look for OOM event
kubectl describe pod nnappone -n learning

# πŸ” Critical lines in "Events":
#   Last State:     Terminated
#     Reason:       OOMKilled
#     Exit Code:    137
#     ...
#   Restart Count:  2+

# 5. Check logs (may be empty if killed instantly)
kubectl logs nnappone -n learning --previous

# 6. Clean up
kubectl delete pod nnappone -n learning
kubectl delete namespace learning


πŸ” Understanding Exit Code 137

Signal Meaning
SIGKILL (9) Force-kill process (can’t be caught/ignored)
Exit Code = 128 + 9 = 137 Standard way to indicate killed by SIGKILL

βœ… In Kubernetes:

Exit Code 137 + Reason: OOMKilled = memory limit exceeded


πŸ› οΈ How to Fix It?