Cloud Intermediate
Kubernetes Pod Lifecycle¶
KubernetesPodLifecycle 3 min read
Pod lifecycle in Kubernetes. Phases, init containers, probes, and graceful shutdown.
Pod Phases¶
- Pending — scheduling, image pull
- Running — at least one container is running
- Succeeded — all containers completed successfully
- Failed — at least one container failed
- Unknown — state cannot be determined
Probes¶
spec:
containers:
- name: app
livenessProbe: # Is the container alive?
httpGet: {path: /healthz, port: 8080}
initialDelaySeconds: 15
periodSeconds: 10
readinessProbe: # Is it ready to accept traffic?
httpGet: {path: /ready, port: 8080}
initialDelaySeconds: 5
startupProbe: # For slow startup
httpGet: {path: /healthz, port: 8080}
failureThreshold: 30
periodSeconds: 10
Graceful Shutdown¶
Kubernetes sends SIGTERM, waits terminationGracePeriodSeconds (default 30s), then SIGKILL.
process.on('SIGTERM', async () => {
console.log('Shutting down...');
server.close();
await db.disconnect();
process.exit(0);
});
Summary¶
Proper probes and graceful shutdown = zero-downtime deployment. Always configure a readiness probe.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.