<p>I am creating a Replication controller with one init-container. however the init container fails to start and the status of the pod is:</p>

<pre><code>NAME                       READY     STATUS             RESTARTS   AGE
testcontainer   0/1       CrashLoopBackOff   12         37m
</code></pre>

<p>I am not sure what part is failing exactly, and the logs do not help.
My kubectl server version is 1.4 (different from client version) so I am using:</p>

<pre><code>annotations:
        pod.beta.kubernetes.io/init-containers:
</code></pre>

<p>Here is the replication controller yaml file I am using.
I am using the "hello-world" image (instead of the nginx to make it faster)</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: testcontainer
spec:
  replicas: 1
  selector:
    app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        pod.beta.kubernetes.io/init-containers: '[
            {
                "name": "install",
                "image": "hello-world"
            }
        ]'
    spec:
      containers:
      - name: nginx
        image: hello-world
      dnsPolicy: Default
      nodeName: x.x.x.x
</code></pre>

<p>logs from kubectl describe pod:</p>

<pre><code>Warning FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "nginx" with CrashLoopBackOff: "Back-off 5m0s restarting failed container=nginx pod=testcontainer()"

  32m   16s     145     {kubelet x.x.x.x}  spec.containers{nginx}  Warning BackOff Back-off restarting failed docker container
</code></pre>

<p>when I check the logs of both containers (nginx and testcontainer) it shows the output of running the hello-world image, so I guess the image is downloaded and started successfully. Im not sure what fails after that ( I even tried creating a single pod, using the example provided on <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-initialization/#creating-a-pod-that-has-an-init-container" rel="noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-initialization/#creating-a-pod-that-has-an-init-container</a> , but still fails)</p>

greg
<p>I think the problem here isn't the init container. The <code>hello-world</code> image print a text and exits immediately. Since <a href="https://kubernetes.io/docs/api-reference/v1/definitions/#_v1_podspec" rel="nofollow noreferrer"><code>.spec.restartPolicy</code></a> of the pod defaults to <code>Always</code>, it just restarts the pod every time.</p>

<p>The error message might be a bit confusing, but since the pod is intended to run forever it quite makes sense to display an error, even if the exit code is <code>0</code>.</p>

<p>If you want to run a pod only a single time, you should use the <a href="https://kubernetes.io/docs/user-guide/jobs/" rel="nofollow noreferrer">job API</a>.</p>

<hr>

<p>Since you are interested in an example for the init-container, I fixed your example:</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: testcontainer
spec:
  replicas: 1
  selector:
    app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        pod.beta.kubernetes.io/init-containers: '[
            {
                "name": "install",
                "image": "hello-world"
            }
        ]'
    spec:
      containers:
      - name: nginx
        image: nginx # &lt;--- this image shouldn't be a single shot application
      dnsPolicy: Default
      nodeName: x.x.x.x
</code></pre>
