Working with Google Cloud Platform and Kubernetes YAML

Cloud Code is designed to help make Kubernetes configuration easier, linting schema for both structure and valid values and providing descriptive errors. Additionally, Cloud Code comes with out-of-the-box solutions for common schema, smart completions, and documentation on hover.

Supported YAML configuration files

Additionally, Cloud Code also supports popular Kubernetes CRDs, like Kubeflow, out-of-the-box.

Note: To use the most up-to-date resource aggregation, you will need the latest version of Cloud Code.

Using custom schema

Additionally, with Cloud Code, you can provide your own CRD schema with the cloudcode.yaml.crdSchemaLocations in your settings.json. You can point to either a local file or a URL. URLs pointing to github.com are automatically converted to raw.githubusercontent.com.

Pulling schema from a cluster

When you switch to a cluster running Kubernetes v1.16 and above in the Kubernetes explorer, Cloud Code automatically pulls the schema of all installed CRDs.

Configuring with snippets

Out-of-the-box snippets for common YAML schema (using Command/Ctrl+Space to view options) make it easy to start a new YAML file or add to an existing one without errors, while still following best practices. Additionally, it's easier to work with repetitive fields; fill in one and Cloud Code fills out the remaining instances.

Using snippets with repetitive fields

Currently, the following snippets are offered:

  • 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 for Anthos - Export
  • Migrate for Anthos - PersistentVolumeClaim
  • Migrate for Anthos - StatefulSet
  • Skaffold - Bazel
  • Skaffold - Getting-started
  • Skaffold - Helm deployment
  • Skaffold - Kaniko

Completing with context

Based on the current schema, Cloud Code will provide contextual completions and relevant docs to help you choose the right option.

Context completions for Kubernetes schema

Validating YAML schema

Cloud Code offers schema validation support by flagging invalid tags and values in your YAML files and suggesting fixes when possible.

Value of name field red-underlined to highlight an invalid value of '1234'; hover text states: "Incorrect type. Expected string."

Discovering documentation on hover

Cloud Code surfaces relevant documentation when you hover over a value in the schema.

Documentation info on hover in schema

Accessing resource definitions

Quickly view definitions for resources by right-clicking and choosing 'Go to Definition' or 'Peek Definition'.

Definition info on right-click in schema

Applying a YAML file

To run kubectl apply -f to apply a configuration change using the current file, you can use Cloud Code: Apply the current JSON/YAML file with Kubernetes deployed resource from the Command Palette (accessible from the Manage menu Manage icon) .

This brings up a diff view for you to review changes. Click Apply when prompted whether you'd like to apply this change.

Diffing between YAML files

If you'd like to view the differences between a YAML file in source control and a deployed YAML file, you can use Cloud Code: Diff the current JSON/YAML file with Kubernetes deployed resource from the Command Palette (accessible from the Manage menu Manage icon) . This brings up a diff view for you to compare and contrast two schema files.

Diff view for Kubernetes schema

Performing a dry-run of a YAML file

To perform a dry run of your configuration and check its validity, you can use Cloud Code: Dry-run current config for server-side validation and Cloud Code: Dry-run current config for client-side validation from the Command Palette (accessible from the Manage menu Manage icon) .

Dry-run commands listed from the command palette and Dry-run current config for server-side validation selected

This runs kubectl apply -f dry-run=server (or kubectl apply -f dry-run=client, for the Client option) and displays successful validation (or an error message, if your config file isn't valid) as a toast notification.

In the following example, server-side dry-run validation of the configuration file, hello.deployment.yaml, returns an error when trying to create a deployment because the specified namespace, random-namespace, doesn't exist.

Server-side dry-run validation fails on `hello.deployment.yaml` with an error message displayed as a toast. The details of the error are found in the Output channel; the namespace 'random-namespace' doesn't exist

Working with secrets

Using configuration maps and secrets is a key part of working with Kubernetes. To view the context of a base64 secret with Cloud Code, simply hover over it to decode it.

Decode secret on hover with Cloud Code

Getting Support

To send feedback, report issues on GitHub, or ask a question on Stack Overflow.