I am trying to figure out the ultimate best practices for using Java in Docker containers deployed using Kubernetes on local environments or while developing code. In the ideal state, Java developers should be able to move as fast as python/javascript developers, but I am having a hard time matching the speed (or even coming close).
At the moment, I have a working, manually deployed k8's cluster. My Java Spring project is built by maven after a build command is run manually (mvn clean install
), then I run a script to make an image, after that I run a script to run minkube (if its not already running) and finally I have to apply
a deployments manifest file (which launches the containers into the pods).
What I am missing:
Sadly, Skaffold, the tool that I would be excited to use does not work natively with Java. Is there another tool that Java Devs are using to make their local deployments super fast and competitive with the DUCK languages (py, js)?
Kubernetes is a container orchestration system that is designed to run in a cloud environment. Therefore, it is simply not possible to run a cloud system like Kubernetes in a local development environment.
Docker is great at setting up a local development environment because it easily adds the running process without duplicating the virtualized resource. Second, it's more modular. Docker makes it easy to run multiple versions or instances of the same program without configuration headaches and port collisions.
Kubernetes is one of the most popular container orchestration engines available. More and more employers are looking for developers with Kubernetes experience. As a Java developer, learning Kubernetes deployment techniques is an easy way to extend your existing skills and employability.
You can build a docker image directly from maven with docker-maven-plugin. Add to your pom.xml
:
<build>
<plugins>
...
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>VERSION GOES HERE</version>
<configuration>
<imageName>example</imageName>
<dockerDirectory>docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
...
</plugins>
</build>
I don't know precisely your use case, but deploying a k8's cluster in your dev machine is maybe overkill. You can test your docker images with Docker compose
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With