Running a Kubernetes application

Cloud Code allows you to easily run your application on a Kubernetes cluster and view it live, by leveraging skaffold dev. You can run your application on a local cluster (like Minikube or Docker Desktop), Google Kubernetes Engine, or any other Cloud provider.

Running your application

  1. Choose the Run on Kubernetes command using the Cloud Code status bar.
  2. If your application doesn't have the necessary skaffold configuration or cloudcode.kubernetes launch configuration, Cloud Code will help you set these up.
  3. Confirm whether you'd like to use the current Kubernetes context to run the app in (or switch to a preferred one).
  4. If the context chosen is of a remote cluster, you will be prompted to provide an image registry to push the images to.

    Here are examples of how to specify where container images are stored for some common registries:

    Docker Hub{account}
    Ensure that you are properly authenticated if you are using a private Docker Hub repository.
    Google Container Repository (GCR){project_id}

    Cloud Code concatenates this image registry with the image name specified in the Kubernetes manifests to generate the final image repository name.

    For more information, refer to the image registry handling guide.

    This choice is stored in your cloudcode.kubernetes launch configuration (found in .vscode/launch.json).

  5. Cloud Code then builds your containers, pushes them to the registry, applies Kubernetes configurations to the cluster, and waits for the rollout.

  6. After the completion of rollout, Cloud Code automatically port-forwards all declared container ports to your machine and displays the URLs in the output window so you can browse your live application.

    Port-forwards and displays the URLs in the output window

  7. By default, Cloud Code continuously watches the file system for changes to your files (whether it's Kubernetes config or code), rebuilds the container(s), and redeploys the application to the cluster; so your edits will be reflected in near real-time! You can change this behavior using the watch flag in your launch configuration.

  8. After your session completes, additional contextual menu options are available to monitor your application and its resources using the Cloud Code status bar, including:

    • Open Deployment Logs: Open the application logs of a specific deployment with the Cloud Code Logs Viewer
    • Open Service URL: Open the application service URL of a specific service in a web browser
    • Turn on/off watch mode: Toggle watch mode for the current session (not available for debug sessions)

      Options available via the Cloud Code status bar: Open Deployment Logs, Open Service URL, and Turn on Watch mode, in addition to regular Cloud Code actions

  9. To stop running the application, click the stop icon on the Debug Toolbar.

    Upon termination of the application, all deployed Kubernetes resources will be deleted from the cluster. You can change this behavior using the cleanUp flag in launch configuration.

Customizing launch configuration

To configure how your application is run, you can customize your skaffold.yaml contents as well as specify the following fields in the cloudcode.kubernetes configuration in your .vscode/launch.json:

  • skaffoldConfig: Specify the Skaffold configuration file, that contains the build and deploy settings.
  • profile: Specify your preferred Skaffold profile. If not defined, the default profile is used.
  • imageRegistry: Specify the image registry to push images to.
  • watch: Watches for changes in the workspace and reruns the application. Unless explicitly set to false, true by default.
  • cleanUp: Deletes deployed Kubernetes resources in the cluster after the application is terminated. Unless explicitly set to false, true by default.
  • portForward: Forward ports for exposed Kubernetes resources on your cluster to your local machine. Unless explicitly set to false, true by default.