Command Line Interface of GCP

The Command line interface in GCP is called as Gcloud. Most GCP services can be managed from Gcloud. We can create, delete and update virtual machines, you can manage instance groups & databases etc…

While there are some more service specific CLI tools in GCP, Gcloud is the most commonly used one. The following is the list of some service specific cli tools about which we will deal later.

  • Cloud storage – gsutil
  • cloud big table -cbt
  • kubernetes – kubectl (Gcloud is also used sometimes to manage clusters)
  • cloud bigquery – bq

Installing Gcloud :

Gcloud is a part of google cloud software development kit (SDK). The get instructions on how to install Gcloud depending on your operating system click here.

You can also use Gcloud from google cloud console using cloud shell. You can activate cloud shell by clicking this Icon marked in yellow

Below is a short video that lets you get more understanding about Gcloud.

gcloud --version // This command lets you see the current version of Gcloud
gcloud init //This lets you start the Initial configuration of Gcloud
gcloud config list // This lets you see the current Gcloud configuration

list command:

Look at the Screenshot of the output of gcloud config list carefully, there are few customized options of this command you can use. for example, if you want to see just the current account you may use the command ” gcloud config list account” but in to view the region you would have to use the command “gcloud config list compute region” because, by default the shell looks for output under the core section.

gcloud config list account // lists the current account being used.
gcloud config list compute/region // list the compute region in the configuration

Set command:

Similar to list command, you can also use the set command to change the value. for example, below are few commands that can be executed. the syntax for this command “gcloud config set section/property.”

gcloud config set core/project <value> // sets the current project to value specified.
gcloud config set compute/region <value> // sets the compute region to specified region.
gcloud config set compute/zone <value> // sets the compute zone to the specified zone.

let’s say that you are working on multiple projects from the same machine & if you want to maintain different configurations.

gcloud config configurations list // lists out the different configurations present.
gcloud config configurations create <name> // lets you create a new configuration.
gcloud config configurations delete <name> // lets you delete an existing configuration.
gcloud config configurations active <name> // activates the specified configuration.
gcloud config configurations describe <name> // gives you details about the configuration.