How to manage custom common libraries built in maven for my Application in kubernetes

1/12/2018

I need to understand how to deal with common libraries that i have created which my Application depends upon. When i create jar for this app using maven it creates a package. But how do we maintain or configure other common libraries which are listed in pom.xml of this application?

should we have maven also as an image in the docker file?

Please explain in detail.

My current progress is explained below: I have an Application A which has other dependencies like B and C libraries which i have specified in pom.xml. When i run application A in my local system it uses local repository that i have configured in user settings for maven. SO it works fine.

So how do we maintain this in kubenetes.

-- Anil Kumar P
docker
kubernetes
maven

1 Answer

1/12/2018

The images that you use to build the containers that run on Kubernetes should contain everything that's needed to run the application.

When you create the JAR file for your application, this JAR should contain the dependencies. There are different ways to achieve this, using both Maven or Gradle. This is an example using Maven and its Apache Maven Assembly Plugin. This is another good user guide on how to achieve it.

Then, you need to create a container image that can run that JAR file, something like

FROM openjdk:8-jdk-alpine
EXPOSE 8080
WORKDIR /opt/app
CMD ["java", "-jar", "app.jar"]
COPY build/libs/app.jar /opt/app

Once this container image is published on a registry, whenever Kubernetes needs to schedule and create a container, it will just use that image: there is no need to re-compile the application and its dependencies.

-- Jose Armesto
Source: StackOverflow