<p>I have a service which runs in apache. The container status is showing as completed and restarting. Why container is not maintaining its state as running even though the arguments passed does not have issues?</p>

<pre><code>apiVersion: apps/v1
kind: Deployment

metadata:
  name: ***
spec:
  selector:
    matchLabels:
      app: ***
  replicas: 1
  template:
    metadata:
      labels:
        app: ***
    spec:
      containers:
      - name: ***
        image: ****
        command: ["/bin/sh", "-c"]
        args: ["echo\ sid\ |\ sudo\ -S\ service\ mysql\ start\ &amp;&amp;\ sudo\ service\ apache2\ start"]
        volumeMounts:
        - mountPath: /var/log/apache2/
          name: apache
        - mountPath: /var/log/***/
          name: ***
      imagePullSecrets:
      - name: regcred
      volumes:
      - name: apache
        hostPath:
          path: "/home/sandeep/logs/apache"
      - name: vusmartmaps
        hostPath:
          path: "/home/sandeep/logs/***"
</code></pre>

<p>Soon after executing this arguments it is showing its status as completed and going to a loop. What we can do to maintain it status as running.</p>

sandeep P
<p>You want to start apache and mysql in the same container and keep it running, aren't you?</p>

<p>Well, lets break down why it exits first. Kubernetes, just like Docker, will run whatever command you would give inside the container. If that command finishes, container would stop. <code>echo sid | sudo -S service mysql start &amp;&amp; sudo service apache2 start</code> will ask your init process to start both mysql and apache, but the thing is that Kubernetes is not aware of your init inside the container.</p>

<p>In fact, the <code>command</code> statement will become instead of init process with pid 1, overriding whatever default startup command you have in your container image. Whenever process with pid 1 exits, container stops.
Therefore in your case you have to start whatever init system you have in your container.</p>

<p>However we come closer to another problem - Kubernetes already acts as init system. It starts your pods and supervises them. Therefore all you need is to start two containers instead - one for mysql and another one for apache.</p>

<p>For example you could use official dockerhub images from <a href="https://hub.docker.com/_/httpd/" rel="nofollow noreferrer">https://hub.docker.com/<em>/httpd/</a> and <a href="https://hub.docker.com/_/mysql" rel="nofollow noreferrer">https://hub.docker.com/</em>/mysql</a>. They already come with both services configured to startup correctly, therefore you don't even have to specify <code>command</code> and <code>args</code> in your deployment manifest.</p>
