LinuxCommandLibrary

gcloud-compute

Manage Google Compute Engine resources

TLDR

List Compute Engine zones

$ gcloud compute zones list
copy

Create a VM instance
$ gcloud compute instances create [instance_name]
copy

Display a VM instance's details
$ gcloud compute instances describe [instance_name]
copy

List all VM instances in a project
$ gcloud compute instances list
copy

Create a snapshot of a persistent disk
$ gcloud compute disks snapshot [disk_name] --snapshot-names [snapshot_name]
copy

Display a snapshot's details
$ gcloud compute snapshots describe [snapshot_name]
copy

Delete a snapshot
$ gcloud compute snapshots delete [snapshot_name]
copy

Connect to a VM instance using SSH
$ gcloud compute ssh [instance_name]
copy

SYNOPSIS

gcloud compute [arguments...] [--flags...]

Example:
gcloud compute instances create my-vm --zone=us-central1-a --machine-type=e2-medium
gcloud compute firewall-rules list --project=my-gcp-project

PARAMETERS

--project=PROJECT_ID
    Specifies the Google Cloud project to operate on. Crucial for multi-project environments.

--zone=ZONE
    Sets the Compute Engine zone for zonal resources like VM instances or disks. Overrides default zone.

--region=REGION
    Sets the Compute Engine region for regional resources such as addresses or subnets. Overrides default region.

--format=FORMAT
    Controls the output format of the command (e.g., json, yaml, text, list, csv, none). Useful for scripting.

--help
    Displays detailed help for the command or subcommand, including examples and flag descriptions.

--verbosity=LEVEL
    Sets the command's logging level (e.g., debug, info, warning, error, critical).

instances
    (Subcommand Group) Manages virtual machine instances (e.g., create, start, stop, delete).

disks
    (Subcommand Group) Manages persistent disks and snapshots (e.g., create, list, delete).

firewall-rules
    (Subcommand Group) Manages network firewall rules (e.g., create, update, list).

networks
    (Subcommand Group) Manages Virtual Private Cloud (VPC) networks and subnets (e.g., create, list).

ssh
    (Subcommand) Connects to a virtual machine instance using SSH, handling authentication automatically.

DESCRIPTION

The gcloud compute command group provides a comprehensive command-line interface for interacting with and managing Google Compute Engine (GCE) resources. As a core part of the Google Cloud SDK, it allows users to perform various operations on virtual machine instances, persistent disks, networks, firewalls, load balancers, and more, directly from their terminal.

It streamlines infrastructure management tasks, enabling efficient automation and scripting of cloud resource provisioning, configuration, and monitoring, making it an essential tool for developers and administrators working with Google Cloud's virtual infrastructure.

CAVEATS

  • Dependency on Google Cloud SDK: Requires the gcloud command-line tool, which is part of the Google Cloud SDK, to be installed and configured.
  • Authentication: Requires proper authentication to a Google Cloud account with sufficient IAM permissions for the operations being performed.
  • Regional/Zonal Specificity: Many Compute Engine resources are zonal or regional. Incorrectly specifying or omitting --zone or --region can lead to errors or operations on unintended resources.
  • Resource Limitations: Operations are subject to project quotas and available resources in a given region/zone.

COMMAND GROUP STRUCTURE

gcloud compute is a command group, meaning it serves as a namespace for numerous subcommands (e.g., gcloud compute instances, gcloud compute disks). To see available subcommands, run gcloud compute --help.

INTERACTIVE HELP

Most gcloud commands and subcommands offer extensive help accessed via --help, which includes examples and descriptions of all available flags specific to that command. For example, gcloud compute instances create --help.

ALPHA/BETA FEATURES

gcloud compute also provides access to alpha and beta versions of features through gcloud alpha compute and gcloud beta compute respectively, allowing users to test upcoming functionalities and API changes.

HISTORY

Google Compute Engine (GCE) was first launched in public beta in 2012. The gcloud compute commands evolved alongside it as the primary command-line interface for managing GCE resources. The gcloud CLI, introduced as a successor to older tools like gcutil, aimed to provide a unified and consistent interface across all Google Cloud services. Since its inception, gcloud compute has seen continuous development, adding support for new GCE features, instance types, networking capabilities, and management paradigms, becoming an essential tool for developers and administrators working with Google Cloud's virtual infrastructure.

SEE ALSO

gcloud(1), gcloud auth(1), gcloud config(1), ssh(1)

Copied to clipboard