How to debug Kotlin applications running in Kubernetes pods in IntelliJ?

5/19/2019

I'm successfully debugging Spring Boot applications written in Java inside Kubernetes using the following setup:

  • Add -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" to the mvn spring-boot:run command line in Dockerfile.
  • Add

    - name: java-debug
      containerPort: 5005

    to spec.containers.ports of the Deployment and

    - name: java-debug
      protocol: TCP
      port: 5005
      targetPort: 5005

    to spec.ports of the Service.

  • Add a Remote run configuration with Debugger mode set to Attach to remove JVM and the host of the Service.

Doing the same for a Kotlin project, the debugger connects to the JVM and accepts breakpoints, however, doesn't stop at them, no matter how often I execute the code where it should stop. The code is executed on k8s according to logs and application feedback.

I'm testing this locally on microk8s using IntelliJ 2019.1.2 CE.

-- Karl Richter
debugging
intellij-idea
kotlin
kubernetes
remote-debugging

1 Answer

11/21/2019

As mdaniel noted, it's indeed a sign of bad practices if I need to do what I'm trying to do. This task needs to be approached with configurable logging and integration tests.

-- Karl Richter
Source: StackOverflow