<p>I would like to try Kubernetes' hooks but I didn't find any example how I should do it. As far as I know, with this hooks I can run bash scripts in freshly created containers and prior to terminate them.</p>

<p>I've found just a short <a href="http://kubernetes.io/docs/user-guide/container-environment/" rel="noreferrer">documentation</a> which say this is possible but that's all.</p>

<p>Do somebody have an example or something useful info?</p>

<p>Thanks in advance.</p>

<p>I don't see any examples .yaml files, but <a href="http://kubernetes.io/docs/api-reference/v1/definitions/#_v1_lifecycle" rel="noreferrer">Kubernetes API v1</a> describes the lifecycle events in the same manner. Currently, only PostStart and PreStop are defined and you should be able to use them by adding a lifecycle section to a container in your pod definition. </p>

<p>Based on reading the API definition, something like this should work (disclaimer: I haven't actually tried it myself):</p>

<pre><code>containers:
  - name: lifecycle
    image: busybox
    lifecycle:
      postStart:
        exec:
          command:
            - "touch"
            - "/var/log/lifecycle/post-start"
      preStop:
        httpGet:
          path: "/abort"
          port: 8080
</code></pre>
