Migration Java application to Kubernetes. Monolith
This article is the thoughts about additional steps that need for monolith installation in k8s.
There is the same application as Spring Boot, but a few main things need highlighting.
Dockerfile
In this example, Dockerfile contains Ubuntu, Tomcat server, and jar/war as application.
This docker image is a little tricky. There is a multistage docker image creation.
The first stage is for Tomcat preparation. We don’t need additional soft for application runtime. But we need it to get and unpack Tomcat, copy and extract web application.
The first step is the application copying. The second step is a complex shell script that includes: additional soft installation, downloading the Tomcat server, setting PROPERTY_SOURCE for using OS environment variables in Tomcat configurations, removing default Tomcat projects and manager, unzipping web application.
The next stage of the dockerfile is copying installed Tomcat with the web application from the previous step into the current layer,
then upgrading system libs and JDK installation. The last step CMD/ENTRYPOINT definition.
In setenv.ev file you can add any Tomcat and Java startup parameters:
Also, You can set your properties. Those properties must call with -D prefix.
For Spring Application
In pom.xml add necessary dependencies:
Then create ServletContextListener:
After that, register this listener in web.xml:
If Spring Security was used, disable security validation to this endpoint,
in security-context.xml add:
If you are using Oracle database
For the web application, you should add this driver in the Dockerfile
and in the maven define driver as provided:
Log definition
For Tomcat based application log4j.xml can print JSON too.
For container memory leak avoiding in logging.properties
disable file log appenders:
You can do it in Dockerfile by replacing original logging.properties with the COPY/ADD commands,
or you can use script like in example below:
Don’t forget to set the docker build-args!
If $log-config are multiline, use /n at the end of each line.