hevi
hevi

Reputation: 2726

How to run an sql script in a kubernetes cluster for exactly for once

I have a service running on a Kubernetes cluster with many replications. My services are spring boot services.

I've no access to the DB, only the service does.

I need to run a script that alters schemas, it must be run once, and just before the newly deployed code starts running.

How can I run an SQL script exactly one time?

Upvotes: 1

Views: 2157

Answers (1)

Arghya Sadhu
Arghya Sadhu

Reputation: 44637

You can use init container for running a script. Init containers runs before the actual container runs.

Because init containers run to completion before any app containers start, init containers offer a mechanism to block or delay app container startup until a set of preconditions are met. Once preconditions are met, all of the app containers in a Pod can start in parallel.

Upvotes: 4

Related Questions