LinuxCommandLibrary

gcloud

Manage Google Cloud Platform resources

TLDR

List all properties in one's active configuration

$ gcloud config list
copy

Login to a Google account
$ gcloud auth login
copy

Set the active project
$ gcloud config set project [project_name]
copy

SSH into a virtual machine instance
$ gcloud compute ssh [user]@[instance]
copy

Display all Google Compute Engine instances in a project (by default instances from all zones are listed)
$ gcloud compute instances list
copy

Update a kubeconfig file with the appropriate credentials to point kubectl to a specific cluster in Google Kubernetes Engine (GKE)
$ gcloud container clusters get-credentials [cluster_name]
copy

Update all gcloud components
$ gcloud components update
copy

Display help for a given command
$ gcloud help [command]
copy

SYNOPSIS


gcloud [GLOBAL_FLAGS] [SUBGROUP | SUBCOMMAND] [ARGS...]

Example: gcloud compute instances create my-vm --zone=us-central1-a

PARAMETERS

--help
    Displays help for a specific command or group.

--project=PROJECT_ID
    Specifies the Google Cloud project to operate on. This flag overrides the active configuration's project setting.

--format=FORMAT
    Sets the output format for command results (e.g., json, yaml, text, table, csv). Useful for scripting.

--account=ACCOUNT
    Specifies the user account to use for authorization. This is useful when managing multiple Google Cloud accounts.

--quiet or -q
    Suppresses interactive prompts and confirmations, making commands non-interactive and suitable for scripts.

--verbosity=LEVEL
    Sets the verbosity level for logging output (e.g., debug, info, warning, error, critical, none).

--log-http
    Logs all HTTP traffic to stderr, which is invaluable for debugging API interactions.

--configuration=NAME
    Activates a named gcloud configuration, allowing easy switching between different project/account setups.

DESCRIPTION

The gcloud command is a powerful, unified command-line tool that is part of the Google Cloud SDK. It allows developers and administrators to manage their Google Cloud resources and services directly from the terminal. gcloud supports a wide range of Google Cloud products, including Compute Engine, Cloud Storage, Cloud SQL, Kubernetes Engine, and many more. It provides a consistent interface for managing projects, authentication, deployments, and various cloud operations.

The tool offers features like automatic updates, easy configuration, and integration with shell scripting for automation. It simplifies complex tasks by abstracting away underlying API calls, making it an essential tool for anyone working with Google Cloud. gcloud commands are structured hierarchically, allowing users to navigate through various service groups and execute specific actions, such as creating virtual machines, listing storage buckets, or deploying applications. It also supports different output formats (JSON, YAML, text, table) for easy parsing and analysis.

CAVEATS

Requires prior installation of the Google Cloud SDK. Continuous internet connectivity and proper authentication (e.g., via gcloud auth login) are essential for operation. Commands within gcloud are highly specific to the Google Cloud service they manage, requiring users to learn sub-command structures for each product. Be mindful that commands under gcloud alpha and gcloud beta are experimental and subject to breaking changes.

OUTPUT FORMATTING

The gcloud command offers extensive options for formatting its output, making it highly suitable for scripting and automation. By using the --format flag, users can specify formats such as json, yaml, text, or table. For example, gcloud compute instances list --format=json provides machine-readable JSON output, while --format="table(name, status, zone)" allows for custom table views. This flexibility greatly enhances the command's utility for parsing data and integrating with other tools.

INTERACTIVE PROMPTS AND AUTOMATION

Many gcloud commands require user confirmation for destructive actions or to fill in missing information. The --quiet (or -q) flag can be used to suppress all interactive prompts, making commands non-interactive and suitable for scripts. Conversely, if detailed operation logs are needed for debugging, the --verbosity=debug flag can be used to provide extensive output, including full HTTP requests and responses. This combination of flags is crucial for both silent automation and in-depth troubleshooting.

HISTORY

The gcloud command is part of the Google Cloud SDK, which evolved to unify command-line access to Google Cloud services. Prior to its introduction, users relied on standalone tools like gsutil (for Cloud Storage) and bq (for BigQuery). Google launched the Google Cloud SDK to centralize CLI access, establishing gcloud as the primary interface. Its development focuses on providing a consistent and user-friendly experience across all Google Cloud products, featuring automatic updates and comprehensive API coverage. It is continuously updated to support new services and features, reflecting Google Cloud's rapid expansion.

SEE ALSO

gsutil(1), bq(1), kubectl(1)

Copied to clipboard