如要設定應用程式以進行偵錯,應用程式必須是以 Go 模組為基礎,並在容器中設定其中一個標準 Go 執行階段環境變數 (例如 GODEBUG、GOGC、GOMAXPROCS 或 GOTRACEBACK),以識別為 Go 應用程式。GOTRACEBACK=single 是 Go 的預設設定,GOTRACEBACK=all 則是一般實用的設定。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-11 (世界標準時間)。"],[[["\u003cp\u003eCloud Code for IntelliJ enables debugging of applications deployed to Kubernetes clusters, including local clusters, Google Kubernetes Engine, or other cloud providers.\u003c/p\u003e\n"],["\u003cp\u003eDebugging support in Cloud Code eliminates the need for manual setup, such as port forwarding, debugging backend installation, or language-specific debug argument injection, for supported languages.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code allows for debugging while actively making changes and iterating on the source code of an application.\u003c/p\u003e\n"],["\u003cp\u003eSupported languages for debugging include Java, Kotlin, Node.js, Go, and Python, with specific IDE and plugin requirements for each.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code offers both manual and automatic configurations for mapping local source code to remote sources in containers for Node.js applications, and it also has specific configurations needed for Go and Python apps.\u003c/p\u003e\n"]]],[],null,["# Debug Kubernetes applications with Cloud Code for IntelliJ\n\n| **Note:** Debugging support is available for Java, Kotlin, Node.js, Go, and Python.\n\nCloud Code for IntelliJ allows you to easily debug your applications deployed to a\nKubernetes cluster. You can debug an application on a local cluster (like\nminikube or Docker Desktop), Google Kubernetes Engine, or any other Cloud provider.\n\nWith Cloud Code's debugging support, you skip manual setup like\nsetting up port forwarding, installing a debugging backend, or injecting\nlanguage-specific debug arguments in the right way. All you need is a\nCloud Code-ready Kubernetes application that includes a\n`skaffold.yaml` configuration file.\n\nCloud Code also enables you to [debug an application while making\nchanges to, and iterating on, source code](/code/docs/intellij/watch-modes#applying-changes-while-debugging).\n\nSupported IDEs\n--------------\n\nThe following table lists the languages and IDEs that Cloud Code supports for\ndebugging. The table also lists the required plugins, where applicable:\n\nFor more information about IDE support, see\n[Supported JetBrains IDEs](/code/docs/intellij/ides).\n\nWith Cloud Code, you can set breakpoints and\ndebug remote applications running in containers for the following languages: \n\n### Java\n\nCloud Code automatically adds an environment variable,\n`JAVA_TOOL_OPTIONS`, with the appropriate JDWP configuration to\nenable debugging. If `JAVA_TOOL_OPTIONS` is already present,\nCloud Code uses existing settings specified in\n`JAVA_TOOL_OPTIONS`.\n\n### Node.js\n\nDepending on the structure of your application and its image build\nconfiguration, you might have to help the debugger map your local sources\nto the remote sources in the container. This enables the Node debugger\nto correctly process your breakpoints.\n\nYou can configure this in one of the following ways:\n\n- **Manual configuration**\n\n Select the **Develop on Kubernetes** Run Configuration from the dropdown\n and then click **Edit Configurations** . On the **Debug** tab, configure the\n source mapping from your local application source to the source\n location in the remote container.\n\n Configuration options:\n - **File/directory** - the local file or directory of your application running on Kubernetes.\n - **Remote path** - the path to the file or directory running in the container on Kubernetes.\n- **Automatic configuration**\n\n You can choose to defer this mapping to Cloud Code. When you\n start your debug session, Cloud Code attempts to infer\n this mapping automatically. The inferred mapping is presented to you in a\n dialog; one dialog for each artifact you are debugging.\n\n Configuration options:\n - **Local path** - the local path to the root of the artifact you are debugging.\n - **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 click **Cancel**, no mapping is applied.\n\n | **Note:** Automatic mapping is a best effort guess based on heuristics.\n\n### Go\n\nTo configure your application for debugging, your app must be a\n[Go Module](https://blog.golang.org/using-go-modules)-based application\nand be identified as being Go-based by setting one of the\n[standard Go runtime environment variables](https://godoc.org/runtime)\nin the container, such as `GODEBUG`, `GOGC`, `GOMAXPROCS`, or\n`GOTRACEBACK`. `GOTRACEBACK=single` is the default setting for Go\nand `GOTRACEBACK=all` is a generally useful configuration.\n\nOptionally (but recommended), your app should be built with the\n`-gcflags='all=-N -l'` options to disable optimizations. Skaffold\n[Profiles](https://skaffold.dev/docs/environment/profiles/) are a useful\noption for this purpose and can be set with the **Deployment Profile**\nfield in your Run configuration on the **Build/Deploy** tab.\n\n### Python\n\nTo configure your application for debugging, ensure you meet the following\nprerequisites:\n\n- **IDE, edition, and plugin are compatible**\n\n For compatible IDEs, editions, and plugins, see\n [Supported IDEs](#supported_ides).\n- **Skaffold version is 1.25.0 or greater**\n\n You can allow Cloud Code to [manage your dependencies](/code/docs/intellij/install#managed_dependencies),\n or point to a local Skaffold installation. See **Preferences \\\u003e Tools \\\u003e\n Cloud Code \\\u003e Dependencies**.\n- **Python interpreter is configured**\n\n Without a Python interpreter configured in your project,\n debugging won't work, as there is no way to run `pydevd`, the\n underlying Python debugger.\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\nFor more information, see the [Skaffold debug\ndocumentation](https://skaffold.dev/docs/workflows/debug/).\n\nDebug an application\n--------------------\n\n1. To start the development cycle in debug mode on your Kubernetes cluster,\n click the debug action for\n **Develop on Kubernetes**.\n\n The [continuous development cycle](/code/docs/intellij/speed-up-k8s-development#continuous_development_on_kubernetes)\n initiates in debug mode.\n\n Cloud Code attaches a debug session:\n\n2. You can now perform the tasks you normally do when debugging local code,\n like setting breakpoints and stepping through code, against a live\n Kubernetes cluster.\n\n3. To end the debugging session, click the stop icon on the\n **Develop on Kubernetes** Run Configuration.\n\nWhat's next\n-----------\n\n- Use [file sync and hot reloading](/code/docs/intellij/speed-up-k8s-development#enable-skaffold-file-sync-and-hot-reloading) to speed up development.\n- Set up a [continuous development](/code/docs/intellij/speed-up-k8s-development#continuous_development_on_kubernetes) environment in Cloud Code.\n- [View Kubernetes logs](/code/docs/intellij/view-logs) in Cloud Code.\n\nGet support\n-----------\n\nTo submit feedback or report an issue in your IntelliJ IDE, go to **Tools** \\\u003e **Cloud Code** \\\u003e **Help / About** \\\u003e **Submit\nfeedback or report an issue** to report an issue on [GitHub](https://github.com/GoogleCloudPlatform/cloud-code-intellij/issues)."]]