The CLI follows rapid releases — pin in CI via the
google-cloud-sdk:SLUG Docker tag. Many surfaces have moved:
gsutil →
gcloud storage,
gcloud functions deploy defaults to gen-2,
Container Registry →
Artifact Registry. ADC is now the path libraries use —
not the user creds from gcloud auth login.
install · auth · configSetup
bash
# install (macOS — Homebrew cask)
brew install --cask gcloud-cli
# install (Linux — bundled tarball)
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz
tar -xf google-cloud-cli-linux-x86_64.tar.gz && ./google-cloud-sdk/install.sh
# verify
gcloud --version # Google Cloud SDK 503+
# login: human (browser)
gcloud auth login
gcloud config set project my-project
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-a
# login: workload (service account JSON — CI, local emulation)
gcloud auth activate-service-account --key-file=key.json
# login: Application Default Credentials (libraries read these)
gcloud auth application-default login
# named configurations (multi-project)
gcloud config configurations create dev
gcloud config configurations activate dev # like AWS profiles
gcloud config configurations list
gcloud logging metrics create m --log-filter='severity>=ERROR'
Log-based metric (alert on it).
gcloud logging sinks create s storage.googleapis.com/B --log-filter='severity>=WARNING'
Export logs to a GCS bucket.
gcloud logging sinks list
Where logs flow out of project.
bash
# live tail (follow) — like aws logs tail
gcloud logging tail "resource.type=cloud_run_revision AND severity>=ERROR" --buffer-window=1s
# one-shot, last 1h, last 100 entries
gcloud logging read \
'resource.type="cloud_run_revision"
AND resource.labels.service_name="my-svc"
AND severity>=WARNING
AND timestamp>="2026-05-19T00:00:00Z"' \
--limit=100 --format=json | jq '.[].textPayload'
# filter by trace, follow a request across services
gcloud logging read \
"trace=\"projects/$PROJECT/traces/abc123\"" \
--format="table(timestamp, resource.labels.service_name, textPayload)"
# create a log-based metric (alertable)
gcloud logging metrics create error-rate \
--description="ERROR-level Cloud Run logs" \
--log-filter='resource.type="cloud_run_revision" AND severity>=ERROR'
build · secret · deploy · tailEnd-to-end · Cloud Run service
Buildpacks turn the working dir into an image, Secret Manager holds the API key, and Cloud Run scales
to zero. Four commands, no Dockerfile, no YAML.
bash
# end-to-end: build + deploy a container to Cloud Run, wire up a secret
PROJECT=my-project
REGION=us-central1
SVC=hello
# 1) buildpacks: source → image, no Dockerfile needed
gcloud builds submit --pack image=us-docker.pkg.dev/$PROJECT/app/$SVC:v1
# 2) create a secret and let the service read it
echo -n "s3cr3t" | gcloud secrets create api-key --data-file=-
gcloud secrets add-iam-policy-binding api-key \
--member="serviceAccount:$PROJECT-compute@developer.gserviceaccount.com" \
--role="roles/secretmanager.secretAccessor"
# 3) deploy: public, autoscaling, secret mounted as env var
gcloud run deploy $SVC \
--image=us-docker.pkg.dev/$PROJECT/app/$SVC:v1 \
--region=$REGION \
--allow-unauthenticated \
--memory=512Mi --cpu=1 --max-instances=10 \
--set-secrets=API_KEY=api-key:latest
# 4) tail logs
gcloud run services logs tail $SVC --region=$REGION
Best practiceGood to know
Use configurations like AWS profiles.gcloud config configurations create dev / activate dev bundles project +
region + account — flip between environments in one command, no shell-env hacks.
--format=value(name) is the secret to scripting.
It strips quotes, headers, and newlines so the result composes with xargs
and while read. Don’t reach for jq until
you actually need nested fields.
Prefer Workload Identity Federation over service-account keys.
Keys leak. WIF lets GitHub Actions / AWS / Azure assume a GCP identity using short-lived OIDC tokens —
same blast-radius story as IAM roles vs IAM users.
Common trapsWatch out for
APIs aren’t enabled by default.
Every first command against a service in a new project fails with Service has not been used.
Run gcloud services enable … — or copy the URL from the error and click
Enable. Quotas + billing must also be live.
gcloud auth login ≠ Application Default Credentials.
The first is the CLI’s identity. The second is what client libraries read. They’re separate
caches — you need gcloud auth application-default login for SDK code
to authenticate locally.
Resource names are region-scoped, but the CLI defaults are tricky.
Many commands inherit zone/region from compute/region in config; others
require --region explicitly. If you get not found for a resource you
just created, the CLI is probably looking in the wrong region.
gcloud is the Google Cloud command-line tool for creating, configuring, and managing GCP resources — compute instances, Cloud Run services, GCS buckets, GKE clusters, IAM policies, and more. It is the primary interface for CI/CD automation and day-to-day operations on Google Cloud.
What is the difference between gcloud auth login and gcloud auth application-default login?
gcloud auth login sets credentials for the gcloud CLI itself (user identity for interactive commands). gcloud auth application-default login (ADC) sets credentials used by client libraries (Python, Node, Go, etc.) when they call GCP APIs. For running code locally, you need ADC; for CLI commands, you need gcloud auth login.
How do I switch between Google Cloud projects with gcloud?
Run gcloud config set project PROJECT_ID to switch the active project. For managing multiple project/account combinations, use named configurations: gcloud config configurations create dev sets up a new config, and gcloud config configurations activate dev switches to it. List all with gcloud config configurations list.
How does --format work in gcloud commands?
The --format flag controls output format. Use --format=json for full JSON, --format='table(name,zone)' for a custom table, or --format='value(name)' to extract a single field for scripting. Combine with --filter='status=RUNNING' to pre-filter server-side before formatting.
What replaced gsutil in the gcloud CLI?
The gcloud storage commands replaced the standalone gsutil tool. Commands like gsutil cp, gsutil ls, and gsutil rm map to gcloud storage cp, gcloud storage ls, and gcloud storage rm respectively. gcloud storage is faster for parallel transfers and is the preferred path for new scripts.
Is the gcloud CLI free to use?
The gcloud CLI itself is free to install and use. However, the GCP resources it creates (VMs, storage, Cloud Run, etc.) incur usage charges. Google Cloud offers a free tier for many services and a $300 credit for new accounts.