Deploy a GKE app by using Cloud Shell

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 check if billing is enabled on a 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 check if billing is enabled on a project.

Create an application

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

  3. Choose Kubernetes application as the application type.

  4. From the list of sample applications (Node.js, Python with 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. After the workspace loads, your app is accessible in the explorer view.

Test your application locally

To run your application in a local Kubernetes cluster in Cloud Code, 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 Code 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.

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

View application logs

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

  1. Open the Command Palette by pressing Cmd/Ctrl+Shift+P and then run the Cloud Code: View Logs command.

    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 Refresh Refresh in the Log Viewer.

Create a GKE cluster

To create a GKE cluster, follow these steps:

  1. To open the Kubernetes Explorer, click Cloud Code - Kubernetes.
  2. 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 Google Cloud console.
  6. In Google Cloud console, configure your cluster.
  7. Click Create. Cluster creation takes a couple minutes.
  8. After the cluster is created, in Kubernetes view, 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.

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

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

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. To open the Kubernetes Explorer, click Cloud Code - Kubernetes.
  2. Hold the pointer over your cluster name and then click Open in Google Cloud console icon Open in Google Cloud console.
  3. Click Delete and then click Delete.

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

  1. Go to the Projects page in the Google 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