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 docker.io/{account}
    Ensure that you are properly authenticated if you are using a private Docker Hub repository.
    Google Container Repository (GCR) gcr.io/{project_id}
    AWS Container Repository (ECR) {aws_account_id}.dkr.ecr.{region}.amazonaws.com/{my-app}
    Azure Container Registry (ACR) {my_acr_name}.azurecr.io/{my-app}

    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.

    Running the Guestbook app and viewing logs returned from the live application

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

    Stop running the Kubernetes application

Storing secrets

If your code includes potentially sensitive data like API keys, passwords, and certificates, it is recommended you store them as secrets. With Cloud Code, you can securely store these secrets in Secret Manager and programmatically fetch them when you need them. For a detailed look at how you can create and manage secrets with Cloud Code, refer to the Secret Manager guide.

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.

Getting Support

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