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-FLAG …] [GROUP] [COMMAND] [COMMAND-FLAG …] [ARG …]

PARAMETERS

--account
    Google Cloud account to use for invocation.

--billing-project
    Billing project to use for requests.

--configuration
    Active Cloud SDK configuration to use.

--flags-file
    File path with flags to apply to the command.

--flatten
    Flatten names of nested fields; use 'help flattening' for details.

--format
    Output format: table/json/yaml/csv/value/tsv.

--help
    Display detailed help.

--impersonate-service-account
    Impersonate service account for this command.

--log-http
    Log all HTTP server interactions to file.

--project
    Default Google Cloud project to use.

--quiet
    Disable most output and prompts; use '--verbosity=debug' for more.

--trace-token
    Trace token for request tracking.

--user-output-enabled
    Print user readable output (default true).

--verbosity
    Override default verbosity: debug/info/warning/error/critical/none.

--version
    Show client version.

DESCRIPTION

gcloud is the unified command-line tool for Google Cloud Platform (GCP), enabling developers and administrators to manage cloud resources directly from the terminal. It provides access to virtually all GCP services, including Compute Engine, Cloud Storage, Kubernetes Engine, BigQuery, and AI/ML tools.

With gcloud, users can create virtual machines, deploy applications, configure networks, run data analytics, and automate workflows via scripts. It supports multiple configurations for different projects, accounts, and environments, making it ideal for CI/CD pipelines and infrastructure as code.

Key strengths include hierarchical command structure (e.g., gcloud compute instances create), tabular/JSON/YAML output formatting, and integration with tools like Terraform or Ansible. Authentication uses service accounts or user credentials, with commands like gcloud auth login for setup.

Prior to use, install the Google Cloud SDK. Run gcloud init to configure defaults. Extensive --help flags provide subcommand details, ensuring discoverability without external docs.

CAVEATS

Requires Google Cloud SDK installation and authentication. Subject to GCP quotas, billing, and IAM permissions. Not all flags apply to every subcommand; check with --help. Large-scale scripting may hit API rate limits.

INSTALLATION

Download from https://cloud.google.com/sdk/docs/install or sudo apt install google-cloud-cli on Debian/Ubuntu.

INITIALIZATION

Run gcloud init to authenticate, select project, and set defaults like compute zone/region.

COMPONENTS

Manage SDK components with gcloud components install kubectl docker-credential-gcr.

HISTORY

Introduced in 2013 with Google Cloud SDK v1.0 as a unified replacement for fragmented tools like gcutil. Evolved with GCP growth, adding support for 100+ services by 2024. Now at SDK v440+, with focus on speed, beta/alpha commands, and AI integrations.

SEE ALSO

gsutil(1), bq(1)

Copied to clipboard