jjbuchan / docs

0 stars 0 forks source link

How to attach debugger to a running deployment #11

Open jjbuchan opened 3 years ago

jjbuchan commented 3 years ago

In IntelliJ open the Run Configurations such as with the menu "Run > Edit Configurations...". Add a new configuration of type "Remote":

image

Pick the module to debug from the "Use module classpath" and copy off the command line arguments it provides:

image

Use kubectl edit or the GCP Console web interface to edit the app-deployment to debug. Locate the JAVA_TOOL_OPTIONS environment variable and add the "-agentlib" arguments copied from the run config. If using the GCP Console, make sure to scroll to the bottom of the page and click "Save".

While you're in there modifying the deployment, it is helpful to scale the replicas down to 1 in order to ensure one, known instance of the application will handle API/events and can be reliably debugged.

Wait for the scaling and new revision of the pod to be created and ready...

image

Start port forwarding to the remote debug port (5005 by default) of the pod using kubectl port-forward such as

kubectl port-forward pod/presence-monitor-7bc76dfb64-sz96r 5005:5005

Start a debug session by selecting the run config created above and clicking the "Debug" button:

image

You can now set breakpoints and/or pause the remote JVM to debug further.

Press the stop button to detach the remote debugger session:

image

You can now Control-C to stop the kubectl port-forward instance.