本頁面中的部分或全部資訊可能不適用於 Trusted Cloud by S3NS。
在 Cloud Code for VS Code 中使用現有應用程式
Cloud Code 會在背景中利用 Skaffold 執行或偵錯應用程式。
如果您已經使用 Kubernetes 資訊清單和 Dockerfile 設定現有應用程式來建構映像檔,則可以開啟該應用程式並搭配 Cloud Code 一起使用。
您只需要額外設定 Skaffold 設定和 cloudcode.kubernetes
類型的啟動設定。第一次執行或偵錯應用程式時,Cloud Code 會引導您建立這些項目。
設定
如果應用程式有 Dockerfile,但沒有必要的 Skaffold 和啟動設定,請完成下列步驟:
在 Cloud Code 狀態列中,按一下目前專案名稱。

在隨即顯示的「快速挑選」選單中,選取「在 Kubernetes 中執行」或「在 Kubernetes 中偵錯」。
在「Run/Debug on Kubernetes」對話方塊中,指定您偏好的建構工具及其設定。您也可以自訂設定名稱。
按一下「Debug」或「Run」。
如果系統提示,請驗證憑證,以便在本機上執行及偵錯應用程式。
新建立的 skaffold.yaml
和 cloudcode.kubernetes
啟動設定會新增至工作區,應用程式會執行或準備好進行偵錯。
為已含有 skaffold.yaml 的應用程式設定設定
如果應用程式已含有 skaffold.yaml
檔案,請按照下列步驟操作:
在 Cloud Code 狀態列中,按一下目前專案名稱。

在隨即顯示的「快速挑選」選單中,選取「在 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 上提問。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-08 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-07-08 (世界標準時間)。"],[[["Cloud 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."],["If your application lacks Skaffold and launch configurations, Cloud Code guides you through creating them when you first run or debug, including setting up a `skaffold.yaml` and `cloudcode.kubernetes` launch configuration automatically."],["For applications already possessing a `skaffold.yaml`, Cloud Code streamlines the process by allowing you to select the desired `skaffold.yaml` file and Skaffold profile, creating a `cloudcode.kubernetes` launch configuration automatically."],["You can manually create a `skaffold.yaml` 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."],["After the configurations are set, file sync and hot reloading can be used to speed up development and debugging."]]],[]]