When i try to open the web UI xyz.com/h2/ of the H2 database with my browser, i get the following plaintext response:
Host xyz.com not found
I am running the H2 database in a Kubernetes environment.
The following JVM options are used to start the H2 database:
command:
- java
args:
- -cp
- /opt/h2/h2.jar
- org.h2.tools.Server
- -baseDir
- /opt/h2/data
- -tcp
- -tcpPort
- "9092"
- -tcpAllowOthers
- -web
- -webDaemon
- -webPort
- "8082"
- -webAllowOthers
- -ifNotExists
When i enable tracing with the option -trace
, i can see an HTTP 404 Not Found error in the server logs of the H2 database.
Versions i use: H2: 2.2.224 Kubernetes: 1.26 Java: JDK11
I am expecting to see the GUI console (web UI) of the H2 database when requesting the URL. With H2 version 1.4.196 the above configuration is working for example.
The solution is: using webExternalNames
JVM option to unlock the host names where my H2 database instance should be requested from.
In my case the command line in the kubernetes deployment manifest looks now like that:
command:
- java
args:
- -cp
- /opt/h2/h2.jar
- org.h2.tools.Server
- -baseDir
- /opt/h2/data
- -tcp
- -tcpPort
- "9092"
- -tcpAllowOthers
- -web
- -webDaemon
- -webPort
- "8082"
- -webAllowOthers
- -webExternalNames
- xyz.com,localhost,h2-v2,h2-v2.build,h2-v2.build.svc.cluster.local
- -ifNotExists
xyz.com = this is the hostname when requesting the H2 web UI from outside the Kubernetes cluster
localhost = loopback adress when calling the web UI from within the Kubernetes pod
h2-v2 = Kubernetes service name for calling the web UI from another pod within the same namespace in the same Kubernetes cluster
h2-v2.* = Kubernetes service name in combination with namespace (build) and full qualified domain name (svc.cluster.local) to support different configurations in pods of the same or different namespaces in the same Kubernetes cluster
A list of all JVM option for starting the H2 database server instance you can get here: H2database.com/javadocs