Kubernetes container lifecycle hooks - postStart, preStop and Sleep
Answer: A container can run code through the lifecycle hook framework, triggered by events in the container's management lifecycle. The PreStop hook is called immediately before a container is terminated, and PostStart is executed immediately after a container is created.
Example
apiVersion: v1
kind: Pod
metadata:
name: hook-demo
spec:
terminationGracePeriodSeconds: 30
containers:
- name: app
image: example/app
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo warmed > /tmp/ready"]
preStop:
sleep:
seconds: 5
Hook types
| Handler | Behavior | |---|---| | exec | run a command inside the container | | httpGet | HTTP request to an endpoint on the Container | | sleep | pause for a specified duration |
Rules
- PreStop runs immediately before a container is terminated, whether from an API request or a management event.
- The grace period covers the time for the PreStop hook to run and for the Container to stop.
See also
Claims
- id: C1 claim: Sleep pauses the container for a specified duration. source: S1 evidence: "Pauses the container for a specified duration"
- id: C2 claim: PreStop runs immediately before termination. source: S1 evidence: "This hook is called immediately before a container is terminated"
- id: C3 claim: PostStart runs immediately after the container is created. source: S2 evidence: "This hook is executed immediately after a container is"
Sources
- [S1] Container Lifecycle Hooks. Kubernetes docs. https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/ . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] container-lifecycle-hooks.md. kubernetes/website (GitHub). https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/containers/container-lifecycle-hooks.md . License: CC-BY-4.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Container Lifecycle Hooks; kubernetes/website (GitHub), container-lifecycle-hooks.md. CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Container Lifecycle Hooks; kubernetes/website (GitHub), container-lifecycle-hooks.md. CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors.
Cite this
iinventedlight. 2026. "Kubernetes container lifecycle hooks - postStart, preStop and Sleep." iinventedlight Library, iil:note:k9xz9wmk, version of 2026-11-18. https://iinventedlight.com/library/notes/kubernetes-prestop-hook/. License: CC-BY-4.0.
@misc{iil_note_k9xz9wmk,
author = {{iinventedlight}},
title = {{Kubernetes container lifecycle hooks - postStart, preStop and Sleep}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/kubernetes-prestop-hook/},
note = {Permanent ID iil:note:k9xz9wmk. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kubernetes-prestop-hook.md.