GCP Shell, What and How!
"I am new to Google Cloud Shell", is a common statement you hear from first time users or not too frequent users of the "command line, or terminal". It is easy if you take the time to understand how the commands are structured. It's no different on Windows, a bit more complicated IMO but works the same.
Another often-heard statement is "why do I need to know the terminal", well on Linux (that I use) when the chips are down your only saviour will be the terminal, and on Windows too! Learn the terminal and keep at it till you get it.
First thing you need to know to be able to use the terminal properly, is how the terminal works whether on Windows or Linux (Mac included). All the "clicks" we do in our GUI eventually gets to call a system-level shell command that will be executed in the background and the result presented to us in the GUI. The GUI comes with some overhead which SysAdmins recognize very well when setting up a server, which in most cases we are encourage not to. Servers are meant to be lightweight, fast and used primarily, of course, to serve up requests.
Now after so much talk lets do this! Every terminal comes with a "help system" that we should be very familiar with and use often as the need arises.
In Linux we ask for help in several ways:
-
By running the commands against the default information system on Linux:
man <query_item_name> info <query_item_name> # modern version, includes clickable links
-
By using the terminal help system:
<query_item_name> --help <query_item_name> -h # short form of "--help"
-
Or simply type the command and without passing any arguments then hitting the return key:
gcloud <hit_the_return_key>
-
Or when we use the command incorrectly and get an output with suggested correct usage
Using the Cloud Shell isn't different. First of all, you need to install the Cloud SDK for your Operating System so you can use the terminal for learning or building on GCP. One of the things I like about the Cloud Shell is its simplicity and very close resemblance to that of the Linux Shell, so for a SysAdmin, it would feel very much like home.
Now the Cloud Shell has several tools we can use to interact with GCP and they include:
- gcloud
- bq
- gsutil
Each of the above-listed tool is passed a set of commands or command groups as GCP calls them and we are told that these commands are structured hierachically, i.e. we can have:
gcloud compute
gcloud compute instances
both compute and instances are command groups but the latter is nested in the former! The terminology for the other tools are a bit different but they all take commands. Taking an excerpt from their official documentation
Within each release level, gcloud CLI commands are organized into a nested hierarchy of command groups, each of which represents a product or feature of the Cloud Platform or its functional subgroups.
Command group | Description |
---|---|
gcloud compute | Commands related to Compute Engine in general availability |
gcloud compute instances | Commands related to Compute Engine instances in general availability |
gcloud beta compute | Commands related to Compute Engine in Beta |
gcloud alpha app | Commands related to managing App Engine deployments in Alpha |
command group ||| What is cloud shell
So basically to say create a compute instance I would run the following commands:
gcloud <group | command> <group | command> <command> [OTHER OPTIONS ...]
So that roughly translates to:
gcloud compute instances <create | ...> mojo-jojo
This would create an instance called mojo-jojo (from the famous Powerpuff Girls Cartoon Series ) with the default configurations that GCP would use for such a command with other options. If I wanted to create an instance in the zone us-central1-a and of machine type f1-micro, then the command would be:
gcloud compute instances create mojo-jojo --zone us-central1-a --machine-type f1-micro
Please note that if you don't have a default zone or region set then the command would ask you for this information, else it just uses the defaults found in your project configurations, otherwise that which is passed as an argument to the gcloud command is used.
Enough talk, let's do (Kungfu Panda). I will use a Youtube video to conclude this write up so go to the provided link and continue the learning and remember to leave me lots of likes and of course do subcribe.
And please remember to delete the mojo-jojo instance if you created it, we can't trust him with such power !