I have a MongoDB cluster in Kubernetes, it's pushed to Kube with a StatefulSet type of deployment.

That part work's good, I can even create 1 DB with variables starting with that...

My question is, how do I create more than 1 DB within Mongo at first run time?

Let's say I have 5 DB to create with their respective user/pass

  • db-foo
  • db-bar
  • db-test
  • db-lotr
  • db-thedb

How can I make sure these are initiated/created at first deploy time? Do I just create a SHELL script within mongodb/pre-init/ and rebuild my Mongo with my scripts in there?

Do I use another set of variables numbered?

I am confused. Please help me.

  • 1
    Why isn't your application doing its own database migrations? – Michael Hampton Feb 17 at 17:03
  • It is not about migration, it is about initiating the DB at first container install. I can do it via variables, but I can only do 1 DB... I need to create more than DB in my case... – yield Feb 18 at 14:23
  • Database migrations do that too. – Michael Hampton Feb 18 at 14:37
  • @MichaelHampton Can you elaborate ? – yield Feb 20 at 13:17
  • What is it you want elaborated? – Michael Hampton Feb 20 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.