<p>I have in my application a shell that I need to execute once the container is started and that it remains in the background, I have seen using lifecycle but it does not work for me</p>
<pre><code> ports:
    - name: php-port
      containerPort: 9000
    lifecycle:
        postStart:
          exec:
            command: [&quot;/bin/sh&quot;, &quot;sh /root/script.sh&quot;]
</code></pre>
<p>I need an artisan execution to stay in the background once the container is started</p>

mastermilan
<p>When the lifecycle hooks (e.g. <code>postStart</code>) do not work for you, you could add another container to your pod, which runs parallel to your main container (<a href="https://medium.com/bb-tutorials-and-thoughts/kubernetes-learn-sidecar-container-pattern-6d8c21f873d" rel="nofollow noreferrer">sidecar pattern</a>):</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: foo
spec:
  containers:
  - name: main
    image: some/image
    ...
  - name: sidecar
    image: another/container
</code></pre>
<p>If your 2nd container should only start <strong>after</strong> your main container started successfully, you need some kind of notification. This could be for example that the main container creates a file on a shared volume (e.g. an empty dir) for which the 2nd container waits until it starts it's main process. The <a href="https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/#creating-a-pod-that-runs-two-containers" rel="nofollow noreferrer">docs</a> have an example about a shared volume for two containers in the same pod. This obviously requires to add some additional logic to the main container.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: foo
spec:
  volumes:
  - name: shared-data
    emptyDir: {}
  containers:
  - name: main
    image: some/image
    volumeMounts:
    - name: shared-data
      mountPath: /some/path
  - name: sidecar
    image: another/image
    volumeMounts:
    - name: shared-data
      mountPath: /trigger
    command: [&quot;/bin/bash&quot;]
    args: [&quot;-c&quot;, &quot;while [ ! -f /trigger/triggerfile ]; do sleep 1; done; ./your/2nd-app&quot;]
</code></pre>
