Open In App

Enable Remote Debugging For Java Application Deployed in Kubernetes Environment

During Development, developers have to debug their applications to resolve code problems. In order to debug a java application which is deployed on remote machine in a Kubernetes cluster, first developer has to do some steps to enable its application ready for debugging. Below are the manual steps to enable remote debugging for any java application running as a container in Kubernetes environment.

Step by Step Implementation

Step 1: Edit the deployment. Let’s say deployment name is “my-app”.



kubectl edit deployment my-app

Step 2: Add the java options (JAVA_OPTS )and its value for enabling debugging as a variable in “env” section in the deployment as follows:



– name: JAVA_OPTS

value: “-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9991”

After saving the changes to the deployment, Kubernetes will automatically redeploy all the pods with the new changes.

Step 3: Create a debug service for your application. Let’s say you have named it as “my-app-debug-svc.yaml”  or change the existing service yaml file if present. Refer below sample service yaml file, do the highlighted changes in your service yaml file. Adding nodePort enables outside application (here your IDE) to access containers deployed in Kubernetes Cluster.

apiVersion: v1

kind: Service

metadata:

 name: my-app-debug-svc

 namespace: <namespace>

 labels:

   service: my-app-debug

   release: “1.0”

spec:

 type: NodePort

 ports:

   – port: 9991

     nodePort: 9991

     protocol: TCP

     name: debug-port

 selector:

   app: my-app

   service: my-app-debug

   release: “1.0”

Step 4: Start the debug service using below command. 

Kubectl create -f my-app-debug-svc.yaml

Step 5: Edit configuration in your IDE to do remote debugging. Here are the steps to edit configuration in IntelliJ IDE:

IntelliJ Remote Debug Edit Configuration

IntelliJ Console: Connected to VM: Ready for Debugging.

That’s all you are ready to debug your Java Application remotely!

Article Tags :