Google Cloud Platform for Architects
上QQ阅读APP看书,第一时间看更新

Using the Cloud Shell

Before we jump into the compute options on GCP and create our first VM instance, let's understand the Cloud Shell. A Cloud Shell is a machine instance that runs on the Google Cloud which serves as your command line. All GCP accounts have a Cloud Shell that they can use to access resources on the Google Cloud Platform. You can access the Cloud Shell by clicking on a button to the top right of the navigation ribbon:

The great thing about the Cloud Shell is that it provides a complete environment for you to connect to various resources in the Cloud. Also, it is worth noting that the Cloud Shell is completely free for usage. The cool thing about it is that you can directly use the gcloud command-line tools to connect to resources in the cloud, create resources, provision it, and so on. You don't need to install and set up anything. The Cloud Shell is what you would use if, say, your organization does not allow you to download software on your local machine. It is a great alternative in that case, which just works. When you first connect to the Cloud Shell or gshell, Google has to spin up an active instance to use for this. It might take a little while, so be patient:

The figure that follows is our provisioned Cloud Shell and you will notice that it is associated with the same project which we mentioned earlier. Let's take the gcloud command-line tool for a test run. Remember that the Cloud Shell is just a terminal session on an ephemeral VM. This session will get disconnected after 30 minutes of inactivity. Also, when you are in the Cloud Shell, you are in a home directory with 5 GB of space, and this home directory will remain constant across all Cloud Shell sessions in the project and will be deleted after 120 days of inactivity:

Let’s explore the Cloud Shell further. The gcloud is Google's main command-line tool that allows you to work with resources and to a whole bunch of operations. It's especially useful if you want to script operations and just run a script rather than perform it manually over and over again.

You can view what the current default project is by typing out the gcloud config list command:

You can see that loonycorn-project08 is the default. If you need help with what commands are available with gcloud, simply type gcloud -h, and you will see a whole bunch of information. The gcloud config list command shows you what properties have been set so far in the configuration. This will only display those properties that are different from the defaults. For example, you can see here that the account has been set to vitthal@loonycorn.com and the project is loonycorn-project08:

If you need help for a particular command, let's say it's the compute command, you can simply say gcloud compute --help:

This essentially throws up the main page for that particular command. In other words, gcloud has context-sensitive help, and that is a great way to go about building the commands you need:

Everything you need is right there on the screen.

In a nutshell, the Google Cloud Shell is a great tool for quick work on the console. Remember, again, though, that it is a short, time-limited session on an ephemeral VM. So, if you are going to be intensely developing on the Google Cloud and you can download software, it's better to download the Google Cloud SDK and use that instead. This offers a permanent connection to your instances on the cloud instead of a temporary VM instance that has to be spun up in order to use Cloud Shell.