<p>I am following documentation example at <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use</a></p>

<p>I created following pod:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  initContainers:
    - name: init-myservice
      image: busybox
      command:
        [
          "sh",
          "-c",
          "until nslookup myservice; do echo waiting for myservice; sleep 2; done;",
        ]
    - name: init-mydb
      image: busybox
      command:
        [
          "sh",
          "-c",
          "until nslookup mydb; do echo waiting for mydb; sleep 2; done;",
        ]
  containers:
    - name: myapp-container
      image: busybox
      command: ["sh", "-c", "echo The app is running! &amp;&amp; sleep 3600"]
</code></pre>

<p>but I did not create the services yet (<code>myservice, mydb</code>).</p>

<p>My expectation is for deployment to <strong>hold until I create services</strong>, but it just continues with deployment and creates the pod called "<code>myapp-pod</code>".</p>

<p>Am I missing something on this run?<br>
Why it does not hold until I create the services?</p>

<p>This happens because you are using <code>ash</code> inside busybox and it has different behavior (not same as bash). So your script actually ends there.</p>

<p>You can try it inside busybox yourself:</p>

<pre><code>kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
</code></pre>

<p>And then use your command:</p>

<pre><code>until nslookup myservice; do echo waiting for myservice; sleep 2; done;
</code></pre>

<p>To fix this issue you can try something different, for example <strong>alpine</strong>.</p>

<pre><code>kubectl run -i --tty alpine --image=alpine --restart=Never -- sh
</code></pre>
