Remote debugging Spring Boot on Kubernetes

Erdem Alparslan
ITNEXT
Published in
2 min readJul 22, 2018

--

You develop your Spring Boot application locally and then you containerize it. Even you deploy it on a Docker host or Kubernetes. But how will you debug your production deployment remotely on your local IntelliJ environment? 🤔 Here is the solution… 🤓

In my previous posts I explained how to deploy a Spring Boot Application on Google Kubernetes. I assume that you already have a workload and an exposed IP address of your application.

Kubernetes deploys applications as workloads. Each workload is exposed to the Internet by a load balancer on a real IP address and port configuration. This is a must unless your app serves your other internal applications.

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ADD $JAR_FILE target/app.jar
ENTRYPOINT ["java","-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n","-Djava.security.egd=file:/dev/./urandom","-Xms2g","-Xmx8g","-jar","target/app.jar"]

The bold line above is an example configuration from my Dockerfile which is on root of my project. As I explained in my previous post this Dockerfile is used by Docker-Maven plugin of Spotify. This plugin containerize the jar file and builds a docker image. In that configuration please notice that this container will run JAVA debugger on port 5005 locally. This means wherever you run a container based on this image, Spring will provide an attachable debugger on port 5005.

But how will we reach that port 5005 on a workload running on GKE?

The point that we need here is to expose one more port on that GKE Load Balancer for debugging purposes of your application remotely.

On Services tab of your GKE console find the service that exposes port 80 (or whatever for your real application) and add another mapping for 5005 so that you can reach your remote debugger from local machine.

Expose port 5005 on GKE Services tab

This can also be achieved by editing the YAML file for your service

Notice that debug port added to service’s YAML file

That’s it. Your port 5005 debugger is accessible by remote debuggers. Add a new Run/Debug Configuration on IntelliJ Idea and simply define GKE service IP and port 5005.

--

--