Google Cloud Cheatsheet
gcloud CLI
Use this Google Cloud reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Installation & Auth
# Install (macOS via Homebrew) brew install --cask google-cloud-sdk # Install (Linux) curl https://sdk.cloud.google.com | bash exec -l $SHELL # Initialize (login + pick project + default region) gcloud init # Authenticate (opens browser) gcloud auth login # Auth for application-default credentials (SDK/client libraries) gcloud auth application-default login # Service-account key auth gcloud auth activate-service-account --key-file=key.json
Configuration & Profiles
# Show active config gcloud config list # Set defaults gcloud config set project my-project-id gcloud config set compute/region us-central1 gcloud config set compute/zone us-central1-a # Named configurations (profiles) gcloud config configurations create staging gcloud config configurations activate staging gcloud config configurations list # One-off flag to override gcloud compute instances list --project=other-project --region=europe-west1
Project Management
| Command | What it does |
|---|---|
gcloud projects list | List all accessible projects |
gcloud projects create my-proj | Create a new project |
gcloud projects describe my-proj | Show project metadata |
gcloud projects delete my-proj | Schedule project deletion (30-day grace) |
gcloud config set project my-proj | Switch active project |
# Enable an API gcloud services enable run.googleapis.com # List enabled APIs gcloud services list --enabled # Disable an API gcloud services disable container.googleapis.com
Output Formats
# Human-readable table (default) gcloud compute instances list # JSON (pipe to jq) gcloud compute instances list --format=json | jq '.[].name' # YAML gcloud compute instances list --format=yaml # Specific fields table gcloud compute instances list --format="table(name,status,networkInterfaces[0].accessConfigs[0].natIP)" # Value only (scriptable) gcloud compute instances describe my-vm --format="value(status)"
Filtering
# Filter by property gcloud compute instances list --filter="status=RUNNING" gcloud compute instances list --filter="zone:us-central1-a AND machineType:n1-standard" # Prefix match (the : operator supports a trailing *) gcloud compute instances list --filter="name:web-*" # Regex match (~ takes an RE2 regex, NOT a glob) gcloud compute instances list --filter="name~'^web-.*'"
Common Global Flags
| Flag | Effect |
|---|---|
--project=PROJECT | Override active project |
--format=json|yaml|table|value | Output format |
--filter="EXPR" | Server-side filtering |
--quiet / -q | Skip confirmation prompts |
--verbosity=debug | Show HTTP requests |
--account=EMAIL | Use specific auth account |
--impersonate-service-account=SA | Act as a service account |
Account & IAM Quick Commands
# Who am I? gcloud auth list gcloud config get-value account # Add IAM binding gcloud projects add-iam-policy-binding my-proj \ --member="user:alice@example.com" \ --role="roles/editor" # List IAM policy gcloud projects get-iam-policy my-proj # Create service account gcloud iam service-accounts create my-sa \ --display-name="My Service Account" # Create + download key gcloud iam service-accounts keys create key.json \ --iam-account=my-sa@my-proj.iam.gserviceaccount.com
SDK Components & Updates
# Update all components gcloud components update # Install a component (e.g., kubectl, beta, alpha) gcloud components install kubectl gcloud components install beta # List installed components gcloud components list
Useful Aliases & Shell Tricks
# Tab completion (add to ~/.bashrc or ~/.zshrc) source "$(gcloud info --format='value(installation.sdk_root)')/completion.bash.inc" # Command reference cheat sheet in the terminal gcloud cheat-sheet # SSH into a VM (no need for external IP) gcloud compute ssh my-vm --tunnel-through-iap # SCP a file to/from a VM gcloud compute scp ./local.txt my-vm:/home/user/remote.txt gcloud compute scp my-vm:/home/user/remote.txt ./local.txt