0

I have an application war which reads an API implementation jar file to load some data in memory. What I am doing currently is that I COPY that jar inside my "application-war/lib" directory using docker file while generating my applications images.

The downside of this is that whenever the jar needs to be changed; I need to recreate my application war docker image.

Is there a way that I can externalize this jar file location, that I just need to restart of my running pod rather creating a new image each time.

I mean someway if I can give an additional CLASSPATH which my pods container can read while starting up.

Thanks

Jaraws
  • 581
  • 1
  • 7
  • 24

2 Answers2

1

You are already doing it the right way. The docker image should always be created for each build so you have history as well. It won't be a good practice to change something inside a running pod and restart it somehow.

If you still want to do it that way, you could mount an external volume to your pod and configure your application server to read war file from that location. In this case you will still need access to that volume some other way which allows you to place the file there.

Hazim
  • 1,405
  • 1
  • 11
  • 24
1

To provide a bit more context. Everything what was said by @Hazim is correct and I fully agree with him about you doing the current build the correct way as it's allows you to see image history and quickly switch if needed.

As for using external files inside your image. You need to setup a PV - persistent volume, which will be utilized by PVC - persistent volume claim. A really detailed description with exampled is available on Configure a Pod to Use a PersistentVolume for Storage. It shows how to create a folder on your node place a file in it which later will be loaded into a pod. You won't be loading that file into a pod but using the path in your Dockerfile to load the .jar file.

If your .jar file is composed of key=value entries you could also use ConfigMap instead of PV. This is nicely explained on a Redis application which you can see here DOCKER / KUBERNETES - CONFIGURE A POD TO USE A CONFIGMAP.

I hope this provides all needed information.

Crou
  • 10,232
  • 2
  • 26
  • 31
  • Crou, my base image is a kind of docker project which takes a spring batch file as input and run the jobs having its classes defined in an external jar. What my users have to do currently is they have to build a new image using my image where they copy their jars inside my app/lib directory and creates a new image to run their project. I just want to avoid that by setting CLASSPATH from where I can read their jar to run their jobs. I know concept the of PV,PVC and can see their jar inside apps container but not able to make it a part of classpath from Kubernetes yaml definition. – Jaraws Jul 03 '20 at 13:05
  • I think what you want to configure right now is how to tell your application server (Tomcat, Jboss etc) to read from different classpaths instead of specifying somewhere int he kubernetes yaml. If your application server can be configured by a configmap or environment variable, then it would be possible to add that in your kubernetes yaml definition – Hazim Jul 06 '20 at 13:37