Pod Lifecycle — phases: Pending → Running → Succeeded/Failed.
Graceful Shutdown (preStop hook + terminationGracePeriodSeconds):
1apiVersion: apps/v12kind: Deployment3metadata:4 name: myapp5spec:6 template:7 spec:8 terminationGracePeriodSeconds: 609 containers:10 - name: myapp11 image: myapp:latest12 lifecycle:13 preStop:14 exec:15 command: ["/bin/sh", "-c", "sleep 15"]16 ports:17 - containerPort: 808018 readinessProbe:19 httpGet:20 path: /health21 port: 808022 initialDelaySeconds: 523 periodSeconds: 10
Shutdown order:
Graceful shutdown example in Node.js:
1const server = app.listen(8080);23const shutdown = () => {4 console.log("SIGTERM received, shutting down gracefully");5 server.close(() => {6 db.disconnect();7 process.exit(0);8 });910 setTimeout(() => {11 process.exit(1);12 }, 30000);13};1415process.on("SIGTERM", shutdown);16process.on("SIGINT", shutdown);
PDB (Pod Disruption Budget): Guarantees minimum available during voluntary disruptions.
Pod Conditions: PodScheduled, Initialized, ContainersReady, Ready.