<p>We are planning to use Kube for Postgres deployments. Our applications will be microservices with separated schema (or logical database). For security sake, we'd like to have separate users for each schema/logical_db. </p>

<p>I suppose that the db/schema&amp;user should be created by Kube, so the application itself does not need to have access to DB admin account.</p>

<p>In <a href="https://github.com/sorintlab/stolon" rel="nofollow noreferrer">Stolon</a> it seems there is just a possibility to create a single user and single database and this seems to be the case also for other HA Postgres charts. </p>

<p>Question: What is the preferred way in Microservices in Kube to create DB users?</p>

<p>When it comes to creating user, as you said, most charts and containers will have environment variables for creating a user at boot time. However, most of them do not consider the possibility of creating multiple users at boot time. </p>

<p>What other containers do is, as you said, have the root credentials in k8s secrets so they access the database and create the proper schemas and users. This does not necessarily need to be done in the application logic but, for example, using an init container that sets up the proper database for your application to run.</p>

<p><a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/init-containers</a></p>

<p>This way you would have a pod with two containers: one for your application and an init container for setting up the DB.</p>
