Google Cloud Shell

  1. Home
  2. Google Cloud Shell

Go back to GCP Tutorials

Google Cloud Shell is an interactive shell environment for Google Cloud that makes it easy for you to learn and experiment with Google Cloud and manage your projects and resources from your web browser.

With Cloud Shell, the Cloud SDK gcloud command-line tool and other utilities you need are pre-installed, fully authenticated, up-to-date, and always available when you need them. Additionally, Cloud Shell comes with a built-in code editor with an integrated Cloud Code experience, allowing you to develop, build, debug, and deploy your cloud-native apps entirely in the Cloud.

Running gcloud commands with Cloud Shell

Cloud Shell comes with Cloud SDK pre-installed. This means you can run gcloud commands without additional setup. You can run gcloud command-line tool commands, like gcloud help straight away after activating a Cloud Shell session. Additionally, any time you manage resources using the interactive interface from the Console, you can generate the equivalent gcloud command and run it in Cloud Shell. However, if you fill in the details of your required resource during tasks like the creation of an instance group or a Kubernetes cluster, the generated command will contain the correct flags and their values.

Example: Creating a Compute Engine instance with a generated gcloud command
  • Firstly, go to the Compute Engine > VM instances page.
  • Secondly, click Create.
  • Thirdly, fill in the required and optional fields to configure the new instance to suit your needs.
  • Then, below the Create button, you’ll find the option to generate the equivalent REST or gcloud command. Click on command line to see the suggested gcloud command.
  • Next, click Run in Cloud Shell.
  • After that, press Enter to execute the command once you see it at the prompt.
  • Going back to the VM instances page, you’ll see the newly created and running VM instance.
  • Lastly, delete the instance either from the command line or the VM instances page, if you no longer need it, to avoid incurring unnecessary charges.

Running a Kubernetes Engine application with Cloud Code

You’ll set up a new Kubernetes application using a starter ‘Hello World’ template, build and test the app locally, create a Google Kubernetes Engine cluster, run your app on this cluster, debug your running code, and view your live application.

Creating an application
  • Firstly, directly launch the Cloud Shell Editor.
  • Secondly, from the Cloud Code status bar, select New Application.
  • Thirdly, choose ‘Kubernetes application’ as your preferred application type.
  • Then, 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 to Go: Hello World will create a starter Go Hello World app.
  • Lastly, select a folder as your application location to proceed and click ‘Create New Application’.
    • Cloud Shell Editor loads the application in a new workspace. Once reloaded, your app is accessible in the explorer view.
gcp cloud architect practice tests
Testing your application locally

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

  • In your terminal, run the following command:
    • minikube start
  • When your minikube cluster is ready, click on the Cloud Code status bar and select Run on Kubernetes. Confirm that you want to use the minikube context.
  • If prompted, authorize Cloud Shell to make Google Cloud API calls.
  • As your app is being built, you can monitor its progress in the Output Panel. Once 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:

  • With the Explorer view, find the main.go file under cmd > hello-world folder.
  • Modify “Hello, world!” to a message of your choosing.
  • Once you make this change, you’ll notice your app being rebuilt by the logs in your Output panel.
  • When your app finishes building and deploying, launch it from the link in your 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:

  • 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.
  • Select ‘Deployment’ or ‘Pod’ to see the logs for your app.
  • Refresh your app in the browser, and see the new logs generated by clicking the Logs refresh button.
Google Cloud Shell GCP cloud architect  online course

Reference: Google Documentation

Go back to GCP Tutorials

Menu