<p>I have a kubernetes manifest file which has 2 containers. Main container is collecting data at a certain time period and other (logstash) container reading logs for the main container and shipping it to the ELK stack.
Once the main container completed its job, what is the best way to gracefully signal or shutdown the logstash container?</p>

<p>Currently, there is no way to explicitly mark a container as &quot;Sidecar&quot; (though there is a <a href="https://github.com/kubernetes/enhancements/blob/e0fc0e7eab51078b5b7bd0730cf48f550bc91d1e/keps/sig-apps/sidecarcontainers.md" rel="nofollow noreferrer">long-lasting KEP</a> to implement it).</p>
<p>It means that the best you can do is to define <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/" rel="nofollow noreferrer">Container Lifecycle Hook</a> with the command to gracefully shutdown your sidecar container. Something like:</p>
<pre><code>  containers:
  - name: logstash-container
    image: logstash-image
  - name: your-main-container
    image: your-main-container-image
    lifecycle:
      preStop:
        exec:
          command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;gracefully terminate logstash&quot;]done&quot;]
</code></pre>
