Mengembangkan aplikasi Kubernetes dengan pengembangan jarak jauh
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menggunakan Cloud Code untuk VS Code
Pengembangan Jarak Jauh,
yaitu, untuk membuka codebase di penampung jarak jauh tempat aplikasi Anda
di-build, di-debug, dan di-deploy. Tindakan ini akan membuat aplikasi yang portabel,
terlepas dari OS mesin pengembangan Anda.
Untuk menyiapkan folder .devcontainer dengan file Dockerfile dan Devcontainer.json
yang dikonfigurasi untuk bahasa yang Anda gunakan, klik
Buka Jendela Jarak Jauh > Tambahkan File Konfigurasi Penampung Dev.
Atau, Anda dapat mengikuti langkah-langkah dalam
Pengembangan jarak jauh di Penampung.
Setelah Anda mengikuti petunjuk, ruang kerja Anda akan menyertakan:
Dockerfile — menentukan image container yang menyimpan alat developer untuk
diinstal di container pengembangan jarak jauh.
Devcontainer.json — Memberi petunjuk kepada ekstensi VS Code Remote Tools tentang cara menjalankan penampung pengembangan jarak jauh.
Buka Dockerfile dan tambahkan petunjuk untuk menginstal
Google Cloud CLI dan
Skaffold. Untuk perintah terbaru, lihat panduan penginstalan.
Di Dockerfile, tambahkan petunjuk untuk menyalin konfigurasi gcloud CLI dan Skaffold localhost sebelum perintah >> $HOME/.bashrc. Atau,
Anda dapat menulis ulang perintah untuk menginstal gcloud CLI
dan Skaffold.
# Copy localhost's ~/.kube/config file into the container and swap out localhost
# for host.docker.internal whenever a new shell starts to keep them in sync.
RUN echo '\n\
if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then\n\
mkdir -p $HOME/.kube\n\
cp -r $HOME/.kube-localhost/* $HOME/.kube\n\
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config\n\
\n\
fi' \
if [ "$SYNC_LOCALHOST_GCLOUD" == "true" ]; then\n\
mkdir -p $HOME/.config/gcloud\n\
cp -r $HOME/.gcloud-localhost/* $HOME/.config/gcloud\n\
\n\
fi' \
Buka file Devcontainer.json dan tambahkan argumen run berikut untuk menyalin konfigurasi gcloud CLI dan Skaffold dari localhost:
Setelah file Anda memiliki konten yang diperlukan, klik
Buka Jendela Jarak Jauh.
Contoh file devcontainer.json
File devcontainer.json memberi tahu ekstensi Penampung Jarak Jauh port mana yang akan
ditampilkan di penampung, cara memasang drive, dan ekstensi mana yang akan diinstal
di penampung jarak jauh. Contoh file devcontainer.json berikut
menentukan bahwa ekstensi Penampung Jarak Jauh harus menginstal ekstensi Cloud Code untuk VS Code:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-11 UTC."],[[["\u003cp\u003eThis guide outlines how to use Cloud Code for VS Code with Remote Development, enabling the building, debugging, and deployment of applications within a portable remote container.\u003c/p\u003e\n"],["\u003cp\u003eSetting up involves configuring a \u003ccode\u003e.devcontainer\u003c/code\u003e folder with a Dockerfile and \u003ccode\u003eDevcontainer.json\u003c/code\u003e file, tailored to your development language, to define the container's environment.\u003c/p\u003e\n"],["\u003cp\u003eThe Dockerfile should include instructions for installing the Google Cloud CLI and Skaffold, essential tools for working with Cloud Code, which you can add by following the official installation guides.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves copying gcloud CLI and Skaffold configurations from the local host into the container, or rewriting the commands, to synchronize and maintain consistent settings between environments.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDevcontainer.json\u003c/code\u003e file manages the container's settings like exposed ports and extensions, with an example provided that includes the installation of the Cloud Code extension.\u003c/p\u003e\n"]]],[],null,["# Develop a Kubernetes app with remote development\n\n\u003cbr /\u003e\n\nThis page explains how to use Cloud Code for VS Code\n[Remote Development](https://code.visualstudio.com/docs/remote/ssh),\nthat is, to open your codebase in a remote container where your application is\nbuilt, debugged, and deployed. This creates an application that's portable,\nregardless of the OS of your development machine.\n| **Note:** For steps to set up remote debugging on Chrome OS, see [Build a dev workflow with Cloud Code on a Pixelbook](/blog/products/application-development/build-a-dev-workflow-with-cloud-code-on-a-pixelbook).\n\nPrerequisites\n-------------\n\nIn addition to the setup described in\n[Install the Cloud Code extension](/code/docs/vscode/install),\ninstall the\n[Remote Development](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)\nVS Code extension pack.\n\nSetup\n-----\n\n1. To set up a `.devcontainer` folder with a Dockerfile and `Devcontainer.json`\n file configured for the language you're using, click\n **Open a Remote Window** \\\u003e **Add Dev Container Config Files** .\n Alternatively, you can follow the steps in\n [Remote development in Containers](https://code.visualstudio.com/docs/remote/containers-tutorial).\n\n After you follow the prompts, your workspace will include:\n - Dockerfile --- defines a container image that holds the developer tools to\n install in a remote development container.\n\n - `Devcontainer.json` --- Instructs the VS Code Remote Tools extension how to run\n the remote development container.\n\n2. Open the Dockerfile and add instructions to install the\n [Google Cloud CLI](/sdk/docs/downloads-interactive) and\n [Skaffold](https://skaffold.dev/docs/install/). For up-to-date\n commands, see the installation guides.\n\n3. In the Dockerfile, add instructions to copy localhost's\n gcloud CLI and Skaffold configs before the `\u003e\u003e $HOME/.bashrc`\n command. Alternatively,\n you can rewrite the commands to install the gcloud CLI\n and Skaffold.\n\n # Copy localhost's ~/.kube/config file into the container and swap out localhost\n # for host.docker.internal whenever a new shell starts to keep them in sync.\n RUN echo '\\n\\\n if [ \"$SYNC_LOCALHOST_KUBECONFIG\" == \"true\" ]; then\\n\\\n mkdir -p $HOME/.kube\\n\\\n cp -r $HOME/.kube-localhost/* $HOME/.kube\\n\\\n sed -i -e \"s/localhost/host.docker.internal/g\" $HOME/.kube/config\\n\\\n \\n\\\n fi' \\\n if [ \"$SYNC_LOCALHOST_GCLOUD\" == \"true\" ]; then\\n\\\n mkdir -p $HOME/.config/gcloud\\n\\\n cp -r $HOME/.gcloud-localhost/* $HOME/.config/gcloud\\n\\\n \\n\\\n fi' \\\n\n4. Open the `Devcontainer.json` file and add the following run arguments to\n copy the gcloud CLI and Skaffold configs from localhost:\n\n \"-e\", \"SYNC_LOCALHOST_KUBECONFIG=true\",\n \"-e\", \"SYNC_LOCALHOST_GCLOUD=true\",\n\n5. After your files have the required contents, click\n\n **Open a Remote Window**.\n\nSample devcontainer.json file\n-----------------------------\n\nThe `devcontainer.json` file tells the Remote Container extension which ports to\nexpose in the container, how to mount drives, and which extensions to install\nin the remote container. The following sample `devcontainer.json` file\nspecifies that the Remote Container extension should install the\nCloud Code for VS Code extension: \n\n \"runArgs\": [\n \"-v\",\"/var/run/docker.sock:/var/run/docker.sock\",\n \"--mount\", \"type=bind,source=${env:HOME}${env:USERPROFILE}/.kube,target=/root/.kube-localhost\",\n \"--mount\", \"type=bind,source=${env:HOME}${env:USERPROFILE}/.config/gcloud,target=/root/.gcloud-localhost\",\n \"-e\", \"SYNC_LOCALHOST_KUBECONFIG=true\",\n \"-e\", \"SYNC_LOCALHOST_GCLOUD=true\",\n \"--cap-add=SYS_PTRACE\", \"--security-opt\", \"seccomp=unconfined\"\n ]\n\nWhat's next\n-----------\n\n- Read the Visual Studio docs on [remote development using SSH](https://code.visualstudio.com/docs/remote/ssh).\n- Take a tutorial to [run Visual Studio Code in a docker container](https://code.visualstudio.com/docs/devcontainers/tutorial). using the Dev containers extension.\n\nGet Support\n-----------\n\nTo send feedback, report issues on [GitHub](https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues), or ask a question on [Stack Overflow](https://stackoverflow.com/questions/ask?tags=cloud-code-vscode)."]]