在 Cloud Code for VS Code 中使用现有应用
Cloud Code 在后台使用 Skaffold 运行或调试您的应用。
如果您已使用 Kubernetes 清单和 Dockerfile 配置了现有应用以构建映像,则可以打开这个应用,并将其与 Cloud Code 搭配使用。
唯一需要的额外配置是类型为 cloudcode.kubernetes
的 skaffold 配置和启动配置。Cloud Code 会在您首次运行应用或调试应用时引导您创建这些配置。
设置配置
如果您的应用具有 Dockerfile,但没有必要的 Skaffold 和启动配置,请完成以下步骤:
在 Cloud Code 状态栏中,点击当前项目名称。

在随即显示的快速选择菜单中,选择 Run on Kubernetes(在 Kubernetes 上运行)或 Debug on Kubernetes(在 Kubernetes 上调试)。
在“Run/Debug on Kubernetes”对话框中,指定首选构建器及其设置。 您还可以自定义配置名称。
点击调试或运行。
如果系统提示,请验证您的凭据以在本地运行和调试应用。
新创建的 skaffold.yaml
和 cloudcode.kubernetes
启动配置会添加到您的工作区,并且您的应用会运行或做好调试准备。
为已有 skaffold.yaml 的应用设置配置
如果您的应用已有 skaffold.yaml
文件,请按以下步骤操作:
在 Cloud Code 状态栏中,点击当前项目名称。

在随即显示的快速选择菜单中,选择 Run on Kubernetes(在 Kubernetes 上运行)或 Debug on Kubernetes(在 Kubernetes 上调试)。
如果您的工作区中有多个 skaffold.yaml
文件,请选择您的首选 skaffold.yaml 文件。
如果您选择的 skaffold.yaml
文件中存在多个 Skaffold 配置文件,请选择您的首选 Skaffold 配置文件。
新创建的 cloudcode.kubernetes
启动配置会添加到您的工作区(在 .vscode/launch.json 中),并且您的应用处于运行状态或做好调试准备。
手动创建 Skaffold 配置
您可能需要手动创建 Skaffold 配置以定义自定义选项。Cloud Code 附带了实时模板,以支持手动创建 Skaffold 配置。
如需手动创建 Skaffold 配置,请执行以下操作:
在工作区的根目录中创建一个名为 skaffold.yaml
的新文件。
在该文件中,按 Command/Ctrl+Space
查看代码段建议列表,然后选择 Skaffold - getting-started 代码段。

在 image
字段中输入项目映像名称,然后在 manifests
字段中输入要部署的 Kubernetes 资源列表。
基于 Dockerfile 的构建示例:
build:
artifacts:
- image: image_name
deploy:
kubectl:
manifests:
- k8s/web.yaml
- k8s/backend.yaml
如果要为不同的上下文定义构建、测试和部署配置,可以使用不同的 Skaffold 配置文件。以下示例展示了一个 Cloud Build 配置文件,用于配置 Cloud Code 以使用 Cloud Build 构建映像:
profiles:
# use the cloudbuild profile to build images using Google Cloud Build
- name: cloudbuild
build:
googleCloudBuild: {}
如需了解全面的架构详情,请参阅 skaffold.yaml 参考。
后续步骤
获取支持
如需发送反馈,请在
GitHub 上报告问题,或者在
Stack Overflow 上提问。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-11。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[[["\u003cp\u003eCloud Code utilizes Skaffold for running and debugging applications, and it can be used with existing applications that are already configured with Kubernetes manifests and a Dockerfile.\u003c/p\u003e\n"],["\u003cp\u003eIf your application lacks Skaffold and launch configurations, Cloud Code guides you through creating them when you first run or debug, including setting up a \u003ccode\u003eskaffold.yaml\u003c/code\u003e and \u003ccode\u003ecloudcode.kubernetes\u003c/code\u003e launch configuration automatically.\u003c/p\u003e\n"],["\u003cp\u003eFor applications already possessing a \u003ccode\u003eskaffold.yaml\u003c/code\u003e, Cloud Code streamlines the process by allowing you to select the desired \u003ccode\u003eskaffold.yaml\u003c/code\u003e file and Skaffold profile, creating a \u003ccode\u003ecloudcode.kubernetes\u003c/code\u003e launch configuration automatically.\u003c/p\u003e\n"],["\u003cp\u003eYou can manually create a \u003ccode\u003eskaffold.yaml\u003c/code\u003e configuration, leveraging Cloud Code's live templating feature and snippet suggestions to define custom options, build, test, and deployment configurations, with options to include multiple Skaffold profiles.\u003c/p\u003e\n"],["\u003cp\u003eAfter the configurations are set, file sync and hot reloading can be used to speed up development and debugging.\u003c/p\u003e\n"]]],[],null,[]]