애플리케이션을 설정하면 Kubernetes 클러스터에서 실행하고 skaffold dev를 사용하여 실시간으로 볼 수 있습니다.
Minikube 또는 Docker Desktop과 같은 로컬 클러스터, Google Kubernetes Engine 또는 다른 클라우드 제공업체에서 애플리케이션을 실행할 수 있습니다.
명령어 팔레트를 열고(Ctrl/Cmd+Shift+P 누르기) Cloud Code: Kubernetes에서 실행 명령어를 실행합니다.
현재의 Kubernetes 컨텍스트를 사용하여 앱을 실행할지 또는 선호하는 컨텍스트로 전환할지 확인합니다. Kubernetes 컨텍스트 설정에 대한 자세한 내용은 구성 설정을 참조하세요.
원격 클러스터를 컨텍스트로 선택한 경우 메시지가 표시되면 이미지를 푸시할 이미지 레지스트리를 선택합니다. Container Registry를 사용하는 경우 기존 레지스트리를 탐색하거나 만들 레지스트리의 이름을 지정할 수 있습니다.
프로젝트에 Artifact Registry API가 사용 설정되어 있고 하나 이상의 Artifact Registry 저장소가 있는 경우 기존 Artifact Registry 저장소를 찾아서 선택할 수 있습니다.
다음 샘플은 몇 가지 일반적인 레지스트리의 경우 컨테이너 이미지가 저장되는 위치를 지정하는 방법을 보여줍니다.
Artifact Registry
{region}-docker.pkg.dev/{project_id}/{repo-name}
Container Registry
gcr.io/{project_id}
Docker Hub
docker.io/{account}
비공개 Docker Hub 저장소를 사용하는 경우 적절하게 인증되었는지 확인합니다.
이 선택사항은 cloudcode.kubernetes 시작 구성(.vscode/launch.json에 있음)에 저장됩니다.
Cloud Code가 컨테이너를 빌드하여 레지스트리로 푸시하고 Kubernetes 구성을 클러스터에 적용하여 출시를 기다립니다.
로그 보기
애플리케이션을 개발하고 실행하는 동안 터미널 출력에서 포드를 실시간 스트림으로 보는 로그 외에 Kubernetes 섹션으로 이동하여 특정 포드의 로그를 볼 수 있습니다.
특정 포드의 로그를 보려면 다음 단계를 따릅니다.
Kubernetes 섹션에서 배포를 펼칩니다.
로그를 보려는 포드를 마우스 오른쪽 버튼으로 클릭한 다음 로그 보기를 클릭합니다.
로그 뷰어가 열립니다.
변경, 다시 빌드, 삭제
시작 구성에서 감시 모드를 false로 설정했고 애플리케이션을 변경한 후 애플리케이션을 다시 빌드하고 다시 배포하려는 경우:
변경사항을 적용하고 저장합니다.
디버그 툴바에서 일시중지(F6)를 클릭한 후 다시 시작(Ctrl/Cmd + Shift + F5)을 클릭하여 애플리케이션을 다시 빌드하고 다시 배포합니다.
애플리케이션 실행을 중지하려면 디버그 툴바에서 중지를 클릭합니다.
애플리케이션을 중지한 후 배포된 모든 Kubernetes 리소스가 클러스터에서 삭제됩니다. 시작 구성에서 cleanUp 플래그를 사용하여 이 동작을 변경할 수 있습니다.
보안 비밀 저장
코드에 API 키, 비밀번호, 인증서와 같이 민감할 수 있는 데이터가 포함된 경우 이를 보안 비밀로 저장하는 것이 좋습니다. Cloud Code를 사용하면 이러한 보안 비밀을 Secret Manager에 안전하게 저장하고 필요할 때 프로그래매틱 방식으로 가져올 수 있습니다.
Cloud Code를 사용하여 보안 비밀을 만들고 관리하는 방법에 대한 자세한 내용은 Secret Manager 가이드를 참조하세요.
리소스 세부정보 보기
Kubernetes 섹션에는 클러스터, 네임스페이스, 노드, 워크로드(예: 배포, 복제본, pod, 컨테이너 등), 서비스 및 인그레스, 구성(보안 비밀, 구성 맵 등), 스토리지(볼륨 등)가 표시됩니다.
Kubernetes 섹션을 사용하면 이러한 리소스 중 일부에 대해 고유한 작업을 수행할 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-12-21(UTC)"],[[["\u003cp\u003eCloud Code facilitates the creation of Kubernetes applications from existing templates or projects, offering a quick start with samples in languages like NodeJS, Go, Python, and Java.\u003c/p\u003e\n"],["\u003cp\u003eThe structure of sample applications includes key files like \u003ccode\u003elaunch.json\u003c/code\u003e for running/debugging, deployment YAML files in \u003ccode\u003ekubernetes-manifests\u003c/code\u003e, source code with \u003ccode\u003eDockerfiles\u003c/code\u003e in \u003ccode\u003esrc\u003c/code\u003e, and the \u003ccode\u003eskaffold.yaml\u003c/code\u003e for build and deployment configurations.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code allows customization of the Kubernetes deployment through the \u003ccode\u003ecloudcode.kubernetes\u003c/code\u003e configuration, where users can define settings for build processes, such as using Docker, Jib, or Buildpacks, and configure the \u003ccode\u003eskaffold.yaml\u003c/code\u003e for application launches.\u003c/p\u003e\n"],["\u003cp\u003eApplications can be run on various Kubernetes clusters, including local setups and cloud-based services, with Cloud Code handling container building, pushing to a designated registry, and deploying configurations to the cluster.\u003c/p\u003e\n"],["\u003cp\u003eUsers can observe live logs directly in the terminal and access specific pod logs via the Kubernetes section, and also includes features for handling secret data, making changes, rebuilding the application, as well as viewing resource details in the Kubernetes section.\u003c/p\u003e\n"]]],[],null,["# Get started with Cloud Code for VS Code for Kubernetes\n\nCloud Code lets you create a Kubernetes application based on a\nsample or from an existing project.\n\nCreate an application from a template\n-------------------------------------\n\nCloud Code comes with a collection of\n[code sample](https://github.com/GoogleCloudPlatform/cloud-code-samples#readme)\ntemplates to get you started quickly. To create a Kubernetes application using\nan existing sample, follow these steps:\n\n1. Launch the Command Palette (press `Ctrl`/`Cmd`+`Shift`+`P` or click **View** \\\u003e **Command Palette** ) and then run **Cloud Code: New Application**.\n2. Select **Kubernetes application** for the type of sample.\n3. Select a sample based on the language you'd like to use from the available options: NodeJS, Go, Python, Java.\n4. Choose a preferred application location on your local machine and then click\n **Create new application** to save.\n\n Cloud Code clones the sample you chose and opens your new\n project for use.\n\n### Sample application structure\n\nAll language sample applications have nearly the same structure. This\nis not the only supported structure but is recommended when starting.\n\nFor example, the Node.js Guestbook application structure looks like: \n\n .\n |---- .vscode\n | └---- launch.json\n |---- kubernetes-manifests\n | |---- guestbook-backend.deployment.yaml\n | |---- guestbook-backend.service.yaml\n | |---- guestbook-frontend.deployment.yaml\n | |---- guestbook-frontend.service.yaml\n | |---- mongo.deployment.yaml\n | └---- mongo.service.yaml\n |---- src\n | |---- backend\n | | |---- Dockerfile\n | | |---- index.js\n | | |---- app.js\n | | └---- package.json\n | |---- frontend\n | |---- Dockerfile\n | |---- index.js\n | | |---- app.js\n | └---- package.json\n └---- skaffold.yaml\n\nTaking a closer look at this Kubernetes Guestbook Node.js sample app, here are\nsome key files and their uses:\n\n- .vscode\n - `extensions.json`: prompt requesting download of related extensions when opening this project\n - `launch.json`: launch configuration (of type `cloudcode.kubernetes`) to run or debug the Kubernetes application\n - `tasks.json`: configuration information for [Visual Studio Code Tasks](https://code.visualstudio.com/docs/editor/tasks)\n- kubernetes-manifests\n - `guestbook-backend.deployment.yaml`: Pod specification for the backend nodes\n - `guestbook-frontend.deployment.yaml`: Pod specification for the frontend nodes\n - `mongo.deployment.yaml`: Pod specification for the database\n- src\n - `(backend|frontend)/app.js`: Node.js code with the web server logic\n - `(backend|frontend)/Dockerfile`: used to build the container image for our program\n- `skaffold.yaml`: config file for [Skaffold](/skaffold), which Cloud Code uses to build, deploy and debug Kubernetes applications\n\nUse your own application\n------------------------\n\nFor steps to use an existing project, see\n[use Cloud Code with an existing Kubernetes application](/code/docs/vscode/use-existing-app).\n| **Note:** For developing and testing an app, create and run the application on a non-production cluster. \n| For changes that will be rolled out to production, use an [automated CI/CD workflow](/docs/ci-cd).\n\nSet your Kubernetes context\n---------------------------\n\nBefore running your application, ensure you're set up to deploy your app to\nyour preferred Kubernetes context. You can specify this in your\n[configuration](#configuration).\n\nConfiguration\n-------------\n\nWhen using the **Cloud Code: Develop on Kubernetes** run configuration, you can\ncustomize your deployment by configuring available settings.\nTo add or edit configurations, go to **Run** \\\u003e **Open Configurations** and then edit or add configurations.\n\nBuild settings\n--------------\n\nCloud Code supports Docker, Jib, and Buildpacks artifact types.\nRefer to the [Configuring container image build preferences guide](/code/docs/vscode/image-build-settings)\nto learn about how to set your preferred builder and its relevant settings.\n\nCustomize your launch configuration\n-----------------------------------\n\nTo configure how your application is run, you can customize your\n[`skaffold.yaml`](https://skaffold.dev/docs/references/yaml) file.\n\nYou can also configure your launch by editing the `cloudcode.kubernetes`\nconfiguration in your `.vscode/launch.json` file.\n\nFor more information on customizing your launch configuration, see the\n[Kubernetes in Cloud Code](/code/docs/vscode/k8s-overview#customize_your_launch_configuration).\n| **Note:** Cloud Code is built to work with [Cloud Build](/build/docs). To build an existing application using Google Cloud infrastructure, see the [Skaffold docs for Cloud Build](https://skaffold.dev/docs/pipeline-stages/builders/docker/#dockerfile-remotely-with-google-cloud-build).\n\nRun your application\n--------------------\n\nOnce you have an application set up, you can run it on a Kubernetes cluster and\nview it live, by leveraging\n[`skaffold dev`](https://skaffold.dev/docs/workflows/dev).\nYou can run your application on a local cluster (like minikube or Docker\nDesktop), Google Kubernetes Engine, or any other Cloud provider.\n| **Note:** If you're working with a private Autopilot cluster, you might run into an image pull error when pulling an image outside of the image registry for your project, such as by using Docker Hub. To resolve this issue, you can either host the image on [Artifact Registry](/artifact-registry/docs/docker/pushing-and-pulling) or provide [outbound internet access for your private nodes](/nat/docs/gke-example#create-nat).\n\n1. Open the Command Palette (press `Ctrl`/`Cmd`+`Shift`+`P`) and then run the **Cloud Code: Run on Kubernetes** command.\n2. Confirm whether to use the current [Kubernetes context](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#context) to run the app in (or switch to a preferred one). For more information about setting up a Kubernetes context, see [setting up configuration](/code/docs/vscode/use-existing-app#setting_up_configuration).\n3. If you chose a remote cluster as the context, when prompted, choose an image\n registry to push the images to. If your project has\n [Artifact Registry API enabled](/artifact-registry/docs/enable-service) and at least one\n [Artifact Registry repository](/artifact-registry/docs/manage-repos), you can\n browse to and select an existing Artifact Registry repository.\n\n The following samples demonstrate how to specify where container images are\n stored for some common registries:\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n Cloud Code concatenates this image registry with the image name\n specified in the Kubernetes manifests to generate the final image repository\n name.\n\n For more information, see the\n [image registry handling guide](https://skaffold.dev/docs/environment/image-registries).\n\n This choice is stored in your `cloudcode.kubernetes` launch configuration\n (found in .vscode/launch.json).\n\n Cloud Code builds your containers, pushes them to the registry,\n applies Kubernetes configurations to the cluster, and waits for the rollout.\n\nView logs\n---------\n\nIn addition to seeing logs from running pods as a live stream in the terminal\noutput as you're developing and running your application, you can view logs from\na specific pod by navigating to the Kubernetes section.\n\nTo view logs from a specific pod, follow these steps:\n\n1. In the Kubernetes section, expand **Deployments**\n2. Right-click the pod you'd like to see logs from, and then click\n **View Logs**.\n\n The **Logs viewer** opens.\n\nMake changes, rebuild, and clean up\n-----------------------------------\n\nIf you've set watch mode to `false` in your launch configuration and you want to make changes to your application and then rebuild and redeploy the application:\n\n\u003cbr /\u003e\n\n1. Make and Save your changes.\n\n2. In the Debug Toolbar, click **Pause** (`F6`) and then click\n **Restart** (`Ctrl/Cmd + Shift + F5`) to rebuild and redeploy the\n application.\n\n3. To stop running the application, in the Debug Toolbar, click **Stop**.\n\nAfter you stop the application, all deployed Kubernetes resources are\ndeleted from the cluster. You can change this behavior using the `cleanUp`\nflag in your launch configuration.\n\nStore secrets\n-------------\n\nIf your code includes potentially sensitive data like API keys, passwords, and\ncertificates, it is recommended you store them as secrets. With\nCloud Code, you can securely store these secrets in\nSecret Manager and programmatically fetch them when you need them.\n\nFor a detailed look at how you can create and manage secrets with\nCloud Code, see the\n[Secret Manager guide](/code/docs/vscode/secret-manager).\n\nView resource details\n---------------------\n\nThe Kubernetes section displays clusters, namespaces, nodes, workloads\n(such as deployments, replicasets, pods and containers), services and ingresses,\nconfigurations (such as secrets and config maps) and storage (such as volumes).\nUsing the Kubernetes section, you can perform unique actions on some\nof these resources.\n\nSee the [Kubernetes overview](/code/docs/vscode/k8s-overview#resource-specific_actions) for more\ninformation on viewing resource details.\n\nWhat's next\n-----------\n\n- [Explore your build options with buildpacks, Jib, or Docker](/code/docs/vscode/image-build-settings).\n- Use [file sync and hot reloading](/code/docs/vscode/speed-up-k8s-development#enable-skaffold-file-sync-and-hot-reloading) to speed up development.\n- Learn more about Cloud Code's [YAML editing](/code/docs/vscode/yaml-editing) assistance.\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)."]]