Cloud SDK In Action

This lesson covers using the Cloud SDK commands.

To use Google Cloud CLI effectively, you must understand how the commands are organized in the SDK. This way, it will be easy to guess the commands even if you don’t know the exact command.

Cloud SDK components

Cloud SDK is a bundle of different components. In the last lesson, we used the gcloud component. A component can be a separate CLI app or a group of commands used with the master component app. For example, gcloud is a component (CLI app), and gcloud alpha and gcloud beta are also components (a group of commands).

Some of the important components in Cloud SDK are:

  1. gcloud: The main google cloud component.

    • gcloud alpha: Set of commands used for early testing of new features.
    • gcloud beta: Beta release of new commands.
  2. bq: Known as BigQuery component

  3. gsutil: Used for Cloud storage operations.

  4. core: Shared libraries for all the other components.

  5. kubectl: Kubectl is used to control the Kubernetes cluster.

You can see the list of components using gcloud components list. Try this command. A table with the list of components will be displayed. At the bottom, there will be a command to install/remove components.

To install or remove components at your current SDK version [317.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [317.0.0], run:
  $ gcloud components update

Let’s try to install minikube using the same command, gcloud components install minikube.


You might get the following error.

root@educative:/# gcloud components install minikube
ERROR: (gcloud.components.install) 
You cannot perform this action because the Cloud SDK component manager 
is disabled for this installation. You can run the following command 
to achieve the same result for this installation: 

sudo apt-get install google-cloud-sdk-minikube

sudo command will not work if you are using the educative terminal. Run the command without sudo.

The reason for this error is if the Google Cloud SDK is installed using a system package manager such as apt, yum etc. then other components need to be installed using the same system package manager. We used apt so the command sudo apt-get install google-cloud-sdk-minikube is suggested. Many times the question is asked on this concept in the exam. So remember the reason of the error.

Structure of gcloud command

The following structure of the Cloud SDK command is as follows:

gcloud + release level (optional) + component + entity + operation + positional args + flags

For example: gcloud + compute + instances + create + example-instance-1 + --zone=us-central1-a

Release level

Release Level refers to the command’s release status.

Example: alpha for alpha commands, beta for beta commands, no release level needed for commands that are released after beta.

Component

Component refers to the different Google Cloud services.

Example: compute for Compute Engine, app for App Engine, etc.

Entity

Entity refers to the plural form of an element or collection of elements under a component.

Example: disks, firewalls, images, instances, regions, zones for compute

Operation

Operation refers to the imperative verb form of the operation to be performed on the entity.

Example: Common operations are describe, list, create/update, delete/clear, import, export, copy, remove, add, reset, restart, restore, run, and deploy.

Positional args

Positional args refer to the required, order-specific arguments needed to execute the command.

Example: <INSTANCE_NAMES> is the required positional argument for gcloud compute instances create <INSTANCE_NAMES>.

Flags

Flags refer to the additional arguments, --flag-name(=value), passed in to the command after positional args.

Example: --machine-type=<MACHINE_TYPE> and --preemptible are optional flags for gcloud compute instances create.

Now, open up the terminal/cmd where you have Cloud SDK installed and type gcloud, and hit enter.

If you haven’t installed the Cloud SDK yet, then you can use the below terminal. It comes with Cloud SDK preinstalled.

Once you do that, it will list all the possible next arguments and commands. And the auto-suggestion will continue until you provide the command in the required format.

Get hands-on with 1200+ tech skills courses.