Cloud Shell용 Cloud Code에서 Google Cloud 및 Kubernetes YAML 작업
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Cloud Shell용 Cloud Code는 구조 및 유효한 값 모두에 대한 스키마를 린트하고 자세한 오류를 제공하여 Kubernetes 및 Cloud Build 구성을 쉽게 만들 수 있도록 설계되어 있습니다. 일반 스키마, 스마트 완성, 마우스를 가져가면 열리는 문서 등 바로 사용할 수 있는 솔루션이 Cloud Code에 함께 제공됩니다.
또한 Cloud Code는 Kubeflow와 같이 즉시 구성 가능한 인기 있는 Kubernetes 커스텀 리소스 정의(CRD)를 지원합니다.
커스텀 스키마 사용
Cloud Code를 사용하면 settings.json 파일에서 cloudcode.yaml.crdSchemaLocations 설정으로 자체 CRD 스키마를 제공할 수 있습니다.
로컬 파일 또는 URL을 가리킬 수 있습니다. github.com을 가리키는 URL은 자동으로 raw.githubusercontent.com으로 변환됩니다.
클러스터에서 스키마 가져오기
Kubernetes 뷰에서 Kubernetes v1.16 이상을 실행하는 클러스터로 전환하면 Cloud Code는 설치된 모든 CRD의 스키마를 자동으로 가져옵니다.
스니펫으로 구성
일반 YAML 스키마에 바로 사용할 수 있는 스니펫(옵션을 보려면 Command/Ctrl+Space 사용)으로 권장사항을 따르면서 손쉽게 새로운 YAML 파일을 시작하거나 오류 없이 기존 YAML 파일에 추가할 수 있습니다. Cloud Code를 사용하면 첫 번째 필드를 작성한 후 남은 인스턴스를 작성하여 반복 필드를 더 쉽게 사용할 수 있습니다.
Cloud Code는 다음 스니펫을 제공합니다.
Anthos Config Management - Cluster
Anthos Config Management - Cluster Selector
Anthos Config Management - Config Management
Anthos Config Management - Namespace Selector
Cloud Build - Cloud Run deployment
Cloud Build - Docker container build
Cloud Build - GKE deployment
Cloud Build - GKE Skaffold deployment
Cloud Build - Go build
Cloud Build - Terraform plan + apply
Config Connector - BigQueryDataset
Config Connector - BigQueryTable
Config Connector - BigtableCluster
Config Connector - BigtableInstance
Config Connector - PubSubSubscription
Config Connector - PubSubTopic
Config Connector - RedisInstance
Config Connector - SpannerInstance
Kubernetes - ConfigMap
Kubernetes - Deployment
Kubernetes - Ingress
Kubernetes - Pod
Kubernetes - Secret
Kubernetes - Service
Migrate to Containers - Export
Migrate to Containers - PersistentVolumeClaim
Migrate to Containers - StatefulSet
Skaffold - Bazel
Skaffold - Getting-started
Skaffold - Helm deployment
Skaffold - Kaniko
컨텍스트 완성
현재 스키마에 따라 Cloud Code는 상황별 완료와 적합한 옵션을 선택하는 데 유용한 관련 문서를 제공합니다.
YAML 스키마 검사
Cloud Code는 YAML 파일의 잘못된 태그와 값을 표시하고 가능한 경우 수정을 제안하여 스키마 유효성 검사 지원을 제공합니다.
마우스를 가져가면 열리는 문서
스키마의 값 위에 포인터를 두면 Cloud Code에서 관련 문서가 표시됩니다.
리소스 정의 액세스
리소스의 정의를 보려면 리소스를 마우스 오른쪽 버튼으로 클릭한 후 정의로 이동 또는 정의 미리보기를 선택합니다.
YAML 파일 적용
현재 파일을 사용하여 구성 변경사항을 적용하려면 명령어 팔레트를 연 다음(Ctrl/Cmd+Shift+P 키를 누르거나 뷰 > 명령어 팔레트 클릭) Cloud Code: Apply Current JSON/YAML File to K8s Deployed Resource를 실행합니다.
이 명령어는 변경사항을 검토할 수 있는 차이점 뷰를 표시합니다. 변경사항을 적용할 것인지 묻는 확인 창이 표시되면 적용을 클릭합니다. 그러면 kubectl apply -f가 실행됩니다.
YAML 파일 간 차이점 보기
소스 제어의 YAML 파일과 배포된 YAML 파일 간의 차이점을 보려면 명령어 팔레트를 연 다음(Ctrl/Cmd+Shift+P 키를 누르거나 뷰 > 명령어 팔레트 클릭) Cloud Code: Diff Current JSON/YAML File with K8s Deployed Resource를 실행합니다.
YAML 파일의 테스트 실행 수행
Cloud Code는 YAML 파일에 정보를 입력할 때 테스트 실행을 자동으로 수행하고 노란색 구불구불한 선으로 오류에 밑줄을 표시합니다.
서버가 예비 실행 결과를 기반으로 코드의 일부를 오류로 간주하면 노란색 물결선이 표시됩니다. 여기에는 정책 위반, 중복 이름 또는 Cloud Code가 클라이언트 측에서 수행하지 않는 유효성 검사(예: 최대 포트 번호)가 포함될 수 있습니다.
YAML 파일에서 오류 설명을 보려면 노란색 밑줄이 그어진 코드 위로 포인터를 가져갑니다.
Cloud Code가 Kubernetes 서버를 확인하기 전에 감지된 오류에 빨간색 물결선이 표시됩니다. 예를 들어 문자열이 있어야 할 자리에 숫자를 입력하면 빨간색 물결선이 표시됩니다.
보안 비밀로 작업하기
구성 맵과 보안 비밀의 사용은 Kubernetes 작업에서 중요한 부분입니다. Cloud Code에서 Base64 보안 비밀의 컨텍스트를 보려면 보안 비밀 위에 포인터를 두어 디코딩합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eCloud Code enhances Kubernetes and Cloud Build configuration by offering schema linting, smart completions, and documentation hover features for various YAML files.\u003c/p\u003e\n"],["\u003cp\u003eIt supports multiple YAML configuration file types, including Config Management, Cloud Build, Config Connector, Istio, Knative, Kubernetes, Kustomize, and Skaffold, as well as custom resource definitions (CRDs) like Kubeflow.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code allows users to define custom CRD schemas via the \u003ccode\u003ecloudcode.yaml.crdSchemaLocations\u003c/code\u003e setting and automatically pulls schema from clusters running Kubernetes v1.16 or later.\u003c/p\u003e\n"],["\u003cp\u003eIt provides out-of-the-box snippets for common YAML schema, facilitating the creation and modification of YAML files with best practices, including snippets for Anthos Config Management, Cloud Build, Config Connector, Kubernetes, Migrate to Containers, and Skaffold.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code offers features like contextual completions, documentation access on hover, schema validation with error flagging, and the ability to view differences between YAML files, apply changes, and perform dry-runs, all within the development environment.\u003c/p\u003e\n"]]],[],null,["# Work with Google Cloud and Kubernetes YAML in Cloud Code for Cloud Shell\n\nCloud Code for Cloud Shell is designed to make Kubernetes and Cloud Build\nconfiguration easier by linting schema for both structure and valid values and\nproviding descriptive errors. Cloud Code comes with out-of-the-box\nsolutions for common schema, smart completions, and documentation on hover.\n| **Note:** Cloud Build YAML editing support is only available for files named `cloudbuild.yaml`.\n\nSupported YAML configuration files\n----------------------------------\n\n- [Config Management](/anthos-config-management/docs/how-to/configs)\n- [Cloud Build](/build/docs/build-config)\n- [Config Connector](/config-connector/docs/overview)\n- [Istio](https://istio.io/docs/setup/getting-started/)\n- [Knative](https://knative.dev/docs/)\n- [Kubernetes](https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/)\n- [Kustomize](https://github.com/kubernetes-sigs/kustomize)\n- [Skaffold](https://skaffold.dev/docs/references/yaml/)\n\nCloud Code also supports popular Kubernetes custom resource\ndefinitions (CRDs), like\n[Kubeflow](https://www.kubeflow.org/docs/about/kubeflow/), out-of-the-box.\n\n### Use custom schema\n\nWith Cloud Code, you can provide your own CRD schema with the\n`cloudcode.yaml.crdSchemaLocations` setting in your\n[`settings.json`](https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations)\nfile.\nYou can point to either a local file or a URL. URLs pointing to `github.com` are\nautomatically converted to `raw.githubusercontent.com`.\n\n### Pull schema from a cluster\n\nWhen you switch to a cluster running Kubernetes v1.16 and later in the\nKubernetes view, Cloud Code automatically pulls the schema of\nall installed CRDs.\n\nConfigure with snippets\n-----------------------\n\nOut-of-the-box snippets for common YAML schema (using `Command/Ctrl+Space` to\nview options) make it easy to start a new YAML file or add to an existing one\nwithout errors, while still following best practices. Cloud Code\nmakes it easier to work with repetitive fields by filling out the remaining\ninstances after you fill in the first field.\n\nCloud Code offers the following snippets:\n\n- `Anthos Config Management - Cluster`\n- `Anthos Config Management - Cluster Selector`\n- `Anthos Config Management - Config Management`\n- `Anthos Config Management - Namespace Selector`\n- `Cloud Build - Cloud Run deployment`\n- `Cloud Build - Docker container build`\n- `Cloud Build - GKE deployment`\n- `Cloud Build - GKE Skaffold deployment`\n- `Cloud Build - Go build`\n- `Cloud Build - Terraform plan + apply`\n- `Config Connector - BigQueryDataset`\n- `Config Connector - BigQueryTable`\n- `Config Connector - BigtableCluster`\n- `Config Connector - BigtableInstance`\n- `Config Connector - PubSubSubscription`\n- `Config Connector - PubSubTopic`\n- `Config Connector - RedisInstance`\n- `Config Connector - SpannerInstance`\n- `Kubernetes - ConfigMap`\n- `Kubernetes - Deployment`\n- `Kubernetes - Ingress`\n- `Kubernetes - Pod`\n- `Kubernetes - Secret`\n- `Kubernetes - Service`\n- `Migrate to Containers - Export`\n- `Migrate to Containers - PersistentVolumeClaim`\n- `Migrate to Containers - StatefulSet`\n- `Skaffold - Bazel`\n- `Skaffold - Getting-started`\n- `Skaffold - Helm deployment`\n- `Skaffold - Kaniko`\n\nComplete with context\n---------------------\n\nBased on the current schema, Cloud Code provides contextual\ncompletions and relevant docs to help you choose the right option.\n\nValidate YAML schema\n--------------------\n\nCloud Code offers schema validation support by flagging invalid tags\nand values in your YAML files and suggesting fixes when possible.\n\nDiscover documentation on hover\n-------------------------------\n\nCloud Code surfaces relevant documentation when you hold the\npointer over a value in the schema.\n\nAccess resource definitions\n---------------------------\n\nTo view definitions for a resource, right-click the resource and then choose\n**Go to Definition** or **Peek Definition**.\n\nApply a YAML file\n-----------------\n\nTo apply a configuration change using the current file, open the command\npalette (press `Ctrl`/`Cmd`+`Shift`+`P` or click **View** \\\u003e **Command Palette** )\nand then run **Cloud Code: Apply Current JSON/YAML File to K8s Deployed Resource**.\n\nThis command brings up a diff view for you to review changes. Click **Apply**\nwhen prompted whether to apply this change. This runs\n[`kubectl apply -f`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply).\n\nView differences between YAML files\n-----------------------------------\n\nTo view the differences between a YAML file in source control and a deployed\nYAML file, open the command palette (press `Ctrl`/`Cmd`+`Shift`+`P` or click\n**View** \\\u003e **Command Palette** ) and then run\n**Cloud Code: Diff Current JSON/YAML File with K8s Deployed Resource**.\n\nPerform a dry-run of a YAML file\n--------------------------------\n\nCloud Code performs dry runs automatically as you type information\nin your YAML file and underlines any errors with a yellow squiggly line.\n\nYellow squiggly lines appear when the server considers a part of your code\nan error based on the result of a dry run. This can include policy violations,\nduplicate names, or validations that Cloud Code doesn't perform on\nthe client side (like max port numbers).\n\nTo view the description of the error in your YAML file, hold your pointer over\nthe code with a yellow underline.\n\nRed squiggly lines appear for detected errors before Cloud Code\nchecks with the Kubernetes server. For example, putting a number where a string\nis expected triggers a red squiggly line.\n\nWork with secrets\n-----------------\n\nUsing configuration maps and\n[secrets](https://kubernetes.io/docs/concepts/configuration/secret/)\nis a key part of working with Kubernetes. To view the context of a base64\nsecret with Cloud Code, hold the pointer over the secret to decode\nit.\n\nWhat's next\n-----------\n\n- Create a [Cloud Code Kubernetes run configuration](/code/docs/shell/use-existing-app#set_up_kubernetes_run_configuration) `skaffold.yaml` file.\n- Manually create a [Skaffold configuration](/code/docs/shell/use-existing-app#manually_create_a_skaffold_configuration) for your application.\n- View the [`Skaffold.yaml` reference docs](https://skaffold.dev/docs/references/yaml/)."]]