Kubernetes helm for creating DB scripts for Database Conatiner

10/18/2019

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

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.

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?

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

-- Pandit Biradar
kubernetes
kubernetes-helm
kubernetes-jobs
postgresql
python-3.x

1 Answer

10/22/2019

I would recommend you to simply use the idea of 'postgresql' sub-chart along with your newly developed app helm chart (check here how to use it within the section called "Use of global variables").

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 *.sql script.

-- Nepomucen
Source: StackOverflow