<p>I am developing the Kubernetes helm for deploying the Python application. Within python application i have a Database that has to be connected.  </p>

<p>I want to run the Database scripts that would create db, create user, create table or any alter Database column and any sql script. I was thinking this can be run as a initContainer but that it is not recommended way since this will be running every time even when there is no db scripts also to run.</p>

<p>Below is the solution i am looking for: 
Create Kubernetes job to run the scripts which will connect to postgres db and run the scripts from the files. Is there way that in Kunernetes Job to connect to Postgres service and run the sql scripts? </p>

<p>Please suggest any good approach for sql script to be run in kubernetes which we can monitor also with pod.</p>

<p>I would recommend you to simply use the idea of 'postgresql' sub-chart along with your newly developed app helm chart (check <a href="https://hub.helm.sh/charts/stable/postgresql/3.15.0" rel="nofollow noreferrer">here</a> how to use it within the section called "Use of global variables").</p>

<p>It uses the concept of 'initContainers' instead of Job, to let you initialize on startup a user defined schema/configuration of database from the custom *.<a href="https://github.com/helm/charts/blob/db0db9ca1d63be09be88dcadd3c5653582040bd6/stable/postgresql/templates/statefulset.yaml#L202" rel="nofollow noreferrer">sql script</a>.</p>
