<p>I'm fairly new with helm and I have a few basic questions. I am deploying a RoR application with Helm 3 and I'm using postgresql as the database. I have added the database as a dependency to the application and I'm  using the bitnami postgres helm chart for this purpose. When i deploy my application chart, both the application and the database pods gets deployed. however, the application pods start running before the database pods. The application requires that database should be running in the background before the migrations happen. but as the application starts before the databse, the migrations fails and the database pods crashes due to which the application pods also crashes.</p>
<p>I want my application pods to wait for the database pods to start running. How can i do this using helm?</p>

nimramubashir
<p>You can define <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">initContainer</a> in your chart, which will check database availability (and will wait for it to start). Your application will start only if initContainer exited successfully.</p>
<p>Postgresql has a handy <code>pg_isready</code>utility, used to check if database is ready to accept requests, which can be used just like that:</p>
<pre class="lang-yaml prettyprint-override"><code>      initContainers:
      - name: check-db-ready
        image: postgres:9.6.5
        command: ['sh', '-c', 
          'until pg_isready -h postgres -p 5432; 
          do echo waiting for database; sleep 2; done;']
</code></pre>
<p>In this example initContainer will check service <code>postgres</code> on port 5432 for readiness each 2 seconds, and will successfully terminate when exit code of <code>pg_isready</code> utility will be 0</p>
<p>See this blog post: <a href="https://medium.com/@xcoulon/initializing-containers-in-order-with-kubernetes-18173b9cc222" rel="nofollow noreferrer">https://medium.com/@xcoulon/initializing-containers-in-order-with-kubernetes-18173b9cc222</a></p>
