Termination — graceful shutdown of Pods.
1apiVersion: apps/v12kind: Deployment3metadata:4 name: myapp5spec:6 replicas: 37 template:8 spec:9 terminationGracePeriodSeconds: 6010 containers:11 - name: app12 image: myapp:latest13 lifecycle:14 preStop:15 exec:16 command:17 - sh18 - -c19 - |20 # Drain connections21 curl -X POST http://localhost:8080/admin/drain22 sleep 15 # Wait for load balancer to remove23 # Graceful shutdown24 kill -TERM 125 startupProbe:26 httpGet:27 path: /healthz28 port: 808029 failureThreshold: 3030 periodSeconds: 1031 readinessProbe:32 httpGet:33 path: /ready34 port: 808035 initialDelaySeconds: 536 periodSeconds: 1037 livenessProbe:38 httpGet:39 path: /healthz40 port: 808041 initialDelaySeconds: 1542 periodSeconds: 20
1# Check termination behavior2kubectl get pod my-pod -o jsonpath='{.spec.terminationGracePeriodSeconds}'34# Watch termination5kubectl get pods -w6kubectl get events --field-selector reason=Killing78# Force delete (bypass grace period)9kubectl delete pod my-pod --grace-period=0 --force1011# Check preStop hook12kubectl describe pod my-pod | grep -A 5 "preStop"1314# Verify endpoint removal15kubectl get endpoints myapp -w
Termination Sequence:
Best Practices: