I have a microservice which connects directly to PostgreSQL. PostgreSQL is already deployed and running on Kubernetes cluster.
I'm planning to deploy microservice and curious, is there any way to create DB schema during microservice deployment?
There can be more microservices and they can use different schemas, but during PostgreSQL deployment how schemas should look like it's not known yet.
During deployment of the service which requires a DB, you need to ensure that the DB is in a state where the service can operate on.
You can use Flyway for this. It supports migrating a database based on sql scripts and also is version aware, so if you for example execute flyway migrations a second time, it wont do the changes again.
This can be run as part of your deployment procedure, or within an init container or even can be injected into your code directly, so everytime your app starts up it will ensure the db state is given.