Using Maven to feed minikube on a VM

24 Views Asked by At

Allow me to start with a basic disclaimer: I always use VMs to run more complex server-like applications. In this example I run minikube on a VM, as I want to play around with Kubernetes a bit. Once I'm done, I kill the VM, or back it up somewhere external to get rid of the stuff quickly. Installing this on my local OS is not a viable option to me. Now to the question/issue I want to resolve.

I have a small Spring Boot Service, nothing worth mentioning. I want to deploy that service into a Pod. Following online documentations and tutorials, I have setup my VM on Debian 12 with Docker, Helm and Minikube. I used a kubernetes/helm plugin for my IDE to have all the necessary config files generated, and followed a simple onboarding tutorial to get an idea of how the basics work. My issue arises with my desire to have Minikube on a VM, instead of having it on the base client. I fail to build the docker image on the VM through Maven.

What works:

  • I can build the .jar-File
  • I can copy the dockerfile and the .jar-File to the VM using Maven-Antrun-Plugin with SCP
  • I can build the image manually on the VM using "docker build -t name ."
  • I can use SSHEXEC to create a file through the touch command or a directory through mkdir

What doesn't work:

  • Using the antrun plugin for SSHEXEC to execute above command with the proper path, results in the proper terminal feedback, but not in a created image
  • I tested the same through a shell-script "buildImage.sh", which runs the command in the proper folder, and have SSHEXEC just run the script, yielding the same results

I use following execution (removed personal info) to run the sshexec

<execution>
  <id>builddocker</id>
  <phase>pre-integration-test</phase>
  <goals>
    <goal>run</goal>
  </goals>
  <configuration>
    <target>
      <sshexec host="xxx" username="xxx" password="xxx"
               failonerror="true" trust="true" timeout="120000" usepty="true"
               command="docker build -t xxx ${kubernetes.image.path}"/>
    </target>
  </configuration>
</execution>

This is the first setup. The setup where I execute the shell-script is a bit more convoluted, but works the same. The only difference, why I tested it, is that the docker command is executed in the same working directory, where the dockerfile is located.

My original hypothesis was that SSHEXEC closes the connection before the command finishes. The existence of the docker feedback in the execution console disproves this though. There are no error messages from docker. Docker finishes with "Writing image sha256:" and "naming to docker.io/library/xxx" But as soon as I docker images ls or minikube images ls the image isn't there. I also tripple checked that maven uses the same user as I use on my ssh terminal to check the results.

Right now I'm a bit out of ideas, so I thought I'll open a question here to see if someone else has an idea. I also never rule out that I missed something really silly :)

PS: If there is another approach to deploy the java/docker-stuff on the VM (meaning better than maven) I'm happy to hear it too. Maven is just "the most obvious answer" when I think of automatic builds in Java.

0

There are 0 best solutions below