Multiple replicas of a helm dependency?

I have a stateful application, where my app has a db, and that conflicts if another (same) app uses it. Therefore, to avoid downtime in case of a crash, I want to deploy two of those. The client should be transparent to where it ends up, but app1 can only use db1, and app2 only db2.

              client
    app1------- | ------- app2
       |                   |
    db1                   db2

It looks simple but I haven’t been able to figure this out. Ideally, I’d be able to scale them horizontally with more instances.

I am using bitnami’s postgres as a dependency:

 - name: pg
   version: "16.1.0"
   repository: "https://charts.bitnami.com/bitnami"

I know I could alias this and use two of them, but then I also have to repeat all the configs for each. Which isn’t too bad, but then if I have to add a 3rd, or a xth, then this doesn’t work well.

Ideally I have ONE deployment object which encapsulates my app and the db into one thing, so that I could just set a replicas of that and I’d be happy. But I couldn’t figure out how to do this.

So far my app is in a Statefulset, but that kinda is detached from the postgres dependency. How can I create such a “package” with app and db?

I’m no fan of the Bitnami charts. I feel like they obscure the (Kubernetes configuration) code with all their templating. If you can’t read the code clearly, mistakes follow. So I’d suggest replacing theirs with your own, simpler chart. And then you put the config into that chart, no? So it’s not repeated.

Are you using NetworkPolicys? Do you have a CNI that supports them? That way you can guarantee that each DB can only be contacted by its app.

Thanks, I ended up doing actually something along these lines. Current iteration has db and app in the same pod in side containers. Looking at how well that works for me right now.