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.
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:
To hide or restore the session display, click Hide or Restore.
To open the session in a new window, click Open Session in New Window.
At the top of the console window to close the detached window and restart the console session Activate Cloud Shell.
Select 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
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 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:
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.
Browse through the file directories using the left-hand pane. You can view and edit your files using the right-hand pane.
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.
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.
Alternatively, you can navigate to File > Download/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: Check out the files and folders in your active workspace.
Search: Look up a string or regular expression in your files.
Source Control: Utilize the Git support of the Cloud Shell Editor to control application files.
Debug: Set breakpoints, look at variables, and debug your program.
Cloud Code - Cloud APIs: Explore, enable, and incorporate Cloud Client Libraries into your project
Cloud Code - Cloud Run: Keep an eye on and control your Cloud Run resources.
Cloud Code - Kubernetes: Keep 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 More > Restart 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
Utilize the status bar to access the Cloud Codemenu.
Choosing New Application.
Choose theKubernetes application sample app type.
Choose Go:Hello World from the list of sample Kubernetes apps.
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.
Click Add a Cluster to the KubeConfig and then press Google Kubernetes Engine in the Quick pick menu.
Click Yes to enable container.googleapis.com when prompted.
Click + Create a New GKE Cluster.
Choose Standard as the cluster type.
Click Open to permit Cloud Shell to open the console.
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.
Click Create. It takes some time to create a cluster.
After the cluster is created, click Refresh in the Quick pick menu.
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:
From the Cloud Code menu, accessible using the status bar, select Run on Kubernetes.
Confirm that the context for your app is your newly created cluster.
Verify the image registry's default setting.
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.
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 URLs > service > go-hello-world-external.
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:
Click Open in console after keeping the mouse pointer over the name of your cluster.
Click Delete and then click Delete.
If you want to delete your project (along with any associated resources, clusters included):
Click Delete after selecting the project you made for this quickstart.
Type the project ID to confirm and then click Shut down.
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 Algorithms, Competitive Programming, JavaScript, System Design, Machine 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 problems, interview 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!