1

H2 is an open-source lightweight Java database. Basically I am trying to build a DevOps pipeline but for the Kubernetes part I need to hook up the h2 database locally to the pod and not using aws rds for anything like that. Any ideas on how to configure this?

Ray
  • 11
  • 2
  • 1
    Can you elaborate your requirement? What you are going to do with `H2`? Is it just deploying to kubernetes? – Bimal Jun 03 '20 at 02:16
  • Yea im pretty sure its supposed to be in each pod so each service in the pod has access to it. or each service in each container has access to the h2 instance. I know you can expose ports for services trying to communicate from outside, but what about inside the cluster itself? – Ray Jun 03 '20 at 02:56

1 Answers1

2

It’s a little unclear when you say you need to hook up H2 locally in each pod whether you mean 1 H2 overall or 1 per pod. I’m assuming you need a server H2 and not an embedded one.

If your requirement is to have all your pods talking to the same H2 instance, you can create a container that runs H2 in server mode and run it in a Deployment. You would also need a Service to expose the database port within the cluster. See https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#accessing-the-service for some details.

You’d probably also want to run H2 with a file backing the database, unless you can recreate the contents of the database by some other magic when its pod restarts. For that file to be persistent across H2 restarts, you would need to provision a persistent volume and persistent volume binding. Details for PVs are Kubernetes platform specific. https://kubernetes.io/docs/concepts/storage/persistent-volumes/

If you don’t need a single H2, but rather one in each pod, you could run an H2 container in each pod beside your other other container(s). Or you could fork an H2 server in a Deployment’s main container command, if you don’t want to use H2 in a container. (Ugly, though and not really the Kubernetes way.) You would not need a Service in this case, as you’d connect to H2 locally in the Pod. But you’d have a real nightmare I’d think managing persistent volumes to hold the database for each Pod’s H2, assuming you need persistent storage.

Ultimately, you may decide that RDS is easier...

Eric Schoen
  • 668
  • 9
  • 16