<p>I have several containers in my pod which are executing specific tasks. Two of the containers act as daemons and if they fail they should be restarted. On the other side, the 3 other containers are meant to execute specific tasks only once.</p>
<p>My intuitive approach was to make them explicitly quit with <code>exit 0</code> but this doesn't seem to prevent them to restart and do the job again and again. How should I proceed?</p>

Hai Nguyen Van
<p><strong>solution #1</strong></p>
<p>Assuming you are using some sort of package manager for k8s deployment. You can use similar feature like helm hooks <a href="https://helm.sh/docs/topics/charts_hooks/" rel="nofollow noreferrer">https://helm.sh/docs/topics/charts_hooks/</a> to execute specific tasks at specific lifecycle of pods.</p>
<p><strong>solution #2</strong></p>
<p>You can configure <strong>restartPolicy</strong> for those containers to <strong>Never</strong> as explained here
<a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy</a></p>
<p><strong>solution #3</strong></p>
<p>Depending on your requirement, you can also use lifecycle handlers of a POD as explained here to execute jobs:</p>
<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/</a></p>
