The Google Cloud CLI is a set of tools to create and manage Google Cloud resources. You can use these tools to perform many common platform tasks from the command line or through scripts and other automation.

For example, you can use the gcloud CLI to create and manage the following:

  • Compute Engine virtual machine instances and other resources
  • Cloud SQL instances
  • Google Kubernetes Engine clusters
  • Dataproc clusters and jobs
  • Cloud DNS managed zones and record sets
  • Cloud Deployment Manager deployments

You can also use the gcloud CLI to deploy App Engine applications, manage authentication, customize local configuration, and perform other tasks.

For a quick introduction to the gcloud CLI, a list of commonly used commands, and a look at how these commands are structured, see the gcloud CLI cheat sheet.

Source: https://cloud.google.com/sdk/gcloud


Download and install the gcloud CLI

If you’re using Cloud Shell (GCP Console), the gcloud CLI is available automatically and you don’t need to install it.

Just click on the right top shell icon as shown below to open Cloud Shell console.


To install the gcloud CLI on your computer you can download the Google Cloud CLI installer for different operating systems like Linux, macOS or Windows at the following link.

Install the gcloud CLI
https://cloud.google.com/sdk/docs/install

I will use the Windows Google Cloud CLI installer as shown below.

Download the Google Cloud CLI installer.


Cloud SDK requires Python; supported versions are Python 3 (3.5 to 3.9). By default, the Windows version of Cloud SDK comes bundled with Python 3. To use Cloud SDK, your operating system must be able to run a supported version of Python.

The installer installs all necessary dependencies, including the needed Python version. While Cloud SDK installs and manages Python 3 by default, you can use an existing Python installation if necessary by unchecking the option to Install Bundled Python. See gcloud topic startup to learn how to use an existing Python installation.


After installation is complete, the installer gives you the option to create Start Menu and Desktop shortcuts, start the Google Cloud CLI shell, and configure the gcloud CLI. Make sure that you leave the options to start the shell and configure your installation selected. The installer starts a terminal window and runs the gcloud init command.

The default installation doesn’t include the App Engine extensions required to deploy an application using gcloud commands. These components can be installed using the gcloud CLI component manager.


Press Y to perform an OAuth 2.0 sign in by using your google account.

Using OAuth 2.0 to Access Google APIs
https://developers.google.com/identity/protocols/oauth2


You can initialize the gcloud configuration by using the following commands.

gcloud init
gcloud init –skip-diagnostics

Source: https://cloud.google.com/sdk/gcloud/reference/init

screen_reader property

 When this property is set to true, the following behaviour is enabled:

  • Status trackers instead of unicode spinners: The phrase ‘working’ is displayed on stderr while gcloud is performing tasks.
  • Percentage progress bars: Progress is displayed as a percentage, outputted to stderr.
  • Flattened tables: Boxed tables are the default output of many list commands. Instead of the queried resources being displayed in tables drawn in Unicode, results are rendered as a flattened list of items. Also, consider using the –format flag to define your own format.

To enable these accessibility features, run:

$ gcloud config set accessibility/screen_reader true




gcloud Authentication and Authorization

Use the following gcloud CLI commands to authorize access with a user account:

  • gcloud init
    Authorizes access and performs other common setup steps.
  • gcloud auth login
    Authorizes access and performs other common setup steps.

During authorization, these commands obtain account credentials from Google Cloud and store them on the local system. The specified account becomes the active account in your configuration. The gcloud CLI uses the stored credentials to access Google Cloud. You can have any number of accounts with stored credentials for a single gcloud CLI installation, but only one account is active at a time.

Source: https://cloud.google.com/sdk/docs/authorizing


Configurations are stored in your user config directory under Windows
%APPDATA%\gcloud

The credentials to access the Google Cloud where stored in SQLite and the two files access_tokens.db and credentials.db.

gcloud will store the OAuth tokens in the database.

legacy_credentials folder
gcloud will use as mentioned the above SQLite database to access the users credentials. For backwards compatibility the credentials will also stored in the following two files in cleartext as shown below.

adc –> Application Default Credentials (ADC)

Provide credentials for Application Default Credentials
https://cloud.google.com/docs/authentication/provide-credentials-adc


The configuration itself is stored in the config_default file as shown below.



Determine Installation Path from Google Cloud SDK

You can use the following command to show the installation path from the Google Cloud SDK.

gcloud info --format="value(installation.sdk_root)"


For Windows OS this will be

C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk



Basic Commands

gcloud config list
Display all the properties for the current configuration.


gcloud config set project <project id>
Set a default Google Cloud project to work on.


More commands you will find in the gcloud CLI cheat sheet at the following link https://cloud.google.com/sdk/docs/cheatsheet





Links

gcloud CLI overview
https://cloud.google.com/sdk/gcloud

The gcloud CLI cheat sheet
https://cloud.google.com/sdk/docs/cheatsheet

Google Cloud Command Line Interface (gcloud CLI)
https://cloud.google.com/cli

gcloud auth
https://cloud.google.com/sdk/gcloud/reference/auth

Authorize the gcloud CLI
https://cloud.google.com/sdk/docs/authorizing

Managing gcloud CLI configurations
https://cloud.google.com/sdk/docs/configurations

Using OAuth 2.0 to Access Google APIs
https://developers.google.com/identity/protocols/oauth2

Cloud Shell Editor interface overview
https://ide.cloud.google.com/