Running a Kubernetes Engine application with Cloud Code

Learn how to set up a simple Kubernetes app, run the app on a Google Kubernetes Engine (GKE) cluster, and view and debug your running code.


For step-by-step guidance on this task directly in Cloud Shell Editor, click Guide me:

Guide me


The following sections take you through the same steps as clicking Guide me.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  4. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

Creating an application

  1. Launch the Cloud Shell Editor.
  2. From the Cloud Code status bar, select New Application.

    Clicking the Cloud Code status bar and choosing New Application

  3. Choose Kubernetes application as the application type.

  4. From the list of templates (Node.js, Python (Flask and Django frameworks), Java, Go), choose a Hello World app.

    For example, choosing Go: Hello World creates a starter Go Hello World app.

  5. Select a folder as your application location and then click Create New Application.

    Cloud Shell Editor loads the application in a new workspace. Once reloaded, your app is accessible in the explorer view.

Testing your application locally

To run your application in a local Kubernetes cluster in Cloud Shell, follow these steps:

  1. In your terminal, run the following command:

    minikube start
    
  2. When your minikube cluster is ready, click the Cloud Code status bar and select Run on Kubernetes. Confirm that you want to use the minikube context.

  3. If prompted, authorize Cloud Shell to make Google Cloud API calls.

  4. As your app is being built, you can monitor its progress in the Output Panel. After it's built, you can launch the app with the link displayed in your Output panel.

Editing your application

To edit your application, follow these steps:

  1. With the Explorer view, find the main.go file under cmd > hello-world folder.
  2. Modify "Hello, world!" to a message of your choosing.

    After you make this change, you'll notice your app being rebuilt by the logs in the Output panel.

  3. When your app finishes building and deploying, launch it from the link in the Output panel to view your updated application.

Viewing application logs

To analyze your application while it's running, you can access its logs using the Log Viewer:

  1. Launch the Log Viewer by typing "Cloud Code: View Logs" using the Command Palette (accessible with Ctrl/Cmd+Shift+P).

    This view allows you to filter and navigate the logs for your app.

  2. Select Deployment or Pod to see the logs for your app.

  3. Refresh your app in the browser and see the new logs that were generated by clicking the Logs refresh button.

Creating a GKE cluster

To create a GKE cluster, follow these steps:

  1. To open the Kubernetes Explorer, click Kubernetes Explorer icon Cloud Code - Kubernetes.
  2. In the header of the Kubernetes Explorer pane, click + Add a Cluster to the KubeConfig.
  3. Choose Google Kubernetes Engine and then click + Create a new GKE Cluster.
  4. Choose Standard or Autopilot as the cluster type.
  5. Click Open to permit Cloud Code to open the Cloud Console.
  6. In Cloud Console, configure your cluster.
  7. Click Create. Cluster creation takes a couple minutes.
  8. After the cluster is created, in Kubernetes Explorer, click Refresh Kubernetes cluster view Refresh.
  9. After the name of your new cluster appears in the list, click the cluster name. Your new cluster is added to the configuration and configured to be the active context.

Running your app

You can now run your application and view it live. Additionally, Cloud Code watches your filesystem for changes so that you can edit and rerun your app in near real-time.

To run your application, follow these steps:

  1. Use the Cloud Code status bar and select Run on Kubernetes.
  2. Confirm that you're using your new cluster as context for your app.
  3. Depending on the context chosen, you might be prompted to choose an image registry to push the images to.
  4. In the Output Panel, you can track the progress of your running application.
  5. After your application is running, the output window displays an IP address. Ctrl/Cmd + click to use this linked address to access your application!

    Output window with IP address link to live Hello World application

Cleaning up

After you stop your application, all Kubernetes resources deployed during the run are deleted automatically. To avoid incurring charges to your account for other resources used in this quickstart, be sure to delete the project or the cluster you created.

To delete just your cluster, follow these steps:

  1. In the Kubernetes Explorer, hover over your cluster name and then click Open in Cloud Console icon Open in Cloud Console.
  2. Click Delete and then click Delete.

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

  1. Go to the Projects page in the Cloud Console:

    Go to the Projects page

  2. Select the project that you created for this quickstart and then click Delete.

  3. Type the project ID to confirm and then click Shut down.

    This shuts down the project and schedules it for deletion.

What's next