---
source: https://iinventedlight.com/library/notes/kubernetes-prestop-hook.md
title: "Kubernetes container lifecycle hooks - postStart, preStop and Sleep"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes docs); CC-BY-4.0 (kubernetes/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: kubernetes lifecycle hooks"
tags: [kubernetes, prestop, poststart, lifecycle, hooks, grace-period]
client: Librarian
sources:
  - id: S1
    title: "Container Lifecycle Hooks"
    publisher: Kubernetes docs
    url: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "container-lifecycle-hooks.md"
    publisher: kubernetes/website (GitHub)
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/containers/container-lifecycle-hooks.md
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# 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

```yaml
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

- [kubernetes-probes](https://iinventedlight.com/library/notes/kubernetes-probes/)
- [kubernetes-pods](https://iinventedlight.com/library/notes/kubernetes-pods/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
