Shape the future of software delivery and make your voice heard by taking the 2021 State of DevOps survey.

Working with Google Cloud and Kubernetes YAML files

Cloud Code is designed to help with editing Google Cloud and Kubernetes-related configuration files, including schema based validation, diagnostics, and quick documentation.

Supported YAML configuration files

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

Using custom schema

Additionally, with Cloud Code, you can provide your own CRD schema with IntelliJ settings (File > Settings > Tools > Cloud Code > Kubernetes or for Mac OS X, IntelliJ IDEA > Preferences > Tools > Cloud Code > Kubernetes and navigate to the CRD Schema Locations section).

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.

Additional Skaffold support

Skaffold is the underlying engine that powers Cloud Code, helping you build, push, and deploy your application as well as providing support for creating CI/CD pipelines.

Cloud Code comes with additional support for managing Skaffold configuration files. On opening a project, Cloud Code detects Skaffold schemas that aren't up-to-date and prompts you (via the Event Log) when a Skaffold schema version upgrade is available for your existing Skaffold YAML configuration files.

Notification in the Event log prompting user to upgrade their Skaffold schema version because their existing Skaffold YAML files are not of the latest version

Alternatively, you can navigate to Tools > Cloud Code > Kubernetes and select Check for Skaffold Schemas Upgrades to check for available schema upgrades.

Configuring with snippets

Out-of-the-box snippets for common YAML schema (using 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:

  • 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 - 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 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."

Validating Skaffold YAML files

Cloud Code provides additional Skaffold configuration file editing support and smart templates allowing you to easily validate your skaffold.yaml files. Refer to this guide on using an existing app with Cloud Code.

Skaffold yaml templates

Completing Skaffold configuration files with context

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

Skaffold completions

Enabling Skaffold file sync and hot reloading

To improve the efficiency of your local development workflow and avoid having to rebuild, redeploy, and restart your pods, Skaffold supports copying changed files to a deployed container. This means that when you're making changes to static and source code files, you can see your changes take effect in a matter of seconds, making for an accelerated feedback loop!

For static files (like HTML and CSS files), this file copying behavior is called file syncing.

For source code files, this behavior is referred to as hot reloading and works for the following file types:

  • Go: *.go
  • Java: *.java, *.kt, *.scala, *.groovy, *.clj
  • NodeJS: *.js, *.mjs, *.coffee, *.litcoffee, *.json

With hot reloading configured, Skaffold detects changes to supported files and syncs these changes to the running container on your cluster, bypassing the need for a cumbersome image rebuild and pod restart. Changes to other file types, however, trigger an image rebuild.

Automatic file-syncing and hot reloading are enabled by default when you're working with Buildpacks as your preferred builder. For other builders like Docker, you can specify a sync section in your skaffold.yaml for the artifact you're customizing.

Your sync setting can be one of (in order of preference):

  • auto (only for Jib and Buildpacks artifacts)
  • infer
  • manual

If you were to specify a manual sync to synchronize all /static-html HTML files to the static folder in your container, your skaffold.yaml would contain this sync section:

build:
  artifacts:
    - image: gcr.io/k8s-skaffold/node-example
      context: node
      sync:
        manual:
          - src: 'static-html/*.html'
            dest: static

For a detailed look at file syncing and specifying sync rules, refer to the Skaffold guide on file sync.

Discovering definitions via quick documentation

Cloud Code surfaces relevant documentation for a resource when you highlight a line in your configuration file and access View > Quick Documentation.

Quick documentation

Linting YAML for structural and validity issues

Cloud Code provides linting support around common schema issues and provides descriptive errors.

Linting YAML files

Applying a YAML file

To run kubectl apply -f to apply a configuration change using the current file, you can use the kubectl actions icon kubectl actions icon, available in the gutter of your IDE and select Apply. This brings up a diff view for you to review changes before clicking Apply.

Apply option highlighted in the kubectl action list

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 the kubectl actions icon kubectl actions icon available in the gutter of your editor. Choose the Diff option to bring up a diff view for you to compare and contrast two schema files.

Diff option highlighted in the kubectl action list

Performing a dry-run of a YAML file

To perform a dry run of your file and check its validity, you can use the kubectl actions icon kubectl actions icon, available in the gutter of your IDE, to select Dry-run on Server or Dry-run on Client. This runs kubectl apply -f dry-run=server (or kubectl apply -f dry-run=client, for the Client option) and notifies you if your file can successfully be created in your Terminal window.

Dry-run on Server option highlighted in the kubectl action list

Getting support

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