Container lifecycle hooks

Kubernetes also provides some hooks within the lifecycle of each container that can be used at setup and teardown time for containers. These are called container lifecycle hooks, and are defined for each container, rather than for the Pod overall. When you want to configure some additional functionality specific to the container when you have multiple containers per Pod, these can be extremely useful.

The two hooks you can define for each container are post-start and pre-stop. The post-start and pre-stop hooks are intended to be invoked at least once, but Kubernetes does not make any guarantees that these hooks will be invoked only once. This means while it is likely rare, the post-start or pre-stop hooks may be ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.