Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Cloud Shell😶‍🌫️
2.
Use Cloud Shell💡
2.1.
Start a new session
2.2.
Use the terminal
2.3.
Use the Cloud Shell Editor
2.4.
Choose ephemeral mode
3.
Launch the Cloud Shell Editor💯
3.1.
Launch a standalone Cloud Shell Editor session
3.2.
Launch Cloud Shell Editor from the console
3.3.
Launch from the Cloud Shell terminal
4.
Cloud Shell Editor interface🖥️
4.1.
Viewing and editing files
4.2.
Uploading and downloading files
4.3.
Activity bar
5.
Configure Cloud Shell🎯
5.1.
Configuration files in your Cloud Shell home directory
5.2.
Pre-configured environment variables
6.
Disable or reset Cloud Shell🧑‍💻
6.1.
Disable Cloud Shell for managed user accounts
6.2.
Reset Cloud Shell
7.
Create and deploy a containerized web app🌐
7.1.
Create your web app
7.2.
Create a Google Kubernetes Engine cluster
7.3.
Deploy your app to a GKE cluster
7.4.
Cleaning up
8.
Frequently Asked Questions❓
8.1.
What is a cloud shell?
8.2.
How do I access the cloud shell?
8.3.
Is cloud shell free?
8.4.
How do cloud shells work?
8.5.
What is cloud shell storage?
9.
Conclusion
Last Updated: Mar 27, 2024

 Cloud Shell

Author Anju Jaiswal
0 upvote

Cloud Shell😶‍🌫️

Hi Ninjas!🥷 We are going to understand a critical topic, Cloud Shell. It is an interactive Google Cloud shell environment that enables you to explore Google Cloud, learn about it, and manage your resources and projects from a web browser.

Cloud Shell

For users with a Google Cloud account, Cloud Shell is free. While Google Cloud Console is a temporary virtual machine, Cloud Shell is a locally installed tool.

Use Cloud Shell💡

In this section, we'll go over how to launch and configure a new Cloud Shell session.

Start a new session

On the Google Cloud console's top menu, select Activate Cloud Shell 

A command-line prompt is shown when a Cloud Shell session launches in a new frame at the bottom of the console. The initialization of the session may take a few seconds.

Use the terminal

A terminal window opens in the console and offers command-line access to the virtual machine instance through Cloud Shell.

You can use the cloud shell command to start tutorials, open the Cloud Shell Editor, and download files, and use it to access the Google Cloud CLI and other command-line tools.

Use the Cloud Shell Editor

The convenience of  editing and viewing files in the exact location where projects are developed and deployed is made possible by the built-in code editor. By selecting Open Editor from the toolbar of the Cloud Shell window, the Cloud Shell Editor is opened.

Choose ephemeral mode

On your temporarily assigned virtual machine, Cloud Shell preloads 5 GB of free persistent disc storage by default. Your $HOME directory is shown here. The files in your home directory remain accessible between sessions when you use the standard Cloud Shell experience.

Use Cloud Shell in ephemeral mode if persistent storage is not a requirement. Ephemeral mode requires less setup and has no disc attachment or archive, so you can use Cloud Shell more quickly. However, this implies that all files you produce while using ephemeral mode are deleted along with the virtual machine when the session expires.

Add ephemeral=true to the URL to select ephemeral mode, or open the Cloud Shell More menu, select Ephemeral mode, and click Save.

Always start Cloud Shell in ephemeral mode before clicking Save to make ephemeral mode your default for Cloud Shell.

Resize the browser window.

To change the display window:

  1. To hide or restore the session display, click Hide Shell Button Hide or Restore Shell Button Restore.
  2. To open the session in a new window, click Detach Shell Button Open Session in New Window.
  3. At the top of the console window to close the detached window and restart the console session Activate Cloud Shell.
  4. Select Settings Button Settings, then select either Switch to Light Theme or Switch to Dark Theme.

Launch the Cloud Shell Editor💯

To best suit your use case, the Cloud Shell Editor can be launched in a variety of ways.

Launch a standalone Cloud Shell Editor session

Directly launching a Cloud Shell Editor session with ide.cloud.google.com is the simplest way to start a Cloud Shell session and start using Cloud Shell Editor. There is still access to

Activate cloud shell

By selecting Open terminal from the Cloud Shell menu bar, you can access the Cloud Shell terminal anytime.

Use shell.cloud.google.com instead to start a standalone Cloud Shell session with the Cloud Shell Editor and Terminal already running.

Launch Cloud Shell Editor from the console

To launch a Cloud Shell session from the console, click Activate Cloud Shell in your console. This launches a session in the bottom pane of your console.

To launch the editor, click  Code Editor Button  Open Editor on the toolbar of the Cloud Shell window.

Launch from the Cloud Shell terminal

From the Cloud Shell terminal (accessible by clicking Activate Cloud Shell in your console), you can run the following command:

Cloud shell edit.

This launches the Cloud Shell Editor in the same pane.

Cloud Shell Editor interface🖥️

The features of the Cloud Shell Editor.

Viewing and editing files

With continued access to Cloud Shell, the built-in code editor in Cloud Shell enables you to browse file directories and edit and view files. Every Cloud Shell instance includes the Theia-based Cloud Shell Editor by default.

To work with the Cloud Shell Editor, follow these steps:

 

  1. By selecting Open Editor from the toolbar of the Cloud Shell window, the Cloud Shell Editor is opened. Above the Cloud Shell terminal window, the editor appears.Recommendation: Go to ide.cloud.google.com to start the Cloud Shell Editor.
  2. Browse through the file directories using the left-hand pane. You can view and edit your files using the right-hand pane.
  3. The Cloud Shell toolbar in the top right corner provides access to features such as switching between the editor and the Cloud Shell window, uploading and downloading files, previewing web applications on a Cloud Shell virtual machine instance, and viewing usage statistics.
Cloud Shell and Editor session

Alternately, you can run the cloud shell command in your console to open an existing file—for instance, README-cloudshell.txt from the environment above—in the Cloud Shell Editor. As an illustration, use

cloudshell edit README-cloudshell.txt

Uploading and downloading files

The Cloud Shell Editor's Explorer allows you to manage your files further. To upload or download files, use the menu by right-clicking the directory or file you want to use in the Cloud Shell Editor Explorer: Copy the download link, download the files, then upload them.

Right-click a file or folder within the Explorer to bring up menu to access Upload/Download options

Alternatively, you can navigate to FileDownload/Upload Files.

Activity bar

You can access the views offered in the Cloud Shell Editor through the Activity bar, which is located on the left side of the Editor.

These are the Activity bar views:

  • Explorer icon ExplorerCheck out the files and folders in your active workspace.
  • Search icon SearchLook up a string or regular expression in your files.
  • Debug View icon Source ControlUtilize the Git support of the Cloud Shell Editor to control application files.
  • Debug View icon DebugSet breakpoints, look at variables, and debug your program.
  • Cloud APIs Cloud Code - Cloud APIsExplore, enable, and incorporate Cloud Client Libraries into your project
  • Cloud Run icon Cloud Code - Cloud RunKeep an eye on and control your Cloud Run resources.
  • Kubernetes icon Cloud Code - KubernetesKeep an eye on and control your Kubernetes resources.
     

Configure Cloud Shell🎯

The configuration options for Cloud Shell are covered in this section so you can personalize your usage.

Configuration files in your Cloud Shell home directory

5 GB of free persistent disc space are made available by Cloud Shell and mounted as your $HOME directory. Scripts, user configuration files like.bashrc and.vimrc, and any other files you keep in your home directory are persistent across sessions. It's a great way to personalise Cloud Shell's behavior because your.bashrc persists across sessions. Similarly, you can install packages into your home directory to make them persistent.

Pre-configured environment variables

The active project in Cloud Shell is immediately propagated to your gcloud configuration inside of Cloud Shell upon startup. The project ID is defined by the environmental variable GOOGLE_CLOUD_PROJECT, which is also set to point to the active project in Cloud Shell and is used by Application Default Credentials library support.

The environment variable CLOUD SHELL has the value actual. Applications can check this variable to see if they are using Cloud Shell.

Disable or reset Cloud Shell🧑‍💻

Cloud Shell is a feature that managed user accounts can disable. You can cleanly restore your Cloud Shell home directory.

Disable Cloud Shell for managed user accounts

Cloud Shell can be turned off for G Suite and Cloud Identity managed user accounts. To do this, open the Google Admin console, go to Apps > Additional Google services > Google Cloud Platform > Cloud Shell Settings, and then disable "Cloud Shell Access Settings."

You must use access groups, add the specific users to the group, and deactivate the group's Cloud Shell access setting to disable Cloud Shell for particular users. See the Controlling who uses Google Cloud in your organisation guide for complete instructions.

Reset Cloud Shell

Note: Before resetting your Cloud Shell home directory, think about logging in as root in Safe mode and fixing any file-related problems. All files in your home directory will be permanently deleted if you do this.

To cleanly restore your Cloud Shell home directory:

  • Check the home directory for any personal files: 
 ls -a $HOME              

 

  • Clear out your home directory of all files:
  sudo rm -rf $HOME

 

  • Click more vert MoreRestart Cloud Shell menu. Start Cloud Shell again. 

    The confirmation dialogue will appear. Click Restart Cloud Shell.

    The home directory is provisioned for a new VM and reset to its initial state.

Create and deploy a containerized web app🌐

Use the Cloud Shell Editor to create a containerized web app, test it locally, and then deploy it to a Google Kubernetes Engine (GKE) cluster.

Create your web app

Create your app using the Cloud Shell Editor as your working environment. The editor is preloaded with the cloud development tools.

How to build your app

  1. Utilize the status bar to access the  Cloud Code menu.
  2. Choosing New Application.
  3. Choose the Kubernetes application sample app type.
  4. Choose Go:Hello World from the list of sample Kubernetes apps.
  5. Click Create New Application after choosing a folder to store your app in.

 

Your app is launched in a new workspace by Cloud Shell Editor. Your app can be accessed using the explorer view after it reloads.

Create a Google Kubernetes Engine cluster

To start a new Google Kubernetes Engine cluster where you can launch your app: click Cloud Code - Kubernetes. to launch the Kubernetes Explorer.

  1. Click Add a Cluster to the KubeConfig and then press Google Kubernetes Engine in the Quick pick menu.
  2. Click Yes to enable container.googleapis.com when prompted.
  3. Click + Create a New GKE Cluster.
  4. Choose Standard as the cluster type.
  5. Click Open to permit Cloud Shell to open the console.
  6. Use your newly created project in the console, and then change the zone to us-central1-a and the cluster name to my-first-cluster.
  7. Click Create. It takes some time to create a cluster.
  8. After the cluster is created, click  Refresh Kubernetes cluster view Refresh in the Quick pick menu.
  9. Click the cluster name when it appears in the list after you enter the name of your new cluster. The configuration now includes your new cluster and is set up to be the active context.

Deploy your app to a GKE cluster

To install your application on the new cluster:

  1. From the Cloud Code menu, accessible using the status bar, select Run on Kubernetes.
  2. Confirm that the context for your app is your newly created cluster.
  3. Verify the image registry's default setting.
  4. Give your app a minute to finish building and deploying, and monitor your app's progress as it's rebuilt using the Development sessions view.
  5. Locate the forward port node for your service once the building and deployment of your app are complete: Expand in the Development Sessions view. Port Forward URLsservicego-hello-world-external.
  6. Hold the pointer over go-hello-world-external to launch your app and click open_in_new Open URL.

Cleaning up

Just the cluster you made for this quickstart can be deleted:

  1. Click  Open in console icon Open in console after keeping the mouse pointer over the name of your cluster.
  2. Click Delete and then click Delete.

 

If you want to delete your project (along with any associated resources, clusters included):

  1. Go to the console's Projects page.
  2.  Go to the Projects page
  3. Click Delete after selecting the project you made for this quickstart.
  4. Type the project ID to confirm and then click Shut down.
  5. The project is terminated and set to be deleted as a result.

Frequently Asked Questions❓

What is a cloud shell?

Using the interactive shell environment known as Cloud Shell, you can explore and learn about Google Cloud. You can also manage your projects and resources from a web browser.

How do I access the cloud shell?

Open a new session. At the top of the Google Cloud console, click the Activate Cloud Shell button. A command-line prompt is shown when a Cloud Shell session launches in a new frame at the bottom of the console. The initialization of the session may take a few seconds.

Is cloud shell free?

Cloud Shell is free for users with a Google Cloud account.

How do cloud shells work?

Each user and each session gets a separate Cloud Shell instance. While your Cloud Shell session is active, the instance is still running; however, after an hour of inactivity, your session ends, and its VM is deleted.

What is cloud shell storage?

Cloud Shell machines are temporary, but your files persist in two ways: through a disk image and a mounted file share named cloud drive. 

Conclusion

In this article, we discussed the cloud shell, an interactive shell environment, how to use a shell editor, its interface, and a configuration like viewing and editing files. We also learned to disable or reset the cloud shell.
Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem DesignMachine learning, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!!     

Thank You
Live masterclass