KEP-3960keps/sig-node/3960-pod-lifecycle-sleep-action
Pod lifecycle sleep action
This KEP proposes the addition of a new sleep action for the PreStop lifecycle hook in Kubernetes, allowing containers to pause for a specified duration before termination. This enhancement aims to provide a more straightforward way to manage graceful shutdowns and improve the overall lifecycle management of containers, and to handle new connections from cli… Full summary
This KEP proposes the addition of a new sleep action for the PreStop lifecycle hook in Kubernetes, allowing containers to pause for a specified duration before termination. This enhancement aims to provide a more straightforward way to manage graceful shutdowns and improve the overall lifecycle management of containers, and to handle new connections from clients that have not yet finished endpoint termination during the pod termination. An example: To use this feature to achieve zero downtime for nginx, we need to deploy a deployment with sleep prestop hook and a service. yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: selector: matchLabels: app: nginx replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.16.1 lifecycle: preStop: sleep: seconds: 5 readinessProbe: httpGet: path: / port: 80 --- apiVersion: v1 kind: Service metadata: name: nginx spec: selector: app: nginx ports: - port: 80 targetPort: 80 - Restart/Update this deployment - A delete pod event is sent to notify the kubelet and the Endpoint Controller (which manages the Service endpoints) simultaneously. - PreStop hook starts, which will delay the shutdown sequence by 5 seconds. During this time, the Endpoint Controller will remove the terminating pod, and the traffic will be sent to other running pods. - When the timeout of 5 seconds ended, the old pod is killed, and new pods will be created. There is no traffic sent to the terminating pod during the update.
Facts
- Authors
- @axezhan
- Approvers
- @mrunalp@sergeykanzhelev
- Reviewers
- @thockin@bobbypage
- Tracking issue
- #3960(opens GitHub in a new tab) closedcompletedclosed 2025-09-19 20:50 UTCmilestone v1.34sig/nodestage/stable
- Milestones
- alpha v1.29beta v1.30stable v1.34
- Participating SIGs
- none
- Feature gates
- PodLifecycleSleepAction
- Created / last updated
- 2023-04-22 / none