Effortless Infrastructure Management with Google Cloud Shell
What is Google Cloud Shell?
If you’re a developer, you know how important it is to have a reliable and efficient environment for coding. Google Cloud Shell is a web-based development environment that provides developers with a fully managed instance of the Google Cloud Platform. It allows you to access a virtual machine that includes pre-installed tools and libraries for development without installing anything on your local device. With Cloud Shell, developers can easily manage their projects, run commands, and edit files securely and conveniently.
In this article, we’ll explore Google Cloud Shell’s features, how to access it, the Cloud Shell environment, running commands, customizing it, pricing, and benefits.
Cloud Shell
Google Cloud Shell is a fully managed development environment accessible directly from your web browser. It provides:
- Pre-installed Tools:
There is no need to set up your local machine; Cloud Shell comes with essential tools like gcloud, kubectl, git, Docker, Kubernetes, and popular programming languages. - Persistent Storage:
5GB of home directory storage persists across sessions, ensuring your files and data are always available. - Web Preview:
Test and debug your applications with built-in web preview functionality before deploying to production. - Virtual Machine Management:
Easily create, start, stop, and delete virtual machines from the command line usinggcloud
.
Accessing Cloud Shell is easy. All you need is a Google Cloud Platform account, free to create if you don’t have one already. Once you have an account, you can access Cloud Shell by clicking on the Cloud Shell icon in the top right corner of the Google Cloud Console. Alternatively, you can open Cloud Shell in your web browser at https://console.cloud.google.com/cloudshell.
When you first access Cloud Shell, initializing your virtual machine will take a few moments. Once it’s ready, you’ll see a command prompt in your web browser, and you can start using it immediately.
Important Google Cloud Shell Commands
General gcloud Commands:
gcloud init
: Initializes or reinitializes thegcloud
CLI, setting up authentication and project configuration.gcloud config list
: Displays the current configuration settings, including the active project, account, and region.gcloud auth login
: Authenticates the user account via a web-based flow.gcloud projects list
: Lists all projects you have access to.gcloud config set project PROJECT_ID
: Sets the default project for the current configuration.gcloud components install COMPONENT_ID
: Installs specificgcloud
components (e.g.,kubectl
,docker-credential-gcr
).gcloud components update
: Updates all installedgcloud
components.gcloud help
: Provides comprehensive help for anygcloud
command.
Compute Engine (gcloud compute):
gcloud compute instances list
: Lists virtual machine instances in a project.gcloud compute instances create INSTANCE_NAME
: Creates a new VM instance.gcloud compute ssh INSTANCE_NAME
: Connects to a VM instance via SSH.gcloud compute instances delete INSTANCE_NAME
: Deletes a VM instance.
Cloud Storage (gsutil):
gsutil mb gs://BUCKET_NAME
: Creates a new Cloud Storage bucket.gsutil ls
: Lists buckets or objects within buckets.gsutil cp FILE_NAME gs://BUCKET_NAME
: Copies a file to a Cloud Storage bucket.gsutil rm gs://BUCKET_NAME/OBJECT_NAME
: Removes an object from a bucket.gsutil rsync
: Synchronizes files and directories between local file systems and Cloud Storage.
Kubernetes (kubectl):
kubectl get pods
: Lists pods in the current Kubernetes context.kubectl describe pod POD_NAME
: Displays detailed information about a pod.kubectl logs POD_NAME
: Streams the logs of a pod.kubectl exec -it POD_NAME -- COMMAND
: Executes a command inside a container of a pod.
Other Useful Commands:
gcloud sql instances list
: Lists Cloud SQL instances.gcloud functions deploy FUNCTION_NAME
: Deploys a Cloud Function.gcloud logging read
: Reads logs from Cloud Logging.gcloud pubsub topics list
: Lists Pub/Sub topics.
Advanced Tips:
- Use the cheat sheet: The
gcloud
CLI cheat sheet is a handy reference: https://cloud.google.com/sdk/docs/cheatsheet - Tab completion: Use tab completion in Cloud Shell to quickly discover available commands and options.
--help
flag: Add the--help
flag to any command to see its usage details and available options.
Cloud Shell Environment
The Cloud Shell environment is a Linux-based virtual machine with many pre-installed tools and libraries for development. It includes tools such as Docker, Kubernetes, and Git and programming languages such as Python, PHP, and Ruby. You can also install additional tools and libraries if you need them.
The Cloud Shell environment also includes a web-based text editor called Cloud Shell Editor. This editor allows you to edit files directly in the web browser, and it supports features such as syntax highlighting auto-completion, and version control integration.
One of the benefits of the Cloud Shell environment is that it’s fully managed by Google, which means you don’t have to worry about managing the underlying infrastructure. Google takes care of updates, security, and availability so you can focus on coding.
Running Commands
Running commands in Cloud Shell is straightforward. You can use the built-in command line interface or the Cloud Shell Editor to run commands in a terminal window.
To run a command in the built-in command line interface, type the command into the terminal window and press enter. For example, to list the files in your home directory, you can order:
ls
Press enter. The output will be displayed in the terminal window.
To run a command in the Cloud Shell Editor, open a file and press Ctrl + Shift + P to open the command palette. Select the “Run Command” option, type in your command, and press enter. The output will be displayed in a terminal window within the editor.
Cloud Shell Editor
The Cloud Shell Editor is a web-based text editor that allows you to edit files directly in the web browser. It supports many features that you would expect from a modern text editor, such as syntax highlighting, auto-completion, and version control integration.
The editor also supports multiple tabs, so you can work on multiple files simultaneously. You can also split the editor into various panes, allowing you to view numerous parts of the same file or files simultaneously.
One of the Cloud Shell Editor’s benefits is that it’s fully integrated with the Cloud Shell environment. This means you can run commands directly within the editor and access your Cloud Shell environment variables and functions from within your code.
Customizing Cloud Shell
Customizing the Cloud Shell environment is easy. You can install additional tools and libraries using the built-in package manager or customize your shell environment with your configurations.
You can use the built-in package manager to install additional tools and libraries. For example, to install Node.js, you can type:
sudo apt-get install nodejs
Press enter. The installation process will begin, and you’ll be prompted to enter your password if necessary.
To customize your shell environment, you can edit your shell configuration file. The default shell for Cloud Shell is Bash, and the configuration file is located at ~/.bashrc. You can add your own aliases, functions, and environment variables to this file, which will be loaded every time you start a new session.
Cloud Shell Pricing
Cloud Shell is free to use and has 5GB of persistent disk storage. This means you can store your files and data in your home directory, which will persist across sessions.
However, you can purchase additional storage space if you need more storage. The pricing for extra storage is based on the amount of storage you need and the region in which your Cloud Shell instance is located.
Google Cloud Shell
Google Cloud Shell is a powerful and convenient development environment that provides developers with a fully managed instance of the Google Cloud Platform. With Cloud Shell, developers can easily manage their projects, run commands, and edit files securely and conveniently. Google fully collects the environment, so you don’t have to worry about managing the underlying infrastructure.
Google Cloud Shell is a command-line interface that integrates you with the Google Cloud experience. It is available in several versions for Windows, Linux, and browsers.
Cloud Shell is a temporary Compute Engine VM with 5GB of persistent disk storage ($home dir). It comes installed with several applications such as Cloud SDK, Java, Python, etc.
gcloud commands are broken up into the following :
gCloud | Service | Resource | Verb
There are some important concepts to remember:
- Cloud shell is tied to the account, not the project
- The server is not persistent.
- Resources in $home are available after reboot, but all other resources are preemptive.
- Cloud Shell can respond to JSON API requests.
- APIs can be queried with the API Explorer (Swagger)
- You can use Google Cloud client libraries – https://cloud.google.com/apis/docs/cloud-client-libraries
- Temporary Compute Engine VM
- Command-line access to the instance via a browser
- 5 GB of persistent disk storage ($HOME dir)
- Pre-installed Cloud SDK and other tools
- gcloud: for working with Google Compute Engine and many GCP services
- gsutil: for working with Cloud Storage
- kubectl: for working with Google Container Engine and Kubernetes
- bq: for working with BigQuery
- Language support for Java, Go, Python, Node.js, PHP, and Ruby
- Web preview functionality
- Built-in authorization for access to resources and instances
After 1 hour of inactivity, the Cloud Shell instance is recycled. Only the /home directory persists. Any changes made to the system configuration, including environment variables, are lost between sessions.
Pricing
The basic Cloud Shell environment is free to use, and it includes 5GB of storage. You can purchase additional storage if needed.
The Power of Google Cloud Shell
Cloud Shell empowers developers by providing a versatile and accessible environment for building, testing, and deploying applications on GCP. Its seamless integration with the Cloud Platform, pre-installed tools, and persistent storage make it a valuable asset in your development toolkit.
Recent Comments