Kubernetes-Anwendung mit Remote-Entwicklung entwickeln
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite wird beschrieben, wie Sie Cloud Code for VS Code für die Remote-Entwicklung verwenden, d. h. wie Sie Ihre Codebasis in einem Remote-Container öffnen, in dem Ihre Anwendung erstellt, debuggt und bereitgestellt wird. Dadurch wird eine portable Anwendung erstellt, unabhängig vom Betriebssystem Ihres Entwicklungsrechners.
Wenn Sie einen .devcontainer-Ordner mit einem Dockerfile und einer Devcontainer.json-Datei für die von Ihnen verwendete Sprache einrichten möchten, klicken Sie auf Remote-Fenster öffnen > Konfigurationsdateien für Entwicklungscontainer hinzufügen.
Alternativ können Sie der Anleitung unter Remote-Entwicklung in Containern folgen.
Nachdem Sie den Anweisungen gefolgt sind, enthält Ihr Arbeitsbereich Folgendes:
Dockerfile: Hiermit wird ein Container-Image definiert, das die Entwicklertools enthält, die in einem Remote-Entwicklungscontainer installiert werden sollen.
Devcontainer.json: Gibt an, wie die VS Code-Erweiterung „Remote-Tools“ den Remote-Entwicklungscontainer ausführen soll.
Öffnen Sie die Dockerfile und fügen Sie eine Anleitung zum Installieren der Google Cloud CLI und Skaffold hinzu. Aktuelle Befehle finden Sie in den Installationsanleitungen.
Fügen Sie in der Dockerfile eine Anleitung zum Kopieren der gcloud CLI- und Skaffold-Konfigurationen von localhost vor dem Befehl >> $HOME/.bashrc hinzu. Alternativ können Sie die Befehle zum Installieren der gcloud CLI und Skaffold neu schreiben.
# 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' \
Öffnen Sie die Datei Devcontainer.json und fügen Sie die folgenden Ausführungsargumente hinzu, um die gcloud-CLI und die Skaffold-Konfigurationen von localhost zu kopieren:
Nachdem Sie die erforderlichen Inhalte in die Dateien kopiert haben, klicken Sie auf Remote-Fenster öffnen.
Beispieldatei „devcontainer.json“
Die Datei devcontainer.json gibt der Remote Container-Erweiterung an, welche Ports im Container freigegeben werden sollen, wie Laufwerke bereitgestellt werden und welche Erweiterungen im Remote-Container installiert werden sollen. In der folgenden Beispieldatei devcontainer.json wird angegeben, dass die Remote-Container-Erweiterung die Cloud Code-Erweiterung für VS Code installieren soll:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-05 (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)."]]