Debugging an application

Cloud Code for IntelliJ allows you to easily debug your applications deployed to a Kubernetes cluster. You can debug an application on a local cluster (like Minikube or Docker Desktop), GKE, or any other Cloud provider.

Furthermore, with Cloud Code's debugging support, you don't have to worry about any manual setup like setting up port forwarding, installing a debugging backend, or injecting language-specific debug arguments in the right way. All you need to do is have a Cloud Code-ready Kubernetes application that includes a skaffold.yaml configuration file.

Debugging

Click the debug action for Develop on Kubernetes run action icon to start the development cycle in debug mode on your Kubernetes cluster.

Starting the Kubernetes cluster development cycle in debug mode

The continuous development cycle will then initiate in debug mode.

Once the debugger can be attached, Cloud Code will attach a debug session:

Kubernetes debugger attached

You can now perform all the tasks you normally do when debugging local code, like setting breakpoints and stepping through code, except with the added advantage of debugging against a live Kubernetes cluster:

Kubernetes debugger session

To end the debugging session, click the stop icon on the Develop on Kubernetes Run Configuration.

Configuration Details

Cloud Code, powered by Skaffold under the hood, can help configure your debugging sessions. With Cloud Code, you can set breakpoints and debug remote applications running in containers for the following languages:

Java

Cloud Code will automatically add an environment variable, JAVA_TOOL_OPTIONS, with the appropriate JDWP configuration to enable debugging. If already present, Cloud Code will use existing settings specified in JAVA_TOOL_OPTIONS.

Node.js

Depending on the structure of your application and its image build configuration, you may have to help the debugger map your local sources to the remote sources in the container. This enables the Node debugger to correctly process your breakpoints.

There are two ways to configure this:

  1. Manual Configuration

    Select the 'Develop on Kubernetes' Run Configuration from the dropdown and select 'Edit Configurations'. In the 'Debug' tab, configure the source mapping from your local application source to the source location in the remote container.

    Choosing a source location in the source mapping section of the Debug tab

    Configuration options:

    • File/Directory - the local file or directory of your application running on Kubernetes.
    • Remote Path - the path to the file or directory running in the container on Kubernetes.
  2. Automatic Configuration

    You can choose to defer this mapping to Cloud Code. When you start your debug session, Cloud Code will attempt to infer this mapping automatically. It will be presented to you in a dialog; one dialog for each artifact you are debugging.

    Remote path mapping dialog for each artifact specifying remote path being used

    Configuration options:

    • Local path - the local path to the root of the artifact you are debugging.
    • Remote Path - the path to the file or directory running in the container on Kubernetes. You can choose to override this with your own value. If you hit Cancel, then no mapping will be applied.

Go

In order to configure your application for debugging, your app must be:

  • a Go Module-based application.
  • identified as being Go-based by setting one of the standard Go runtime environment variables in the container, such as GODEBUG, GOGC, GOMAXPROCS, or GOTRACEBACK. GOTRACEBACK=single is the default setting for Go, and GOTRACEBACK=all is a generally useful configuration.

Optionally (but recommended), your app should be built with the -gcflags='all=-N -l' options to disable optimizations. Skaffold Profiles are a useful option for this purpose, and can be set with the 'Deployment Profile' field in your Run configuration under the 'Build/Deploy' tab.

For more details, refer to the Skaffold debug documentation.

Getting Support

To send feedback, report issues on GitHub, or ask a question on Stack Overflow.