Score:0

How to launch a sql file on kubernetes pod creation?

uz flag

We have our database either in aws rds or azure postgres or even on a different online server based on customer.

But our product will be running in azure kubernetes as a pod and service with database details in configmap.

Before we launch our app, it is mandatory that an sql file should be running in the database as preconfiguration.

What is the best approach we can set it so that we can automate this?

Score:1
cn flag

There are many possible solutions for this and it will depend on the way you do the deploy and what tools you use to do the deploy.

First of all be aware that it's an antipattern to launch a pod and execute an SQL (init or migration script). Containers should do one thing and you should not assume how the containers will be executed. For example, what happens if you launch multiple containers at the same time? If all of them run migrations at start, they will trip over each other. So, initcontainers should also be discarded as a solution.

The simplest solution is to run as a separate job as part of your CI/CD pipeline. You execute the init/migration. Once it's applied, you deploy your code.

If you are you using helm, you can use pre-install or pre-update hook

As I tried to explain, there are many alternatives to do exactly what you want. The main thing is that you need to control "when" the database changes are applied specially because you can't control "how" they will be running.

uday kiran avatar
uz flag
We didnn't create helm yet. The project is in initial stage, it is really helpful if you suggest more points like this.
Ezequiel Gonzalez Rial avatar
cn flag
The it's easier to go with https://kubernetes.io/docs/concepts/workloads/controllers/job/
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.