# Kubernetes Lifecycle Hooks

\
A [Kubernetes Lifecycle Hook](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/) triggers events to run at different stages of a container's lifecycle. These hooks run scripts or commands before or after a specific event, such as a container being created, started, or stopped. Lifecycle hooks perform tasks like starting services, or initializing, configuring, or verifying containers.

## Implementing Kubernetes Lifecycle Hooks

You can implement Kubernetes Lifecycle Hooks while adding a DuploCloud EKS Service by adding YAML, like the example below, to the **Other Container Config** field.

```yaml
#lifecycle hook sample
lifecycle:
  postStart:
    exec:
      command:
        - /bin/sh
        - '-c'
        - date > /container-started.txt
  preStop:
    exec:
      command:
        - /usr/sbin/nginx
        - '-s'
        - quit
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.duplocloud.com/docs/automation-platform/kubernetes-overview/kubernetes-lifecycle-hooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
