Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local Development Best Practices: Java, Docker, Kubernetes

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:

  1. All of this is done manually (there is clear room to automate the process of building an image after code is built and to have k8s update using the new image).
  2. Builds are manually specified (python relaunches on code save. No hot reloading to my knowledge in the java world).
  3. I have yet to see an integration between a local development environment and a cloud hosted k8's cluster. Ideally, a dev would test locally until they are ready to deploy to the cloud. When they are ready, it would be awesome to click a button and have a cluster read from a remote registry that could pick up the docker image changes and reload.

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)?

like image 281
Chad Van De Hey Avatar asked Oct 09 '18 17:10

Chad Van De Hey


People also ask

Should you use Kubernetes for local development?

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.

Is Docker good for local development?

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.

Should Java developers learn Kubernetes?

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.


1 Answers

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

like image 65
Ortomala Lokni Avatar answered Sep 29 '22 18:09

Ortomala Lokni