<p>I <a href="https://stackoverflow.com/questions/44233242/kubernetes-cluster-and-phoenix-automate-mix-ecto-migrate/44233465#44233465">learned recently</a> that Kubernetes has a feature called <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="noreferrer">Init Containers</a>. Awesome, because I can use this feature to wait for my postgres service and create/migrate the database before my web application service runs.</p>

<p>However, it appears that Init Containers can only be configured in a Pod yaml file. Is there a way I can do this via a Deployment yaml file? Or do I have to choose?</p>

<p>To avoid confusion, ill answer your specific question. i agree with oswin that you may want to consider another method.</p>

<p>Yes, you can use init containers with a deployment. this is an example using the old style (pre 1.6) but it should work </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: 'nginx'
spec:
  replicas: 1
  selector:
    matchLabels:
      app: 'nginx'

  template:
    metadata:
      labels:
        app: 'nginx'
      annotations:
        pod.beta.kubernetes.io/init-containers: '[
            {
                "name": "install",
                "image": "busybox",
                "imagePullPolicy": "IfNotPresent",
                "command": ["wget", "-O", "/application/index.html", "http://kubernetes.io/index.html"],
                "volumeMounts": [
                    {
                      "name": "application",
                      "mountPath": "/application"
                    }
                ]
            }
        ]'
    spec:
      volumes:
        - name: 'application'
          emptyDir: {}

      containers:

      - name: webserver
        image: 'nginx'
        ports:
        - name: http
          containerPort: 80
        volumeMounts:
          - name: 'application'
            mountPath: '/application'
</code></pre>
