Deploying Spring Boot onto Kubernetes

Updated: April 26, 2019

Kubernetes is great, but flippin’ heck, it is unbelievably complicated for new developers.

If you’re a developer who’s new to Kubernetes, you might be staring it in the face and thinking “how the hell do I work this thing”. Or you might be thinking “oh great, yet another step in my deployment process 😩”

So I wanted to put together a clear guide on how to deploy a Spring Boot application to Kubernetes. This will get you going running your first application on Kubernetes.

So we execute this next command. It sets up some environment variables which configure Fabric8 Maven Plugin to use the Docker daemon running in Minikube. It does this by setting the DOCKER_HOST variable, and a couple of others:

$ eval $(minikube docker-env)

If you’re running Windows, just type minikube docker-env and it will tell you what you need to do.

Finally, we compile our Spring Boot application to a JAR (package) and build a container image using the fabric8:build goal:

$ mvn package fabric8:build

This will:

Compile your Spring Boot app to a JAR

Pull down a suitable base image to use for your application, from Docker Hub

Use Minikube’s Docker daemon to build (or bake!) a Docker image, using the base image

Push the new image into Minikube’s local Docker registry

Once the build has completed, you can take a look at it in the Docker registry: