Contents
What is Cloud Shell?
Cloud Shell is your command line environment in the Cloud. This feature enables you to connect to a shell environment on a virtual machine, pre-loaded with the tools you need to easily run commands to develop, deploy and manage your projects.
Currently, Cloud Shell is an f1-micro Google Compute Engine machine that exposes a Debian-based development environment. You are also assigned 5 GB of standard persistent disk space as the home disk so you can store files between sessions.
The features of this environment are:
-
The Google Cloud SDK and its dependencies are already installed. It also comes with Docker installed and enabled so that deployment to Managed VMs works out of the box.
-
Authentication with Google Cloud tools is transparent. Just open your Cloud Shell and work under your credentials from anywhere. Note: this is your personal environment, so your credentials are not visible to anybody, including your teammates.
-
It runs in Google data centers, which can make some operations faster than on your local machine.
-
It gives you a home disk that persists across your sessions so that you can durably store things like your source code and configuration files for your favourite tools like Bash, Vim etc.
-
It automatically uses your current Developers Console project as the default Cloud SDK project. To change it (or to set it if you opened the tab from the project list page), use “gcloud config set
” at any time. -
It securely exposes a set of TCP ports that can be used to run an HTTP server and connect to it from your laptop / machine over authenticated HTTPS connection.
Cost
Use of the Cloud Shell is free through the end of 2015: you will not be charged for any resource utilization.
How do I get started?
Connect to your Cloud Shell by clicking the Cloud Shell button in the top right of the Google Developers Console:
If you need multiple connections to the same virtual machine instance, you can click the plus button next to your current session to open multiple sessions.
You can resize the shell window by dragging the top of it to resize or by clicking the maximize button.
Known issues and limitations
Custom installed software packages may not persist across Cloud Shell sessions
The virtual machine instance that backs your Cloud Shell session is not assigned to the session forever and gets deleted if the session is idle for about an hour. Once the instance is deleted, any modifications that you made to it outside your $HOME will be lost in the next sessions.
We do allow the use of 'sudo' to install custom packages, and we would welcome your feedback on which packages you had to install so that we can include them in the default configuration. We are also working on a solution that would persist custom packages across sessions on different VM instances.
Connection performance is slow
Connecting to a Cloud Shell for the very first time involves creating your home disk and can currently take up to 25 seconds. Subsequent connections to existing VM instances should take ~5 seconds. We are working on improving the performance of the first connection.
How do I use Cloud Shell in my work?
There are a number of things that you can accomplish in your Cloud Shell. Here are some common examples:
Managing Google Compute Engine resources with gcloud compute
You can use the Cloud SDK gcloud command line tool to manage your
Compute Engine resources. This may be more convenient than using Developers
Console if you want to quickly script a complex query or command to operate
on a number of resources. Working with the gcloud command from
Cloud Shell might be more convenient than installing it locally.
# List all compute instances in the project
$ gcloud compute instances list
# Grep the serial console output from all instances in the project
# for a specific pattern in the output.
$ gcloud compute instances list | \
awk 'NR > 1 { print "--zone " $2 " " $1 }' | \
xargs -L1 gcloud compute instances get-serial-port-output | \
grep BREAK-IN
Managing Google Cloud SQL databases with gcloud sql
Below is an example of how you can use Cloud Shell to create a Cloud SQL instance and access it using the pre-installed MySQL command-line client:
# Set the cloud project of interest
$ gcloud config set project hello-world-314
# Create a Cloud SQL instance
$ gcloud sql instances create my-instance
# Assign the instance an IPv4 address, because Compute Engine
# does not yet support IPv6 addresses.
$ gcloud sql instances patch --assign-ip my-instance
# Figure out the IP address that the instance was assigned
$ gcloud sql instances describe my-instance | grep ipAddress
# Authorize the external IP of the Cloud Shell machine with
# the Cloud SQL instance authorized networks list. CLIENT_IP here is
# not a placeholder, but is rather a special string that gets replaced with
# the request IP by the Cloud SQL API automatically.
$ gcloud sql instances patch --authorized-networks=CLIENT_IP my-instance
# Set the root user password for the instance. Replace the <PASSWORD>
# placeholder with the actual password you want to use.
$ gcloud sql instances set-root-password --password=<PASSWORD> my-instance
# Connect to the instance.
$ mysql -h 173.194.253.241 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.38 (Google)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Managing Google Cloud Storage data with gsutil
Another valuable tool available in Cloud Shell is gsutil which you can
use to manipulate your Google Cloud Storage resources: creating
/ deleting GCS buckets and objects, copying / moving the data around, managing
bucket and object ACLs and many more. This also gives you an easy way to
transfer the data in and out your Cloud Shell machine. Some examples are
listed below.
# Create a GCS bucket
$ gsutil mb gs://my-bucket-555
# Upload some data to the GCS bucket you created
$ gsutil cp test.dat gs://my-bucket-555
Managing Google Container Engine clusters
You can create and manage Google Container Engine clusters from the Cloud Shell command line. For example, you can create a cluster with:
$ gcloud config set compute/zone us-central1-a
$ gcloud container clusters create my-cluster
Once the cluster is created, you can initialize the kubectl tool and use it
to manage the cluster:
$ gcloud container clusters get-credentials my-cluster
$ kubectl get nodes
...
$ kubectl cluster-info
...
See Google Container Engine documentation for further details on managing container clusters.
Web Preview
Cloud Shell supports running HTTP servers listening on ports chosen from a
predefined range. The range of ports is typically 8080 - 8084.
To view the range of ports specific to your Cloud Shell, click on the
Web Preview icon in the Cloud Shell
toolbar. These ports are only accessible via the Cloud Shell Proxy, which
provides HTTPS access to the proxy and authenticates the traffic to ensure that
only your account can access the servers running inside your Cloud Shell.
To connect to a server running inside your Cloud Shell, first start a HTTP server listening on one of the available ports, and then connect to it by selecting the target port from the Web Preview menu. This will connect your browser to the HTTP server via the Cloud Shell Proxy.
Running and deploying a Python Google Application Engine app
- Open your Cloud Shell.
- Make sure that you have the current Developers Console project set. You can
do that by choosing the project and Developers Console first and then
opening the new Cloud Shell tab, or by using
gcloud config set project <project ID>. This example will assume your project ID is “hello-world-314”. -
In Cloud Shell terminal, run
$ mkdir helloworld && cd helloworld -
Create app.yaml and helloworld.py files with the content from Google Application Engine Python “Hello World” example.
-
In Cloud Shell terminal, run the server by executing:
$ gcloud preview app run --host=0.0.0.0 ./app.yaml -
In the Cloud Shell toolbar, click on the Web Preview icon
in the Cloud Shell toolbar and choose port 8080. A tab in your browser will open, connecting you to the server you just ran remotely in your Cloud Shell.
-
In Cloud Shell terminal, deploy your Hello World server to Application Engine by executing:
$ gcloud preview app deploy --version 1 ./app.yamlThis may take a while, so be patient. After it finishes, visit “http://hello-world-313.appspot.com”. Congratulations - your application is running and is available to the world now!
-
Modify the app.yaml file by adding “vm: yes” into it to enable Managed VMs support. Try running and deploying your application again. Congratulations - you were able to run and deploy Google Application Engine server with Managed VMs support!
Running and deploying a Java Google Application Engine app
- Open your Cloud Shell.
- Make sure that you have the current Developers Console project set.
You can do that by choosing the project and Developers Console first
and then opening the new Cloud Shell tab, or by using
gcloud config set project <project ID>. This example will assume your project ID is “hello-world-314”. - Follow the steps from the Google Application Engine Java tutorial.
-
When running the local development server, use the command:
$ mvn appengine:devserver -Dappengine.address=0.0.0.0This will make sure that the server is accessible through the Cloud Shell HTTP proxy.
-
Once you have the development server running, click on the Web Preview icon
in the Cloud Shell toolbar and choose port 8080. A tab in your browser will open, connecting you to the server you just ran remotely in your Cloud Shell.
Configured tools
The below is the list of tools installed in the Cloud Shell:
- Up-to-date Google SDKs
- Google App Engine SDK
- Google Cloud SDK
- Text editors
- Emacs
- Nano
- Vim
- Language tools
- Go 1.5
- Java SDK 1.7 and 1.8
- Node.js
- Python 2.7
- Build & package tools
- Gradle
- Make
- Maven
- npm
- pip
- Source control tools
- Git
- Mercurial
- And more
- Docker
- MySQL client
- gRPC compiler
This list is not comprehensive and more tools may have been added since this list was compiled. To find out whether the tool you need is available, try
$ which $TOOL_NAME
Copy/Paste
You can copy and paste text using the keyboard shortcuts supported by your browser and platform (Ctrl+C/Ctrl+V on Windows and Linux, and Cmd+C/Cmd+V on Mac OS X).
Environment persistence
The virtual machine instance which backs your Cloud Shell gets garbage collected when
your session is inactive for about an hour. Next time you connect, you will
get a brand new instance with up-to-date Google Cloud SDK and other software. But,
your home directory will keep the data across the sessions, so you can use that
to store the software or scripts you need, to customize the .bashrc or
.vimrc file to your taste, or to persist your favourite Maven plugins.
How do I send feedback?
We want your feedback! Please send us bugs, suggestions on how to improve the experience and examples of how you’re making use of Cloud Shell or how you think others might be able to use it.
To give us feedback, click on the Cloud Shell Settings icon
and choose “Send Feedback":