Written for the Google Cloud CLI (gcloud) from version 500. Project IDs, names, zones and regions are examples, so swap in your own, and add --project to any command to pick a project. Set a default region and zone with gcloud config set to leave out --region and --zone. Filters and formats are written to work in bash, zsh, PowerShell and Command Prompt.
Official links: Google Cloud website, gcloud CLI overview, gcloud command reference.
Setup and help #
-
Show the gcloud version and installed componentsLinux, macOS, Windows
gcloud version -
Update gcloud and its componentsLinux, macOS, Windows
gcloud components update -
List components you can installLinux, macOS, Windows
gcloud components list -
Install kubectl and the GKE sign-in pluginLinux, macOS, Windows
gcloud components install kubectl gke-gcloud-auth-plugin -
Install the beta commandsLinux, macOS, Windows
gcloud components install beta -
Get help for a command, with examplesLinux, macOS, Windows
gcloud compute instances create --help -
Search the help for a wordLinux, macOS, Windows
gcloud help -- snapshot -
Show a cheat sheet of common commandsLinux, macOS, Windows
gcloud cheat-sheet -
Show where gcloud is installed and which settings it's usingLinux, macOS, Windows
gcloud info
Sign in and configurations #
-
Sign in in the browserLinux, macOS, Windows
gcloud auth login -
Sign in on a machine with no browserLinux, macOS, Windows
gcloud auth login --no-browser -
Sign in for apps, SDKs and Terraform on this machineLinux, macOS, Windows
gcloud auth application-default login -
Sign in as a service account with a key fileLinux, macOS, Windows
gcloud auth activate-service-account --key-file=sa-key.jsonWarning: Key files are long-lived secrets. Prefer impersonation or workload identity where you can.
-
List the accounts you've signed in with, and which one is activeLinux, macOS, Windows
gcloud auth list -
Switch to another signed-in accountLinux, macOS, Windows
gcloud config set account [email protected] -
Sign out of an accountLinux, macOS, Windows
gcloud auth revoke [email protected] -
Print an access token for the Google Cloud APIsLinux, macOS, Windows
gcloud auth print-access-tokenWarning: Prints a secret in plain text. Don't paste the output anywhere it could be saved or shared.
-
Run one command as a service account, without a keyLinux, macOS, Windows
gcloud storage ls --impersonate-service-account=deployer@my-project.iam.gserviceaccount.com -
Show your current settings: account, project, region and zoneLinux, macOS, Windows
gcloud config list -
Set the default projectLinux, macOS, Windows
gcloud config set project my-project -
Set the default regionLinux, macOS, Windows
gcloud config set compute/region europe-west1 -
Set the default zoneLinux, macOS, Windows
gcloud config set compute/zone europe-west1-b -
Clear the default zoneLinux, macOS, Windows
gcloud config unset compute/zone -
Make a named configuration, such as one per client or projectLinux, macOS, Windows
gcloud config configurations create client-a -
List configurationsLinux, macOS, Windows
gcloud config configurations list -
Switch to another configurationLinux, macOS, Windows
gcloud config configurations activate client-a -
Run one command in another projectLinux, macOS, Windows
gcloud compute instances list --project=my-project -
Use a project for every command in this terminalLinux, macOS
export CLOUDSDK_CORE_PROJECT=my-projectWindows$env:CLOUDSDK_CORE_PROJECT = "my-project" -
Answer yes to every prompt, for scriptsLinux, macOS, Windows
gcloud compute instances delete web-1 --zone=europe-west1-b --quietWarning: --quiet skips the "are you sure" prompt, so this deletes the instance straight away.
Output, filters and formats #
-
Show only some columns in a tableLinux, macOS, Windows
gcloud compute instances list --format="table(name, zone.basename(), status, networkInterfaces[0].networkIP)" -
Show output as JSONLinux, macOS, Windows
gcloud compute instances list --format=json -
Show output as YAMLLinux, macOS, Windows
gcloud compute instances describe web-1 --zone=europe-west1-b --format=yaml -
Get one value for a scriptLinux, macOS, Windows
gcloud config get-value project -
Print just the names, one per lineLinux, macOS, Windows
gcloud compute instances list --format="value(name)" -
Save a value in a variableLinux, macOS
ip=$(gcloud compute instances describe web-1 --zone=europe-west1-b --format="value(networkInterfaces[0].accessConfigs[0].natIP)")Windows$ip = gcloud compute instances describe web-1 --zone=europe-west1-b --format="value(networkInterfaces[0].accessConfigs[0].natIP)" -
Show output as CSVLinux, macOS, Windows
gcloud compute instances list --format="csv(name, zone.basename(), status)" -
Filter the resultsLinux, macOS, Windows
gcloud compute instances list --filter="status=RUNNING" -
Filter by a name that contains some textLinux, macOS, Windows
gcloud compute instances list --filter="name:web" -
Filter by labelLinux, macOS, Windows
gcloud compute instances list --filter="labels.env=prod" -
Combine filtersLinux, macOS, Windows
gcloud compute instances list --filter="status=RUNNING AND zone:europe-west1" -
Sort the resultsLinux, macOS, Windows
gcloud compute instances list --sort-by=~creationTimestamp -
Show only the first few resultsLinux, macOS, Windows
gcloud compute instances list --limit=10 -
Show every field as key and value, for finding a field's nameLinux, macOS, Windows
gcloud compute instances describe web-1 --zone=europe-west1-b --format=flattened
Projects, APIs and IAM #
-
List your projectsLinux, macOS, Windows
gcloud projects list -
Show a projectLinux, macOS, Windows
gcloud projects describe my-project -
Make a projectLinux, macOS, Windows
gcloud projects create my-project --name="My Project" -
Delete a projectLinux, macOS, Windows
gcloud projects delete my-projectWarning: Shuts down everything in the project. You have 30 days to undelete it before it's gone for good.
-
Undelete a projectLinux, macOS, Windows
gcloud projects undelete my-project -
Link a project to a billing accountLinux, macOS, Windows
gcloud billing projects link my-project --billing-account=0X0X0X-0X0X0X-0X0X0X -
List the APIs turned on in a projectLinux, macOS, Windows
gcloud services list --enabled -
Turn on an APILinux, macOS, Windows
gcloud services enable compute.googleapis.com -
Turn off an APILinux, macOS, Windows
gcloud services disable compute.googleapis.comWarning: Anything using the API stops working.
-
List your organisationsLinux, macOS, Windows
gcloud organizations list -
List the folders in an organisationLinux, macOS, Windows
gcloud resource-manager folders list --organization=123456789012 -
Show who has which role in a projectLinux, macOS, Windows
gcloud projects get-iam-policy my-project --flatten="bindings[].members" --format="table(bindings.role, bindings.members)" -
Show the roles one person has in a projectLinux, macOS, Windows
gcloud projects get-iam-policy my-project --flatten="bindings[].members" --filter="bindings.members:[email protected]" --format="value(bindings.role)" -
Give someone a role in a projectLinux, macOS, Windows
gcloud projects add-iam-policy-binding my-project --member="user:[email protected]" --role=roles/viewer -
Remove someone's role in a projectLinux, macOS, Windows
gcloud projects remove-iam-policy-binding my-project --member="user:[email protected]" --role=roles/viewer -
List the predefined rolesLinux, macOS, Windows
gcloud iam roles list --format="table(name, title)" -
Show the permissions in a roleLinux, macOS, Windows
gcloud iam roles describe roles/viewer -
Find every resource in a projectLinux, macOS, Windows
gcloud asset search-all-resources --scope=projects/my-project --format="table(assetType, displayName, location)"
Compute Engine VMs #
-
List VMsLinux, macOS, Windows
gcloud compute instances list -
Show everything about a VMLinux, macOS, Windows
gcloud compute instances describe web-1 --zone=europe-west1-b -
Show a VM's external IP addressLinux, macOS, Windows
gcloud compute instances describe web-1 --zone=europe-west1-b --format="value(networkInterfaces[0].accessConfigs[0].natIP)" -
Make a Debian VMLinux, macOS, Windows
gcloud compute instances create web-1 --zone=europe-west1-b --machine-type=e2-small --image-family=debian-12 --image-project=debian-cloud -
Make an Ubuntu VM with no external IP addressLinux, macOS, Windows
gcloud compute instances create web-1 --zone=europe-west1-b --machine-type=e2-small --image-family=ubuntu-2404-lts-amd64 --image-project=ubuntu-os-cloud --no-address -
Make a Spot VM, cheaper but can be stopped at any timeLinux, macOS, Windows
gcloud compute instances create web-1 --zone=europe-west1-b --machine-type=e2-small --provisioning-model=SPOT --instance-termination-action=STOP -
Make a VM with a start-up scriptLinux, macOS, Windows
gcloud compute instances create web-1 --zone=europe-west1-b --metadata-from-file=startup-script=startup.sh -
Start a VMLinux, macOS, Windows
gcloud compute instances start web-1 --zone=europe-west1-b -
Stop a VMLinux, macOS, Windows
gcloud compute instances stop web-1 --zone=europe-west1-b -
Restart a VM straight away, like pulling the plugLinux, macOS, Windows
gcloud compute instances reset web-1 --zone=europe-west1-b -
Delete a VMLinux, macOS, Windows
gcloud compute instances delete web-1 --zone=europe-west1-bWarning: Deletes the VM and its boot disk, with no undo. Other disks are kept unless they were set to auto-delete.
-
Delete a VM but keep its disksLinux, macOS, Windows
gcloud compute instances delete web-1 --zone=europe-west1-b --keep-disks=all -
Change a VM's machine type (stop it first)Linux, macOS, Windows
gcloud compute instances set-machine-type web-1 --zone=europe-west1-b --machine-type=e2-standard-2 -
SSH in to a VMLinux, macOS, Windows
gcloud compute ssh web-1 --zone=europe-west1-b -
SSH in to a VM with no external IP, through IAPLinux, macOS, Windows
gcloud compute ssh web-1 --zone=europe-west1-b --tunnel-through-iap -
Run one command on a VM over SSHLinux, macOS, Windows
gcloud compute ssh web-1 --zone=europe-west1-b --command="uptime" -
Copy a file to a VMLinux, macOS, Windows
gcloud compute scp report.csv web-1:~/ --zone=europe-west1-b -
Copy a file from a VMLinux, macOS, Windows
gcloud compute scp web-1:~/report.csv . --zone=europe-west1-b -
Forward a port from a VM to your machine, through IAPLinux, macOS, Windows
gcloud compute start-iap-tunnel web-1 3389 --local-host-port=localhost:13389 --zone=europe-west1-b -
Show a VM's serial console output, to debug a bootLinux, macOS, Windows
gcloud compute instances get-serial-port-output web-1 --zone=europe-west1-b -
Add or change a labelLinux, macOS, Windows
gcloud compute instances add-labels web-1 --zone=europe-west1-b --labels=env=prod -
Change a VM's start-up scriptLinux, macOS, Windows
gcloud compute instances add-metadata web-1 --zone=europe-west1-b --metadata-from-file=startup-script=startup.sh -
Turn on OS Login for a projectLinux, macOS, Windows
gcloud compute project-info add-metadata --metadata=enable-oslogin=TRUE -
List the machine types in a zoneLinux, macOS, Windows
gcloud compute machine-types list --filter="zone:europe-west1-b" -
List public images from a familyLinux, macOS, Windows
gcloud compute images list --filter="family:debian" -
List your own imagesLinux, macOS, Windows
gcloud compute images list --no-standard-images -
Make an image from a VM's diskLinux, macOS, Windows
gcloud compute images create web-1-image --source-disk=web-1-data --source-disk-zone=europe-west1-b -
List zones and regionsLinux, macOS, Windows
gcloud compute zones list
Disks and snapshots #
-
List disksLinux, macOS, Windows
gcloud compute disks list -
List disks that aren't attached to anythingLinux, macOS, Windows
gcloud compute disks list --filter="-users:*" -
Make a diskLinux, macOS, Windows
gcloud compute disks create web-1-data --zone=europe-west1-b --size=200GB --type=pd-balanced -
Attach a disk to a VMLinux, macOS, Windows
gcloud compute instances attach-disk web-1 --zone=europe-west1-b --disk=web-1-data -
Detach a diskLinux, macOS, Windows
gcloud compute instances detach-disk web-1 --zone=europe-west1-b --disk=web-1-data -
Make a disk biggerLinux, macOS, Windows
gcloud compute disks resize web-1-data --zone=europe-west1-b --size=200GBWarning: Disks can only grow. You'll also need to grow the file system inside the VM.
-
Take a snapshot of a diskLinux, macOS, Windows
gcloud compute snapshots create web-1-data-snap --source-disk=web-1-data --source-disk-zone=europe-west1-b -
List snapshotsLinux, macOS, Windows
gcloud compute snapshots list -
Make a disk from a snapshotLinux, macOS, Windows
gcloud compute disks create web-1-data --zone=europe-west1-b --source-snapshot=web-1-data-snap -
Delete a diskLinux, macOS, Windows
gcloud compute disks delete web-1-data --zone=europe-west1-bWarning: The data is gone for good unless you have a snapshot.
-
Delete a snapshotLinux, macOS, Windows
gcloud compute snapshots delete web-1-data-snapWarning: Deleted snapshots can't be got back.
VPC networking #
-
List VPC networksLinux, macOS, Windows
gcloud compute networks list -
Make a VPC network with custom subnetsLinux, macOS, Windows
gcloud compute networks create my-vpc --subnet-mode=custom -
List subnetsLinux, macOS, Windows
gcloud compute networks subnets list -
Make a subnetLinux, macOS, Windows
gcloud compute networks subnets create web --network=my-vpc --region=europe-west1 --range=10.10.0.0/24 -
Let VMs with no external IP reach Google APIsLinux, macOS, Windows
gcloud compute networks subnets update web --region=europe-west1 --enable-private-ip-google-access -
List firewall rulesLinux, macOS, Windows
gcloud compute firewall-rules list -
Allow a port in from one addressLinux, macOS, Windows
gcloud compute firewall-rules create allow-https --network=my-vpc --allow=tcp:443 --source-ranges=203.0.113.10/32 -
Allow a port in to VMs with a network tagLinux, macOS, Windows
gcloud compute firewall-rules create allow-https --network=my-vpc --allow=tcp:443 --source-ranges=0.0.0.0/0 --target-tags=web -
Allow SSH through IAP onlyLinux, macOS, Windows
gcloud compute firewall-rules create allow-iap-ssh --network=my-vpc --allow=tcp:22 --source-ranges=35.235.240.0/20 -
Allow SSH from your own public IP addressLinux, macOS
gcloud compute firewall-rules create allow-my-ssh --network=my-vpc --allow=tcp:22 --source-ranges="$(curl -s https://ifconfig.me)/32" -
Delete a firewall ruleLinux, macOS, Windows
gcloud compute firewall-rules delete allow-https -
Add a network tag to a VMLinux, macOS, Windows
gcloud compute instances add-tags web-1 --zone=europe-west1-b --tags=web -
Reserve a static external IP addressLinux, macOS, Windows
gcloud compute addresses create web-ip --region=europe-west1 -
List reserved IP addresses, including unused ones you're paying forLinux, macOS, Windows
gcloud compute addresses list -
Release a static IP addressLinux, macOS, Windows
gcloud compute addresses delete web-ip --region=europe-west1Warning: The address goes back to Google and you can't get the same one back.
-
Give private VMs internet access with Cloud NATLinux, macOS, Windows
gcloud compute routers create my-router --network=my-vpc --region=europe-west1 gcloud compute routers nats create my-nat --router=my-router --region=europe-west1 --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges -
List routesLinux, macOS, Windows
gcloud compute routes list -
List Cloud DNS zonesLinux, macOS, Windows
gcloud dns managed-zones list -
List the records in a DNS zoneLinux, macOS, Windows
gcloud dns record-sets list --zone=example-com -
Add an A recordLinux, macOS, Windows
gcloud dns record-sets create www.example.com. --zone=example-com --type=A --ttl=300 --rrdatas=203.0.113.10
Cloud Storage #
-
List your bucketsLinux, macOS, Windows
gcloud storage ls -
List the files in a bucketLinux, macOS, Windows
gcloud storage ls gs://my-bucket -
List every file in a bucket, with sizesLinux, macOS, Windows
gcloud storage ls --long --recursive gs://my-bucket -
Show how much space a bucket usesLinux, macOS, Windows
gcloud storage du --summarize --readable-sizes gs://my-bucket -
Make a bucketLinux, macOS, Windows
gcloud storage buckets create gs://my-bucket --location=europe-west1 --uniform-bucket-level-access --public-access-prevention -
Upload a fileLinux, macOS, Windows
gcloud storage cp report.csv gs://my-bucket/reports/2026.csv -
Download a fileLinux, macOS, Windows
gcloud storage cp gs://my-bucket/reports/2026.csv report.csv -
Upload a folderLinux, macOS, Windows
gcloud storage cp --recursive ./site gs://my-bucket/ -
Print a file to the screenLinux, macOS, Windows
gcloud storage cat gs://my-bucket/reports/2026.csv -
Rename or move a fileLinux, macOS, Windows
gcloud storage mv gs://my-bucket/reports/2026.csv gs://my-bucket/archive/2026.csv -
Sync a folder up to a bucket, copying only what changedLinux, macOS, Windows
gcloud storage rsync --recursive ./site gs://my-bucket/site/ -
Sync and delete files in the bucket that aren't in the folderLinux, macOS, Windows
gcloud storage rsync --recursive --delete-unmatched-destination-objects ./site gs://my-bucket/site/Warning: Deletes files from the bucket. Run it with --dry-run first to see what it would remove.
-
Delete a fileLinux, macOS, Windows
gcloud storage rm gs://my-bucket/reports/2026.csvWarning: Deleted files can't be got back unless versioning or soft delete is on.
-
Delete everything under a folder in a bucketLinux, macOS, Windows
gcloud storage rm --recursive gs://my-bucket/site/Warning: Deletes every file under that prefix, with no prompt.
-
Delete a bucket and everything in itLinux, macOS, Windows
gcloud storage rm --recursive gs://my-bucketWarning: Deletes every file and then the bucket, with no undo.
-
Show a bucket's settingsLinux, macOS, Windows
gcloud storage buckets describe gs://my-bucket -
Turn on versioning for a bucketLinux, macOS, Windows
gcloud storage buckets update gs://my-bucket --versioning -
List every version of a fileLinux, macOS, Windows
gcloud storage ls --all-versions gs://my-bucket/reports/2026.csv -
Make a download link that expires in an hourLinux, macOS, Windows
gcloud storage sign-url gs://my-bucket/reports/2026.csv --duration=1h --impersonate-service-account=deployer@my-project.iam.gserviceaccount.comWarning: Anyone with the link can download the file until it expires.
-
Give someone read access to a bucketLinux, macOS, Windows
gcloud storage buckets add-iam-policy-binding gs://my-bucket --member="user:[email protected]" --role=roles/storage.objectViewer -
Delete files after 30 daysLinux, macOS, Windows
gcloud storage buckets update gs://my-bucket --lifecycle-file=lifecycle.json
Service accounts #
-
List service accountsLinux, macOS, Windows
gcloud iam service-accounts list -
Make a service accountLinux, macOS, Windows
gcloud iam service-accounts create deployer --display-name="GitHub deployer" -
Give a service account a role in the projectLinux, macOS, Windows
gcloud projects add-iam-policy-binding my-project --member="serviceAccount:[email protected]" --role=roles/viewer -
Let someone act as a service accountLinux, macOS, Windows
gcloud iam service-accounts add-iam-policy-binding [email protected] --member="user:[email protected]" --role=roles/iam.serviceAccountTokenCreator -
List a service account's keysLinux, macOS, Windows
gcloud iam service-accounts keys list [email protected] -
Make a key file for a service accountLinux, macOS, Windows
gcloud iam service-accounts keys create sa-key.json [email protected]Warning: The key file is a long-lived secret. Prefer impersonation or workload identity where you can.
-
Delete a service account keyLinux, macOS, Windows
gcloud iam service-accounts keys delete 1234567890abcdef1234567890abcdef12345678 [email protected]Warning: Anything still using the key stops working straight away.
-
Turn off a service accountLinux, macOS, Windows
gcloud iam service-accounts disable [email protected] -
Delete a service accountLinux, macOS, Windows
gcloud iam service-accounts delete [email protected]Warning: Anything running as it loses access. You have 30 days to undelete it.
Secret Manager and KMS #
-
List secretsLinux, macOS, Windows
gcloud secrets list -
Make a secret from a fileLinux, macOS, Windows
gcloud secrets create db-password --data-file=report.csv -
Read the latest version of a secretLinux, macOS, Windows
gcloud secrets versions access latest --secret=db-passwordWarning: Prints a secret in plain text. Don't paste the output anywhere it could be saved or shared.
-
Add a new version of a secret from a fileLinux, macOS, Windows
gcloud secrets versions add db-password --data-file=report.csv -
List a secret's versionsLinux, macOS, Windows
gcloud secrets versions list db-password -
Turn off an old secret versionLinux, macOS, Windows
gcloud secrets versions disable 1 --secret=db-password -
Let a service account read a secretLinux, macOS, Windows
gcloud secrets add-iam-policy-binding db-password --member="serviceAccount:[email protected]" --role=roles/secretmanager.secretAccessor -
Delete a secretLinux, macOS, Windows
gcloud secrets delete db-passwordWarning: Deletes every version of the secret, with no undo.
-
Make a KMS key ringLinux, macOS, Windows
gcloud kms keyrings create my-keyring --location=europe-west1 -
Make a KMS key that rotates every 90 daysLinux, macOS, Windows
gcloud kms keys create my-key --keyring=my-keyring --location=europe-west1 --purpose=encryption --rotation-period=90d --next-rotation-time=2027-01-01T00:00:00Z -
Encrypt a file with a KMS keyLinux, macOS, Windows
gcloud kms encrypt --key=my-key --keyring=my-keyring --location=europe-west1 --plaintext-file=report.csv --ciphertext-file=report.csv.enc -
Decrypt a file with a KMS keyLinux, macOS, Windows
gcloud kms decrypt --key=my-key --keyring=my-keyring --location=europe-west1 --ciphertext-file=report.csv.enc --plaintext-file=report.csv
Cloud Run and Cloud Functions #
-
Deploy the current folder to Cloud Run, building it for youLinux, macOS, Windows
gcloud run deploy my-service --source=. --region=europe-west1 -
Deploy a container image to Cloud RunLinux, macOS, Windows
gcloud run deploy my-service --image=europe-west1-docker.pkg.dev/my-project/my-repo/my-app:v1 --region=europe-west1 -
Deploy a public Cloud Run service anyone can callLinux, macOS, Windows
gcloud run deploy my-service --image=europe-west1-docker.pkg.dev/my-project/my-repo/my-app:v1 --region=europe-west1 --allow-unauthenticatedWarning: Anyone on the internet can call the service.
-
List Cloud Run servicesLinux, macOS, Windows
gcloud run services list -
Show a Cloud Run service's URLLinux, macOS, Windows
gcloud run services describe my-service --region=europe-west1 --format="value(status.url)" -
Set environment variables on a Cloud Run serviceLinux, macOS, Windows
gcloud run services update my-service --region=europe-west1 --update-env-vars=LOG_LEVEL=debug -
Use a secret as an environment variableLinux, macOS, Windows
gcloud run services update my-service --region=europe-west1 --update-secrets=LOG_LEVEL=db-password:latest -
Change a service's memory and CPULinux, macOS, Windows
gcloud run services update my-service --region=europe-west1 --memory=1Gi --cpu=1 -
List a service's revisionsLinux, macOS, Windows
gcloud run revisions list --service=my-service --region=europe-west1 -
Send all traffic to the latest revisionLinux, macOS, Windows
gcloud run services update-traffic my-service --region=europe-west1 --to-latest -
Roll back to an earlier revisionLinux, macOS, Windows
gcloud run services update-traffic my-service --region=europe-west1 --to-revisions=my-service-00042-abc=100 -
Read a Cloud Run service's logsLinux, macOS, Windows
gcloud run services logs read my-service --region=europe-west1 --limit=50 -
Follow a Cloud Run service's logs (beta component)Linux, macOS, Windows
gcloud beta run services logs tail my-service --region=europe-west1 -
Run a Cloud Run jobLinux, macOS, Windows
gcloud run jobs execute nightly-report --region=europe-west1 --wait -
Delete a Cloud Run serviceLinux, macOS, Windows
gcloud run services delete my-service --region=europe-west1 -
List Cloud FunctionsLinux, macOS, Windows
gcloud functions list -
Deploy an HTTP function from the current folderLinux, macOS, Windows
gcloud functions deploy my-function --gen2 --runtime=python312 --region=europe-west1 --source=. --entry-point=handler --trigger-http -
Read a function's logsLinux, macOS, Windows
gcloud functions logs read my-function --region=europe-west1 --limit=50 -
Call a functionLinux, macOS, Windows
gcloud functions call my-function --region=europe-west1 --data="{}" -
Delete a functionLinux, macOS, Windows
gcloud functions delete my-function --region=europe-west1
GKE, Artifact Registry and Cloud Build #
-
List GKE clustersLinux, macOS, Windows
gcloud container clusters list -
Make an Autopilot clusterLinux, macOS, Windows
gcloud container clusters create-auto my-cluster --region=europe-west1 -
Set up kubectl for a clusterLinux, macOS, Windows
gcloud container clusters get-credentials my-cluster --region=europe-west1 -
Show a cluster's version and statusLinux, macOS, Windows
gcloud container clusters describe my-cluster --region=europe-west1 --format="table(name, currentMasterVersion, status)" -
List the versions you can upgrade toLinux, macOS, Windows
gcloud container get-server-config --region=europe-west1 -
Upgrade a cluster's control planeLinux, macOS, Windows
gcloud container clusters upgrade my-cluster --region=europe-west1 --master --cluster-version=1.33Warning: You can't downgrade afterwards.
-
List a Standard cluster's node poolsLinux, macOS, Windows
gcloud container node-pools list --cluster=my-cluster --region=europe-west1 -
Resize a Standard cluster's node poolLinux, macOS, Windows
gcloud container clusters resize my-cluster --region=europe-west1 --node-pool=default-pool --num-nodes=10 -
Delete a clusterLinux, macOS, Windows
gcloud container clusters delete my-cluster --region=europe-west1Warning: Deletes the cluster and everything running in it.
-
Make a Docker repository in Artifact RegistryLinux, macOS, Windows
gcloud artifacts repositories create my-repo --repository-format=docker --location=europe-west1 -
List Artifact Registry repositoriesLinux, macOS, Windows
gcloud artifacts repositories list -
Sign Docker in to Artifact RegistryLinux, macOS, Windows
gcloud auth configure-docker europe-west1-docker.pkg.dev -
List the images in a repositoryLinux, macOS, Windows
gcloud artifacts docker images list europe-west1-docker.pkg.dev/my-project/my-repo -
Build the Dockerfile in this folder with Cloud Build and push the image, no Docker neededLinux, macOS, Windows
gcloud builds submit --tag=europe-west1-docker.pkg.dev/my-project/my-repo/my-app:v1 -
List recent buildsLinux, macOS, Windows
gcloud builds list --limit=10 -
Follow a build's logsLinux, macOS, Windows
gcloud builds log 0a1b2c3d-1234-5678-9abc-def012345678 --stream
Cloud SQL #
-
List Cloud SQL instancesLinux, macOS, Windows
gcloud sql instances list -
Show a Cloud SQL instanceLinux, macOS, Windows
gcloud sql instances describe my-db -
Connect to a database with its client (needs psql or mysql)Linux, macOS, Windows
gcloud sql connect my-db --user=postgres -
List the databases on an instanceLinux, macOS, Windows
gcloud sql databases list --instance=my-db -
Set a database user's passwordLinux, macOS, Windows
gcloud sql users set-password postgres --instance=my-db --prompt-for-password -
Take a backup nowLinux, macOS, Windows
gcloud sql backups create --instance=my-db -
List backupsLinux, macOS, Windows
gcloud sql backups list --instance=my-db -
Export a database to a bucketLinux, macOS, Windows
gcloud sql export sql my-db gs://my-bucket/appdb.sql.gz --database=appdb -
Restart a Cloud SQL instanceLinux, macOS, Windows
gcloud sql instances restart my-db -
Stop a Cloud SQL instance to save moneyLinux, macOS, Windows
gcloud sql instances patch my-db --activation-policy=NEVER -
Start a stopped Cloud SQL instanceLinux, macOS, Windows
gcloud sql instances patch my-db --activation-policy=ALWAYS -
Delete a Cloud SQL instanceLinux, macOS, Windows
gcloud sql instances delete my-dbWarning: Deletes the instance and its automatic backups. Export the data first if you need it.
Logging, monitoring and Pub/Sub #
-
Read the last hour of errors in a projectLinux, macOS, Windows
gcloud logging read "severity >= ERROR" --freshness=1h --limit=50 -
Read a VM's logsLinux, macOS, Windows
gcloud logging read "resource.type = gce_instance AND resource.labels.instance_id = 1234567890123456789" --limit=50 -
Read who changed what (audit logs)Linux, macOS, Windows
gcloud logging read "logName : cloudaudit.googleapis.com%2Factivity" --freshness=1d --format="table(timestamp, protoPayload.authenticationInfo.principalEmail, protoPayload.methodName)" -
List log names in a projectLinux, macOS, Windows
gcloud logging logs list -
List log sinksLinux, macOS, Windows
gcloud logging sinks list -
Send logs to a bucketLinux, macOS, Windows
gcloud logging sinks create warnings-to-bucket storage.googleapis.com/my-bucket --log-filter="severity >= WARNING" -
List alerting policiesLinux, macOS, Windows
gcloud monitoring policies list --format="table(displayName, enabled)" -
List Pub/Sub topicsLinux, macOS, Windows
gcloud pubsub topics list -
Make a Pub/Sub topicLinux, macOS, Windows
gcloud pubsub topics create orders -
Send a message to a topicLinux, macOS, Windows
gcloud pubsub topics publish orders --message="Hello from gcloud" -
Make a subscription to a topicLinux, macOS, Windows
gcloud pubsub subscriptions create orders-worker --topic=orders -
Read messages from a subscriptionLinux, macOS, Windows
gcloud pubsub subscriptions pull orders-worker --auto-ack --limit=10
Billing and quotas #
-
List your billing accountsLinux, macOS, Windows
gcloud billing accounts list -
Show which billing account a project usesLinux, macOS, Windows
gcloud billing projects describe my-project -
List the projects on a billing accountLinux, macOS, Windows
gcloud billing projects list --billing-account=0X0X0X-0X0X0X-0X0X0X -
List budgetsLinux, macOS, Windows
gcloud billing budgets list --billing-account=0X0X0X-0X0X0X-0X0X0X -
Make a monthly budgetLinux, macOS, Windows
gcloud billing budgets create --billing-account=0X0X0X-0X0X0X-0X0X0X --display-name="Monthly budget" --budget-amount=100EUR --threshold-rule=percent=0.9 -
Show a region's Compute Engine quotasLinux, macOS, Windows
gcloud compute regions describe europe-west1 --flatten="quotas[]" --format="table(quotas.metric, quotas.usage, quotas.limit)" -
Show the recommendations for idle VMsLinux, macOS, Windows
gcloud recommender recommendations list --project=my-project --recommender=google.compute.instance.IdleResourceRecommender --location=europe-west1-b
BigQuery (bq) #
-
List datasetsLinux, macOS, Windows
bq ls -
List the tables in a datasetLinux, macOS, Windows
bq ls analytics -
Show a table's schema and sizeLinux, macOS, Windows
bq show analytics.events -
Run a SQL queryLinux, macOS, Windows
bq query --nouse_legacy_sql "SELECT * FROM analytics.events LIMIT 10" -
See how much data a query would read, without running itLinux, macOS, Windows
bq query --nouse_legacy_sql --dry_run "SELECT * FROM analytics.events" -
Make a datasetLinux, macOS, Windows
bq mk --dataset --location=europe-west1 my-project:analytics -
Load a CSV file into a tableLinux, macOS, Windows
bq load --source_format=CSV --autodetect analytics.events report.csv
Troubleshooting #
-
Show more detail about what a command is doingLinux, macOS, Windows
gcloud compute instances list --verbosity=debug -
Show every request and responseLinux, macOS, Windows
gcloud compute instances list --log-httpWarning: The output includes your access token. Check it before you share it.
-
Check gcloud's network and settingsLinux, macOS, Windows
gcloud info --run-diagnostics -
Show the log of your recent gcloud commandsLinux, macOS, Windows
gcloud info --show-log -
Clear the sign-in used by apps and SDKsLinux, macOS, Windows
gcloud auth application-default revoke -
Set the quota project for apps and SDKs, to fix quota errorsLinux, macOS, Windows
gcloud auth application-default set-quota-project my-project -
Send gcloud through a proxyLinux, macOS, Windows
gcloud config set proxy/type http gcloud config set proxy/address proxy.example.com gcloud config set proxy/port 8080 -
Turn off usage reportingLinux, macOS, Windows
gcloud config set disable_usage_reporting true