Q: What is the purpose of `terminationGracePeriodSeconds`?
When a pod is deleted, Kubernetes sends SIGTERM to the container and waits terminationGracePeriodSeconds (default: 30s) for the app to sh...
#Kubernetes #Advanced Scenarios #L2 #Container Orchestration #K8s
🎙️ Candidate Opening & Architectural Context
""When troubleshooting Kubernetes, I always follow a structured layered model: Pod status -> Events -> Logs -> Network. When addressing this question, I walk the interviewer through our production incident runbook: isolating the blast radius, checking diagnostic logs and metrics, and applying a safe fix.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Initial Diagnostics & Root Cause Analysis
When a pod is deleted, Kubernetes sends SIGTERM to the container and waits terminationGracePeriodSeconds (default: 30s) for the app to shut down gracefully. After the grace period, SIGKILL is sent.
- Your app should handle
SIGTERMby finishing in-flight requests and closing connections before exiting. - If your app needs more than 30s to drain (e.g., it's processing long jobs), increase the grace period.
- If
preStophook is defined, it runs before SIGTERM and counts against the grace period.
2️⃣
Remediation & Permanent Safeguards
Why it matters: For web servers: graceful shutdown means finishing current HTTP requests. For consumers: finish processing the current message before stopping.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Your app should handle SIGTERM by finishing in-flight requests and closing connections before exiting.."
⚡ 60-Second Elevator Pitch Talking Points
- Your app should handle SIGTERM by finishing in-flight requests and closing connections before exi...
- If your app needs more than 30s to drain (e.g., it's processing long jobs), increase the grace pe...
- If preStop hook is defined, it runs before SIGTERM and counts against the grace period.
Advertisement