<p>I'm pushing my Phoenix app to a Kubernetes cluster for review. I use GitLab to create a service for the web server and another service for a temporary postgres pod.</p>

<p>What I would like to do is automate <code>mix ecto.create</code> and <code>mix ecto.migrate</code>. However, there is a timing issue - there's a short period of time when the postgres server is not ready yet.</p>

<p>I could poll the postgres service in my deployment script before creating the web application service. But is this the most practical method?</p>

<p>Kubernetes has something called <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init containers</a> which may help you.</p>

<p>From the documentation, here is an example of an app container which waits for a dB container.</p>

<pre><code>apiVersion: v1 
kind: Pod 
metadata: 
  name: myapp-pod 
  labels: 
    app: myapp 
spec: 
  containers: 
  - name: myapp-container 
    image: busybox 
    command: ['sh', '-c', 'echo The app is running! &amp;&amp; sleep 3600'] 
  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;'] 
</code></pre>
