Quickstart

This page shows you how to get started quickly with Cloud Code.

You'll set up a new application using a starter 'Hello World' template, create a cluster, deploy your app to this cluster, debug your running code, view logs from your live application, and also, connect a terminal to your running container.

Creating a new Hello World app with Cloud Code

Before you begin

If you'd like to use Google Cloud(GCP), you'll need to create a GCP project and enable billing.

Installing Cloud Code

  1. Install Visual Studio Code on your machine, if you haven't already.
  2. For all Cloud platforms, ensure the Docker client (authenticated with your Docker registry) is installed on the PATH of your machine (its respective folder should be visible under a directory within your PATH). Cloud Code will automatically install kubectl, Skaffold, and Google Cloud SDK.
  3. Install Cloud Code using one of these options:
    • Use this link to open VS Code and install Cloud Code.
    • Open Visual Studio Code on your machine. Using the 'Extensions' view Extension icon in VS Code (its square icon available on the left side taskbar), search for the 'Cloud Code' extension and click 'Install'.
  4. Once the installation is complete, you'll see the Cloud Code Welcome page and a collection of built-in templates under Starter Apps which you can use to quickly set up a new application.

    Extension icon

Creating an application

  1. From the Cloud Code status bar, select New Application. Creating a new app with the Cloud Code status bar
  2. From the list of templates (Node.js, Python (Flask and Django frameworks), Java, Go), choose a Hello World app in a language of your choosing.

    For example, choosing Node.js: Hello World will create a starter Node.js Hello World app.

  3. Confirm your application location (or modify it, if necessary) to proceed.

    A notification will confirm your application has been created and a new window with your application will open.

Creating a Google Kubernetes Engine cluster

To create a GKE cluster, follow these steps:

  1. Navigate to the Kubernetes explorer using the Cloud Code view Cloud Code icon, by clicking on its icon in the VS Code Activity bar on the left.
  2. Authenticate with the Cloud SDK by clicking on 'Click here to log in to Google Cloud SDK'.
  3. Click the '+' button(plus icon) to create a new GKE cluster.
  4. Fill out fields in the Create Cluster wizard and click 'Create Cluster'. Your cluster will be created and listed under the GKE Explorer view Cloud Code icon.

    Creating a new cluster with the GKE explorer

Deploying your app

You can deploy your app using one-time deployment or continuous deployment (in which case your filesystem is watched for changes so that you can edit and redeploy your app in near real-time!).

To deploy your application with continuous deployment, follow these steps:

  1. Use the Cloud Code status bar and select Deploy Application Continuously.
  2. For your build option, select 'default' to build containers using your local Docker.
  3. If you haven't previously defined defaults for your profile, you'll be prompted to choose an image registry and a cluster to associate with your profile.

  4. An output window will appear where you can track the progress of your deployment. You'll also see a live stream of the logs from the running pods within the terminal output.

  5. Once the deployment is successful, the output window will display an IP address. Ctrl/Cmd + click to use this linked address to access your application!

    Continuously deploying the Hello World app

Troubleshooting tips

  1. If Cloud Code is deploying to the wrong project, run gcloud auth application-default login.

    Refer to this issue for more details.

  2. If you're using a pre-existing cluster, run gcloud container clusters get-credentials ${CLUSTER} --zone=${ZONE} to get cluster credentials.

Debugging your app

To debug your application, follow these steps:

  1. Open VS Code's Debug view from the left taskbar Debug icon.
  2. Press the debug start button to attach a debugger session to the hello-world application.

    Cloud Code uses the .vscode/launch.json file to locate the pods to attach a debug session to.

  3. Click in the editor margin of app.js to add a breakpoint.

    Red filled circles denote active breakpoints, while gray hollow circles signify disabled breakpoints. For finer breakpoint control, you can use the Breakpoints section in VS Code's Debug view.

    Breakpoints section in the left hand panel of Debug View that allows adding, removing, and disabling breakpoints

    When you send a new request to your application, it will pause at that desired line.

    Setting a breakpoint and starting the debugger

  4. (Optional) To inspect variables and stack info, use the Debug Sidebar.

    To interact with the debugging session, use the Debug Console in the bottom pane debugger.

Viewing logs

While you can see a live stream of the logs from running pods within the terminal output from your continuous deployment, you can also view logs with the Log Viewer that comes with Cloud Code.

To view logs, follow these steps:

  1. Launch the Log Viewer by typing Cloud Code: View Logs using the Command Palette (accessible with Ctrl/Cmd+Shift+P or through the 'Manage' menu marked with a gear icon Manage icon).

  2. Search for the deployment, in this case 'node-hello-world', to view logs from using the deployment field in the Log Viewer search box.

    Viewing logs for a non-Stackdriver Logging cluster by setting the deployment field within the Log Viewer search box to 'node-hello-world'

Bonus: Opening a terminal in your container

Additionally, if you'd like to open a terminal in your container, follow these instructions:

  1. Navigate to the Cluster Explorer.
  2. Select the cluster and from the underlying Pods section, the pod you'd like to connect to.
  3. Under your specified pod, expand your Containers section and right-click the container in which you'd like to open a terminal.
  4. Select Get Terminal.

    This will launch a terminal; you now have access to a shell inside the running container!

    Opening a terminal for the specified pod

Cleaning up

To avoid incurring charges to your account for the resources used in this quickstart, be sure to delete the cluster and project you created.

If you're using Google Cloud and would like to delete just your cluster, you can do so by:

  • Using the Kubernetes explorer under the Cloud Code view Cloud Code icon, right click the cluster you'd like to delete from the Google Kubernetes Engine Explorer pane and select 'Delete cluster'.

To delete your project (and associated resources, including any clusters):

  • Go to the Projects page in the Cloud Console:

    Go to the Projects page

  • Select the project you created for this Quickstart and click on the trash can icon next to delete it.

    This shuts down the project and schedules it for deletion.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Code for VS Code