Debugging java app in a K8S pod using telepresence

284 Views Asked by At

I am trying to debug a java application deployed in K8S cluster in Kyma.

I am trying to use telepresence for this

I have installed telepresence and have swapped the deployment.

Below are the logs while connecting

    T: Forwarding remote port 8080 to local port 8080.

T: Connected. Flushing DNS cache.
T: Setup complete. Launching your command.

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
@cba47a8.kyma-stage.shoot.live.k8s-hana.ondemand.com|bash-3.2$

Now when i try to create a remote debug configuration in Eclipse by giving localhost:8080 i am getting connection refused error.

I understood with the logs above that the port forwarding has happened and available as local port.

Best Regards,

Saurav

1

There are 1 best solutions below

0
On

I think connection refused error is not related to Telepresence configuration. When you start your java application, you need to enable remote debugging by providing JVM option -agentlib:jdwp:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar app.jar

More details here

After that you can set Eclipse configuration with localhost:5005.

Also, I think it's worth mentioning that if you don't need bidirectional communication, you can simply port-forward with kubectl command:

kubectl port-forward <pod_name> 8080:8080

but don't forget to enable remote debugging in your deployed application.
For Docker image you can define ENTRYPOINT as

ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]

and control enable or not debugging by setting JAVA_OPTS environment variable.