home / cheat sheet

>_ gcloud CLI cheat sheet 2026

640 commands · 32 categories · updated April 2026

This cheat sheet covers every gcloud and kubectl command tested on Google Cloud certifications — organised by category so you can scan exactly what you need. Each command links through to a dedicated topic page with practice quizzes. Want to test your recall instead of just reading? Take the interactive quiz →

Alpha & Beta20 commands

Create a Docker repository in Artifact Registry

gcloud artifacts repositories create REPO_NAME --repository-format=docker --location=REGION

Configure Docker to authenticate with Artifact Registry in a given region

gcloud auth configure-docker REGION-docker.pkg.dev

Create a GKE Autopilot cluster

gcloud container clusters create-auto CLUSTER_NAME --region=REGION

SSH to a Compute Engine instance through Identity-Aware Proxy without a public IP

gcloud compute ssh INSTANCE_NAME --tunnel-through-iap --zone=ZONE

Open an IAP TCP tunnel to port 22 on a Compute Engine instance for SSH forwarding

gcloud compute start-iap-tunnel INSTANCE_NAME 22 --local-host-port=localhost:2222 --zone=ZONE

List all Docker images stored in an Artifact Registry repository

gcloud artifacts docker images list REGION-docker.pkg.dev/PROJECT_ID/REPO_NAME

Map a custom domain to a Cloud Run service

gcloud beta run domain-mappings create --service=SERVICE_NAME --domain=DOMAIN_NAME --region=REGION

Create a Cloud Deploy release from the current directory

gcloud deploy releases create RELEASE_NAME --delivery-pipeline=PIPELINE_NAME --region=REGION --source=.

Create a Workload Identity Federation pool for authenticating external workloads

gcloud iam workload-identity-pools create POOL_ID --location=global --display-name='My Pool'

Create an OIDC provider in a Workload Identity Federation pool

gcloud iam workload-identity-pools providers create-oidc PROVIDER_ID --workload-identity-pool=POOL_ID --location=global --issuer-uri=ISSUER_URI --attribute-mapping='google.subject=assertion.sub'

Export the Binary Authorization policy to a YAML file

gcloud container binauthz policy export > policy.yaml

List all packages in an Artifact Registry repository

gcloud artifacts packages list --repository=REPO_NAME --location=REGION

List all rollouts for a Cloud Deploy release

gcloud deploy rollouts list --delivery-pipeline=PIPELINE_NAME --release=RELEASE_NAME --region=REGION

Split Cloud Run traffic 90/10 between two revisions for a canary rollout

gcloud run services update-traffic SERVICE_NAME --to-revisions=REVISION1=90,REVISION2=10 --region=REGION

Add a tag to a specific version of a package in Artifact Registry

gcloud artifacts tags add TAG_NAME --package=PACKAGE_NAME --location=REGION --repository=REPO_NAME --version=VERSION

Add a BGP peer to a Cloud Router for a VPN or Interconnect attachment

gcloud compute routers add-bgp-peer ROUTER_NAME --peer-name=PEER_NAME --interface=INTERFACE_NAME --peer-ip-address=PEER_IP --peer-asn=PEER_ASN --region=REGION

Retrieve the serial port output from a Compute Engine instance for boot-time debugging

gcloud compute instances get-serial-port-output INSTANCE_NAME --zone=ZONE

Display configuration details for a Cloud Run job

gcloud run jobs describe JOB_NAME --region=REGION

Update a Cloud Run job to use a new container image

gcloud run jobs update JOB_NAME --image=NEW_IMAGE_URL --region=REGION

List all Cloud Run jobs in a given region

gcloud run jobs list --region=REGION
↑ back to top

App Engine20 commands

Deploy the current directory's application to Google App Engine

gcloud app deploy

Open the deployed App Engine application URL in your default browser

gcloud app browse

Stream live log entries from the deployed App Engine application

gcloud app logs tail

Display metadata about the current App Engine application including region and URL

gcloud app describe

List all deployed versions of the App Engine application and their traffic allocation

gcloud app versions list

List all services deployed in the App Engine application

gcloud app services list

Show details and traffic splits for a specific App Engine service

gcloud app services describe SERVICE

Show details of a specific App Engine version within a service

gcloud app versions describe VERSION --service SERVICE

Delete a specific App Engine version that is not receiving traffic

gcloud app versions delete VERSION --service SERVICE

Stop serving traffic to a specific App Engine version

gcloud app versions stop VERSION --service SERVICE

Start a previously stopped App Engine version to resume serving traffic

gcloud app versions start VERSION --service SERVICE

List all regions where App Engine applications can be created

gcloud app regions list

Deploy an App Engine app with a specific version identifier

gcloud app deploy --version VERSION

Route 100% of App Engine traffic to a specific version

gcloud app services set-traffic SERVICE --splits VERSION=1

List all running instances of the App Engine application

gcloud app instances list

Show details of a specific App Engine instance

gcloud app instances describe INSTANCE --service SERVICE --version VERSION

Force-stop and delete a specific App Engine instance

gcloud app instances delete INSTANCE --service SERVICE --version VERSION

Read recent log entries from the App Engine application

gcloud app logs read

List all App Engine operations and their completion status

gcloud app operations list

Deploy a new App Engine version without shifting traffic to it

gcloud app deploy --no-promote
↑ back to top

Auth20 commands

Authorize gcloud to access Google Cloud using your user account credentials

gcloud auth login

List all credentialed accounts and identify the currently active account

gcloud auth list

Print an OAuth2 access token for the active account to use in API requests

gcloud auth print-access-token

Authenticate gcloud using a service account JSON key file

gcloud auth activate-service-account --key-file KEY_FILE

Set up Application Default Credentials for local development libraries and tools

gcloud auth application-default login

Revoke credentials and remove access for a specific account from gcloud

gcloud auth revoke ACCOUNT

Register gcloud as a Docker credential helper for Google Container Registry

gcloud auth configure-docker

Print an OpenID Connect identity token for the active account

gcloud auth print-identity-token

Print an access token generated from Application Default Credentials

gcloud auth application-default print-access-token

Revoke Application Default Credentials stored on the local machine

gcloud auth application-default revoke

Set the quota project used by Application Default Credentials

gcloud auth application-default set-quota-project PROJECT_ID

Authenticate with gcloud without automatically opening a browser window

gcloud auth login --no-launch-browser

Switch the active gcloud account without re-authenticating

gcloud config set account ACCOUNT

Revoke credentials for all accounts logged into gcloud

gcloud auth revoke --all

Configure Docker to authenticate with a regional Artifact Registry

gcloud auth configure-docker REGION-docker.pkg.dev

Activate a service account by specifying both email and key file path

gcloud auth activate-service-account SA_EMAIL --key-file KEY_FILE

Configure gcloud to impersonate a service account for all commands

gcloud config set auth/impersonate_service_account SA_EMAIL

List credentialed accounts filtered to a specific account email

gcloud auth list --filter-account ACCOUNT

Authenticate gcloud using a credential configuration file

gcloud auth login --cred-file CREDENTIAL_FILE

Display OAuth2 token details for a specific credentialed account

gcloud auth describe ACCOUNT
↑ back to top

BigQuery20 commands

List all datasets in the current BigQuery project

bq ls

Create a new BigQuery dataset

bq mk DATASET_NAME

Display schema and metadata for a BigQuery table

bq show DATASET.TABLE

Run a BigQuery query using standard SQL (GoogleSQL)

bq query --use_legacy_sql=false 'SELECT * FROM DATASET.TABLE'

Load a CSV file from Cloud Storage into a BigQuery table using a schema file

bq load DATASET.TABLE gs://BUCKET/FILE.csv SCHEMA.json

Export a BigQuery table to a CSV file in Cloud Storage

bq extract DATASET.TABLE gs://BUCKET/export.csv

Delete a BigQuery table without prompting for confirmation

bq rm -f DATASET.TABLE

Display the first rows of a BigQuery table

bq head DATASET.TABLE

Copy a BigQuery table to a new destination table

bq cp SOURCE_DATASET.SOURCE_TABLE DEST_DATASET.DEST_TABLE

Create a BigQuery table with an explicit schema file

bq mk --table DATASET.TABLE SCHEMA.json

Estimate the bytes processed by a BigQuery query without running it

bq query --dry_run --use_legacy_sql=false 'SELECT * FROM DATASET.TABLE'

Run a BigQuery query and write the results to a destination table

bq query --use_legacy_sql=false --destination_table=DATASET.RESULTS_TABLE 'SELECT * FROM DATASET.TABLE'

Load newline-delimited JSON data from Cloud Storage into BigQuery

bq load --source_format=NEWLINE_DELIMITED_JSON DATASET.TABLE gs://BUCKET/FILE.json SCHEMA.json

Create a BigQuery view with a standard SQL query

bq mk --use_legacy_sql=false --view 'SELECT id, name FROM DATASET.TABLE' DATASET.VIEW_NAME

Create a BigQuery dataset in a specific region such as the EU

bq mk --location=EU DATASET_NAME

Export a BigQuery table to compressed CSV files in Cloud Storage

bq extract --compression=GZIP --destination_format=CSV DATASET.TABLE gs://BUCKET/export_*.csv.gz

Run a BigQuery query that fails if it would process more than 1 GB of data

bq query --use_legacy_sql=false --maximum_bytes_billed=1000000000 'SELECT * FROM DATASET.TABLE'

Set a 30-day expiry on a BigQuery table (value in seconds)

bq update --expiration=2592000 DATASET.TABLE

Load Parquet files from Cloud Storage into BigQuery with schema autodetection

bq load --source_format=PARQUET --autodetect DATASET.TABLE gs://BUCKET/*.parquet

Create a BigQuery table partitioned by day using a schema file

bq mk --table --time_partitioning_type=DAY DATASET.PARTITIONED_TABLE SCHEMA.json
↑ back to top

Cloud Build20 commands

Create a Cloud Build trigger on a Cloud Source Repository branch

gcloud builds triggers create cloud-source-repositories --repo=my-app-repo --branch-pattern=main --build-config=cloudbuild.yaml

List recent Cloud Build jobs for the current project

gcloud builds list

Show detailed information about a specific Cloud Build job

gcloud builds describe BUILD_ID

Cancel an in-progress Cloud Build job

gcloud builds cancel BUILD_ID

Submit the current directory as a Cloud Build job and tag the resulting container image

gcloud builds submit --tag IMAGE_URL

Submit a Cloud Build job using a custom build configuration file

gcloud builds submit --config cloudbuild.yaml

Stream or display the log output for a specific Cloud Build run

gcloud builds log BUILD_ID

List all Cloud Build triggers configured in the current project

gcloud builds triggers list

Show full configuration details of a specific Cloud Build trigger

gcloud builds triggers describe TRIGGER_ID

Delete a Cloud Build trigger by its ID

gcloud builds triggers delete TRIGGER_ID

Manually execute a Cloud Build trigger against a specific branch

gcloud builds triggers run TRIGGER_ID --branch BRANCH

Create a Cloud Build trigger that fires on pushes to a GitHub repository

gcloud builds triggers create github --repo-name REPO --repo-owner OWNER --branch-pattern PATTERN --build-config cloudbuild.yaml

Temporarily disable a Cloud Build trigger without deleting it

gcloud builds triggers pause TRIGGER_ID

Re-enable a previously paused Cloud Build trigger

gcloud builds triggers resume TRIGGER_ID

Create a Cloud Build trigger by importing its YAML configuration file

gcloud builds triggers import --source FILE

Export a Cloud Build trigger configuration to a YAML file

gcloud builds triggers export TRIGGER_ID --destination FILE

Build a container image from source using Cloud Buildpacks without a Dockerfile

gcloud builds submit --pack image=IMAGE

List only failed Cloud Build runs in the current project

gcloud builds list --filter status=FAILURE

Run a Cloud Build without uploading any local source code

gcloud builds submit --no-source --config cloudbuild.yaml

List all private worker pools configured for Cloud Build

gcloud builds worker-pools list
↑ back to top

Cloud Functions20 commands

Deploy a new or updated Cloud Function with an HTTP trigger

gcloud functions deploy FUNCTION_NAME --runtime RUNTIME --trigger-http

List all deployed Cloud Functions in the current project

gcloud functions list

Show details and configuration of a specific Cloud Function

gcloud functions describe FUNCTION_NAME

Delete a deployed Cloud Function from the project

gcloud functions delete FUNCTION_NAME

Deploy an HTTP Cloud Function that requires authentication

gcloud functions deploy processOrder --runtime=nodejs18 --trigger-http --region=us-central1 --no-allow-unauthenticated

Deploy a Cloud Function that is triggered by a Pub/Sub topic

gcloud functions deploy FUNCTION_NAME --runtime RUNTIME --trigger-topic TOPIC_NAME

Invoke a deployed Cloud Function directly with test data

gcloud functions call FUNCTION_NAME --data DATA

Display recent log output from a deployed Cloud Function

gcloud functions logs read FUNCTION_NAME

Deploy a Cloud Function specifying a custom entry point handler name

gcloud functions deploy FUNCTION_NAME --runtime nodejs20 --trigger-http --entry-point HANDLER

Deploy a Cloud Function and set environment variables for it

gcloud functions deploy FUNCTION_NAME --set-env-vars KEY=VALUE

Deploy a Cloud Function with a specific memory allocation

gcloud functions deploy FUNCTION_NAME --memory 512MB

Deploy a Cloud Function with a custom maximum execution timeout

gcloud functions deploy FUNCTION_NAME --timeout 300s

Allow unauthenticated public access to an HTTP Cloud Function

gcloud functions add-iam-policy-binding FUNCTION_NAME --member allUsers --role roles/cloudfunctions.invoker

Retrieve the IAM policy controlling who can invoke a Cloud Function

gcloud functions get-iam-policy FUNCTION_NAME

Deploy a publicly accessible HTTP Cloud Function with no auth required

gcloud functions deploy FUNCTION_NAME --trigger-http --allow-unauthenticated

Deploy a Cloud Function connected to a VPC network via a connector

gcloud functions deploy FUNCTION_NAME --vpc-connector CONNECTOR

List all event types that can trigger a Cloud Function

gcloud functions event-types list

Deploy a second-generation Cloud Function with the specified runtime and region

gcloud functions deploy FUNCTION_NAME --gen2 --runtime python311 --trigger-http --region REGION

Deploy a Cloud Function using a specific service account identity

gcloud functions deploy FUNCTION_NAME --service-account SA_EMAIL

Update a single environment variable on a deployed Cloud Function without redeploying code

gcloud functions deploy FUNCTION_NAME --update-env-vars KEY=VALUE
↑ back to top

Cloud Run20 commands

Split Cloud Run traffic between two revisions for a canary rollout

gcloud run services update-traffic checkout-api --to-revisions=checkout-api-00003=10,checkout-api-00002=90

Deploy a container to Cloud Run with public access enabled

gcloud run deploy my-app --image=gcr.io/my-project/my-app:v2 --region=us-central1 --platform=managed --allow-unauthenticated

List all Cloud Run services in the current project

gcloud run services list

Show detailed configuration and status of a Cloud Run service

gcloud run services describe SERVICE_NAME

Delete a Cloud Run service and all its revisions

gcloud run services delete SERVICE_NAME

Deploy a container image to Cloud Run in a specific region

gcloud run deploy SERVICE_NAME --image IMAGE --region REGION

Deploy a container image to Cloud Run as a new or updated service

gcloud run deploy SERVICE --image IMAGE --region REGION

List all revisions of a Cloud Run service

gcloud run revisions list --service SERVICE --region REGION

Show configuration and status of a specific Cloud Run revision

gcloud run revisions describe REVISION --region REGION

Delete a specific Cloud Run revision that is not serving traffic

gcloud run revisions delete REVISION --region REGION

Route 100% of Cloud Run traffic to the latest deployed revision

gcloud run services update-traffic SERVICE --to-latest --region REGION

Split Cloud Run traffic evenly between two revisions for canary testing

gcloud run services update-traffic SERVICE --to-revisions REV1=50,REV2=50 --region REGION

Allow unauthenticated public access to a Cloud Run service

gcloud run services add-iam-policy-binding SERVICE --member allUsers --role roles/run.invoker --region REGION

Retrieve the IAM policy for a Cloud Run service

gcloud run services get-iam-policy SERVICE --region REGION

Update environment variables on a deployed Cloud Run service

gcloud run services update SERVICE --set-env-vars KEY=VALUE --region REGION

Update the memory limit for a deployed Cloud Run service

gcloud run services update SERVICE --memory MEMORY --region REGION

Set the maximum number of concurrent requests per Cloud Run container instance

gcloud run services update SERVICE --concurrency N --region REGION

Create a Cloud Run Job for running containerised batch tasks

gcloud run jobs create JOB --image IMAGE --region REGION

Trigger an execution of a Cloud Run Job

gcloud run jobs execute JOB --region REGION

Set a minimum number of Cloud Run instances to keep warm and avoid cold starts

gcloud run services update SERVICE --min-instances N --region REGION
↑ back to top

Cloud Scheduler20 commands

Create a Cloud Scheduler HTTP job with OIDC authentication targeting Cloud Run

gcloud scheduler jobs create http daily-process --schedule="0 2 * * *" --uri=https://my-service-xyz.run.app/process --http-method=POST --oidc-service-account-email=scheduler-sa@my-project.iam.gserviceaccount.com

List all Cloud Scheduler jobs in the current project

gcloud scheduler jobs list

Show detailed configuration of a specific Cloud Scheduler job

gcloud scheduler jobs describe JOB_NAME

Delete a Cloud Scheduler job permanently

gcloud scheduler jobs delete JOB_NAME

Pause a Cloud Scheduler job so it stops triggering on its schedule

gcloud scheduler jobs pause JOB_NAME

Manually trigger a Cloud Scheduler job immediately outside its normal schedule

gcloud scheduler jobs run JOB_NAME

Create a Cloud Scheduler job that sends HTTP requests on a cron schedule

gcloud scheduler jobs create http JOB_NAME --schedule "CRON" --uri URI --location LOCATION

Create a Cloud Scheduler job that publishes a message to a Pub/Sub topic

gcloud scheduler jobs create pubsub JOB_NAME --schedule "CRON" --topic TOPIC --message-body MESSAGE --location LOCATION

Create a Cloud Scheduler job that calls an App Engine endpoint

gcloud scheduler jobs create app-engine JOB_NAME --schedule "CRON" --relative-url URL --location LOCATION

Update the cron schedule of an existing Cloud Scheduler HTTP job

gcloud scheduler jobs update http JOB_NAME --schedule "NEW_CRON" --location LOCATION

Resume a previously paused Cloud Scheduler job

gcloud scheduler jobs resume JOB_NAME --location LOCATION

List all Cloud Scheduler jobs in a specific region

gcloud scheduler jobs list --location LOCATION

List only currently enabled Cloud Scheduler jobs in a region

gcloud scheduler jobs list --location LOCATION --filter state=ENABLED

Delete a Cloud Scheduler job without an interactive confirmation prompt

gcloud scheduler jobs delete JOB_NAME --location LOCATION --quiet

Create a Cloud Scheduler job that authenticates to an OIDC-protected endpoint

gcloud scheduler jobs create http JOB_NAME --schedule "CRON" --uri URI --oidc-service-account-email SA_EMAIL --location LOCATION

Export a Cloud Scheduler job configuration as YAML

gcloud scheduler jobs describe JOB_NAME --location LOCATION --format yaml

Add or update HTTP headers on an existing Cloud Scheduler HTTP job

gcloud scheduler jobs update http JOB_NAME --update-headers KEY=VALUE --location LOCATION

Manually trigger an immediate execution of a Cloud Scheduler job

gcloud scheduler jobs run JOB_NAME --location LOCATION

List all regions where Cloud Scheduler is available

gcloud scheduler locations list

Create a Cloud Scheduler job that publishes to Pub/Sub every Monday at 9am

gcloud scheduler jobs create pubsub JOB_NAME --schedule "0 9 * * 1" --topic TOPIC --message-body MESSAGE --location LOCATION
↑ back to top

Cloud SQL20 commands

Create a Cloud SQL read replica using --master-instance-name

gcloud sql instances create prod-db-replica --master-instance-name=prod-db

List all Cloud SQL instances in the current project

gcloud sql instances list

Show detailed information about a specific Cloud SQL instance

gcloud sql instances describe INSTANCE_NAME

Delete a Cloud SQL instance and all its data permanently

gcloud sql instances delete INSTANCE_NAME

List all databases within a specific Cloud SQL instance

gcloud sql databases list --instance INSTANCE_NAME

Open an interactive SQL session to a Cloud SQL instance

gcloud sql connect INSTANCE_NAME --user USER

Create a new database inside an existing Cloud SQL instance

gcloud sql databases create DB_NAME --instance INSTANCE

Delete a database from a Cloud SQL instance

gcloud sql databases delete DB_NAME --instance INSTANCE

Show details and collation settings of a Cloud SQL database

gcloud sql databases describe DB_NAME --instance INSTANCE

Create a new database user in a Cloud SQL instance

gcloud sql users create USER --instance INSTANCE --password PASSWORD

List all database users in a Cloud SQL instance

gcloud sql users list --instance INSTANCE

Delete a database user from a Cloud SQL instance

gcloud sql users delete USER --instance INSTANCE

Set database engine flags on a Cloud SQL instance

gcloud sql instances patch INSTANCE --database-flags FLAG=VALUE

Configure the automated backup start time for a Cloud SQL instance

gcloud sql instances patch INSTANCE --backup-start-time HH:MM

Change the machine type (tier) of a Cloud SQL instance

gcloud sql instances patch INSTANCE --tier TIER

Restart a Cloud SQL instance to apply pending flag changes

gcloud sql instances restart INSTANCE

Create an exact copy of a Cloud SQL instance

gcloud sql instances clone INSTANCE CLONE_NAME

List all available automated and on-demand backups for a Cloud SQL instance

gcloud sql backups list --instance INSTANCE

Export a Cloud SQL database to a SQL dump file in Cloud Storage

gcloud sql instances export INSTANCE gs://BUCKET/FILE --database DB_NAME

Import a SQL dump file from Cloud Storage into a Cloud SQL instance

gcloud sql instances import INSTANCE gs://BUCKET/FILE --database DB_NAME
↑ back to top

Cloud Storage20 commands

Copy files or objects between your local filesystem and Cloud Storage

gcloud storage cp LOCAL_PATH gs://BUCKET_NAME/OBJECT_PATH

List objects and prefixes inside a Cloud Storage bucket

gcloud storage ls gs://BUCKET_NAME

Create a new Cloud Storage bucket in a specified location

gcloud storage buckets create gs://BUCKET_NAME --location LOCATION

Delete objects or buckets from Cloud Storage

gcloud storage rm gs://BUCKET_NAME/OBJECT_PATH

List all Cloud Storage buckets in the current project

gcloud storage buckets list

Show detailed metadata and configuration for a specific Cloud Storage bucket

gcloud storage buckets describe gs://BUCKET_NAME

Move or rename an object within Cloud Storage

gcloud storage mv gs://BUCKET/SOURCE gs://BUCKET/DEST

Print the contents of a Cloud Storage object to stdout

gcloud storage cat gs://BUCKET/OBJECT

Show metadata such as size, hash, and content type for a Cloud Storage object

gcloud storage objects describe gs://BUCKET/OBJECT

Recursively copy a local directory and all its contents to Cloud Storage

gcloud storage cp -r LOCAL_DIR gs://BUCKET/

Enable object versioning on a Cloud Storage bucket

gcloud storage buckets update gs://BUCKET --versioning

Apply a lifecycle management policy to a Cloud Storage bucket from a JSON file

gcloud storage buckets update gs://BUCKET --lifecycle-file LIFECYCLE_FILE

Make all objects in a Cloud Storage bucket publicly readable

gcloud storage buckets add-iam-policy-binding gs://BUCKET --member allUsers --role roles/storage.objectViewer

Retrieve the IAM policy for a Cloud Storage bucket

gcloud storage buckets get-iam-policy gs://BUCKET

List Cloud Storage objects with their sizes and last-modified timestamps

gcloud storage ls -l gs://BUCKET

Synchronise a local directory to Cloud Storage, copying only changed files

gcloud storage rsync LOCAL_DIR gs://BUCKET/

Enable uniform bucket-level access to disable per-object ACLs

gcloud storage buckets update gs://BUCKET --uniform-bucket-level-access

Download an object from Cloud Storage to the local filesystem

gcloud storage cp gs://BUCKET/OBJECT LOCAL_PATH

Delete an empty Cloud Storage bucket

gcloud storage buckets delete gs://BUCKET

Set a retention policy to prevent object deletion for a specified period

gcloud storage buckets update gs://BUCKET --retention-period SECONDS
↑ back to top

Cloud Storage gsutil20 commands

Create a new Cloud Storage bucket

gsutil mb gs://BUCKET_NAME

List all Cloud Storage buckets accessible in the current project

gsutil ls

Upload a local file to a Cloud Storage bucket

gsutil cp FILE.TXT gs://BUCKET_NAME/

Download a file from Cloud Storage to the current directory

gsutil cp gs://BUCKET_NAME/FILE.TXT .

Delete an object from a Cloud Storage bucket

gsutil rm gs://BUCKET_NAME/FILE.TXT

Rename or move an object within Cloud Storage

gsutil mv gs://BUCKET_NAME/OLD.TXT gs://BUCKET_NAME/NEW.TXT

Remove an empty Cloud Storage bucket

gsutil rb gs://BUCKET_NAME

Print the contents of a Cloud Storage object to stdout

gsutil cat gs://BUCKET_NAME/FILE.TXT

Display the total size of a Cloud Storage bucket in human-readable format

gsutil du -sh gs://BUCKET_NAME

Display metadata for a specific Cloud Storage object

gsutil stat gs://BUCKET_NAME/FILE.TXT

Recursively upload an entire local directory to Cloud Storage

gsutil cp -r ./LOCAL_DIR/ gs://BUCKET_NAME/

Synchronise a local directory with a Cloud Storage bucket, copying only changed files

gsutil rsync -r ./LOCAL_DIR gs://BUCKET_NAME

Upload a directory to Cloud Storage using parallel multi-threaded transfers

gsutil -m cp -r ./DATA/ gs://BUCKET_NAME/

Enable object versioning on a Cloud Storage bucket

gsutil versioning set on gs://BUCKET_NAME

Apply a lifecycle configuration file to a Cloud Storage bucket

gsutil lifecycle set lifecycle.json gs://BUCKET_NAME

Grant a user the Storage Object Viewer role on a Cloud Storage bucket

gsutil iam ch user:USER@example.com:roles/storage.objectViewer gs://BUCKET_NAME

Apply a CORS configuration file to a Cloud Storage bucket

gsutil cors set cors.json gs://BUCKET_NAME

Generate a signed URL valid for 1 hour for a private Cloud Storage object

gsutil signurl -d 1h KEY.json gs://BUCKET_NAME/PRIVATE_FILE.TXT

Set a 365-day retention policy on a Cloud Storage bucket

gsutil retention set 365d gs://BUCKET_NAME

Copy CSV files to Cloud Storage, skipping any files that already exist at the destination

gsutil cp -n ./DATA/*.csv gs://BUCKET_NAME/DATA/
↑ back to top

Cluster & Context20 commands

Display the API server endpoint addresses and cluster services URLs

kubectl cluster-info

Show the client and server Kubernetes version information

kubectl version

Display the merged kubeconfig settings from all configured files

kubectl config view

Print the name of the currently active kubeconfig context

kubectl config current-context

List all available kubeconfig contexts and highlight the active one

kubectl config get-contexts

Switch the active kubeconfig context to a different cluster or user

kubectl config use-context CONTEXT_NAME

Modify a kubeconfig context to set its default namespace or cluster

kubectl config set-context CONTEXT_NAME --namespace NAMESPACE

Rename a kubectl context in the kubeconfig file

kubectl config rename-context OLD_NAME NEW_NAME

Remove a context entry from the kubeconfig file

kubectl config delete-context CONTEXT

Add or update a cluster entry in the kubeconfig with its API server URL

kubectl config set-cluster CLUSTER --server SERVER

Set the credentials for a user entry in the kubeconfig file

kubectl config set-credentials USER --token TOKEN

Remove a cluster entry from the kubeconfig file

kubectl config delete-cluster CLUSTER

Show only the kubeconfig entries relevant to the current context

kubectl config view --minify

Dump detailed cluster diagnostic information for debugging

kubectl cluster-info dump

Display only the kubectl client version without contacting the server

kubectl version --client

List all cluster names defined in the kubeconfig file

kubectl config get-clusters

Display the full kubeconfig including unredacted certificate data

kubectl config view --raw

Remove a user entry from the kubeconfig file

kubectl config delete-user USER

List only the Kubernetes resource types that are scoped to a namespace

kubectl api-resources --namespaced

Set the default namespace for the current kubectl context so you don't need -n on every command

kubectl config set-context --current --namespace NAMESPACE
↑ back to top

Compute Engine20 commands

Create a new Compute Engine virtual machine instance

gcloud compute instances create INSTANCE_NAME --zone ZONE --machine-type MACHINE_TYPE

List all Compute Engine VM instances in the current project

gcloud compute instances list

Show detailed metadata and configuration of a specific VM instance

gcloud compute instances describe INSTANCE_NAME --zone ZONE

Permanently delete a Compute Engine VM instance and its boot disk

gcloud compute instances delete INSTANCE_NAME --zone ZONE

Start a previously stopped Compute Engine VM instance

gcloud compute instances start INSTANCE_NAME --zone ZONE

Stop a running Compute Engine VM instance without deleting it

gcloud compute instances stop INSTANCE_NAME --zone ZONE

Open an SSH connection to a Compute Engine VM instance

gcloud compute ssh INSTANCE_NAME --zone ZONE

Perform a hard reset on a Compute Engine VM instance (equivalent to power cycle)

gcloud compute instances reset INSTANCE_NAME --zone ZONE

List all available Compute Engine zones and their status

gcloud compute zones list

Create a new persistent disk in a specified zone

gcloud compute disks create DISK_NAME --size SIZE --zone ZONE

Create a new VPC firewall rule to allow or deny specific traffic

gcloud compute firewall-rules create RULE_NAME --allow PROTOCOL:PORT

List all VPC firewall rules in the current project

gcloud compute firewall-rules list

Reserve a new static external IP address in a specified region

gcloud compute addresses create ADDRESS_NAME --region REGION

Add network tags to a Compute Engine instance for firewall rule targeting

gcloud compute instances add-tags INSTANCE_NAME --tags TAG1,TAG2 --zone ZONE

Securely copy files between a local machine and a Compute Engine instance over SSH

gcloud compute scp LOCAL_PATH INSTANCE_NAME:REMOTE_PATH --zone ZONE

List all available Compute Engine disk images including public and custom images

gcloud compute images list

Delete a VM from the wrong zone, update the default zone, and recreate it

gcloud compute instances delete web-server --zone=us-east1-b && gcloud config set compute/zone us-central1-a && gcloud compute instances create web-server

Create a new Compute Engine disk from an existing snapshot

gcloud compute disks create restored-disk --source-snapshot=data-server-snapshot --zone=us-east1-b

Create a snapshot of a Compute Engine persistent disk

gcloud compute snapshots create SNAPSHOT_NAME --source-disk DISK --source-disk-zone ZONE

List all available Compute Engine machine types in a specific zone

gcloud compute machine-types list --filter zone:ZONE
↑ back to top

Config & Init20 commands

Initialize the gcloud CLI with a new configuration, project, and default settings

gcloud init

Set the active GCP project for all subsequent gcloud commands

gcloud config set project PROJECT_ID

Set the default Compute Engine region for the current configuration

gcloud config set compute/region REGION

Set the default Compute Engine zone for the current configuration

gcloud config set compute/zone ZONE

Display all properties in the active gcloud configuration

gcloud config list

Create a new named gcloud configuration profile

gcloud config configurations create CONFIG_NAME

Switch to a different named gcloud configuration profile

gcloud config configurations activate CONFIG_NAME

List all available gcloud configuration profiles and show which is active

gcloud config configurations list

List all GCP projects accessible with the active account credentials

gcloud projects list

Print the currently active GCP project from the gcloud configuration

gcloud config get project

Print the currently configured default Compute Engine region

gcloud config get compute/region

Print the currently configured default Compute Engine zone

gcloud config get compute/zone

Remove a property from the active gcloud configuration so it has no default

gcloud config unset compute/region

Display diagnostic info about the gcloud installation, environment, and logs

gcloud info

Display the installed version of the gcloud CLI and all components

gcloud version

List all installed and available gcloud components with their versions

gcloud components list

Update all installed gcloud SDK components to their latest versions

gcloud components update

Show all properties set in a specific named gcloud configuration

gcloud config configurations describe CONFIG_NAME

Permanently delete a named gcloud configuration profile

gcloud config configurations delete CONFIG_NAME

Set which Google account is active in the current gcloud configuration

gcloud config set core/account ACCOUNT
↑ back to top

ConfigMaps & Secrets20 commands

Create a ConfigMap from literal key-value pairs on the command line

kubectl create configmap CONFIGMAP_NAME --from-literal=KEY=VALUE

List all ConfigMaps in the current namespace

kubectl get configmaps

Show the stored data and metadata of a specific ConfigMap

kubectl describe configmap CONFIGMAP_NAME

Create an opaque Secret from literal key-value pairs for sensitive data

kubectl create secret generic SECRET_NAME --from-literal=KEY=VALUE

List all Secrets and their types in the current namespace

kubectl get secrets

Show metadata and data key sizes of a specific Secret without revealing values

kubectl describe secret SECRET_NAME

Create a ConfigMap populated with the contents of a file on disk

kubectl create configmap CONFIGMAP_NAME --from-file=FILEPATH

Create a TLS Secret from a certificate and private key file pair

kubectl create secret tls SECRET_NAME --cert=CERT_FILE --key=KEY_FILE

List all Kubernetes service accounts in the current namespace

kubectl get serviceaccounts

Delete a ConfigMap from the current namespace

kubectl delete configmap CONFIG_NAME

Open a ConfigMap for in-place editing in the default editor

kubectl edit configmap CONFIG_NAME

Create a ConfigMap from a single key-value literal pair

kubectl create configmap CONFIG_NAME --from-literal KEY=VALUE

Create a Kubernetes secret for authenticating with a private container registry

kubectl create secret docker-registry REGISTRY_SECRET --docker-server SERVER --docker-username USER --docker-password PASS

Delete a secret from the current namespace

kubectl delete secret SECRET_NAME

Open a Kubernetes secret for in-place editing (values are base64-encoded)

kubectl edit secret SECRET_NAME

Extract and decode a specific key from a Kubernetes secret

kubectl get secret SECRET_NAME -o jsonpath='{.data.KEY}' | base64 --decode

Create a ConfigMap by importing all key-value pairs from a .env file

kubectl create configmap CONFIG_NAME --from-env-file ENV_FILE

Create a secret with a specific key mapped to a file's contents

kubectl create secret generic SECRET_NAME --from-file KEY=FILE_PATH

List all ConfigMaps across every namespace in the cluster

kubectl get configmaps --all-namespaces

Update a specific key in a ConfigMap using a JSON patch

kubectl patch configmap CONFIG_NAME --patch '{"data":{"KEY":"VALUE"}}'
↑ back to top

Debugging20 commands

List cluster events sorted by creation time to troubleshoot recent issues

kubectl get events --sort-by=.metadata.creationTimestamp

Retrieve logs from the previous terminated instance of a pod container

kubectl logs POD_NAME --previous

Stream live log output from a pod container in real time

kubectl logs -f POD_NAME

Attach to the primary process running inside a pod container for live interaction

kubectl attach POD_NAME -c CONTAINER_NAME -it

Retrieve logs from a specific container within a multi-container pod

kubectl logs POD_NAME -c CONTAINER_NAME

Block until a pod reaches a specified condition or the timeout expires

kubectl wait --for=condition=ready pod/POD_NAME --timeout TIMEOUT

List cluster events sorted chronologically to diagnose recent failures

kubectl get events --sort-by .metadata.creationTimestamp

Attach a debug container to a running pod for live troubleshooting

kubectl debug pod POD_NAME --image IMAGE --stdin --tty

Show CPU and memory usage broken down per container within a specific pod

kubectl top pod POD_NAME --containers

Launch a temporary BusyBox pod for network or DNS debugging, auto-deleted on exit

kubectl run debug-pod --image=busybox --rm -it --restart=Never -- sh

Output the full pod specification and current status as YAML

kubectl get pod POD_NAME -o yaml

Extract the conditions array from a pod to inspect readiness and scheduling state

kubectl get pod POD_NAME -o jsonpath='{.status.conditions}'

Describe a ReplicaSet to diagnose pod scheduling or image pull failures

kubectl describe replicaset RS_NAME

Read the serial port output from a Compute Engine VM to diagnose boot failures

gcloud compute instances get-serial-port-output INSTANCE_NAME --zone ZONE

Read error and critical log entries from the past hour across all services

gcloud logging read "severity>=ERROR" --freshness 1h --limit 50

Query Cloud Logging for Kubernetes container logs from a GKE cluster

gcloud logging read "resource.type=k8s_container" --limit 50

Show events and routing rules for an ingress to debug traffic routing issues

kubectl describe ingress INGRESS_NAME

Show pod logs from only the last hour to narrow down a recent error

kubectl logs POD_NAME --since=1h

Open an interactive shell session inside a running pod container

kubectl exec -it POD_NAME -- /bin/sh

Check whether the current user has permission to create pods in a namespace

kubectl auth can-i create pods --namespace NAMESPACE
↑ back to top

Deployment Manager20 commands

Update an existing Deployment Manager deployment with a revised config file

gcloud deployment-manager deployments update prod-infra --config prod.yaml

List all Deployment Manager deployments in the current project

gcloud deployment-manager deployments list

Show detailed information about a specific Deployment Manager deployment

gcloud deployment-manager deployments describe DEPLOYMENT_NAME

Create a new Deployment Manager deployment from a YAML config file

gcloud deployment-manager deployments create DEPLOYMENT_NAME --config CONFIG_FILE

Delete an existing Deployment Manager deployment and all its managed resources

gcloud deployment-manager deployments delete DEPLOYMENT_NAME

Update an existing Deployment Manager deployment with a revised config file

gcloud deployment-manager deployments update DEPLOYMENT_NAME --config CONFIG_FILE

List Deployment Manager deployments filtered by operation type

gcloud deployment-manager deployments list --filter "operation.operationType=insert"

List all resource types available for use in Deployment Manager configurations

gcloud deployment-manager types list

List all individual resources created by a Deployment Manager deployment

gcloud deployment-manager resources list --deployment DEPLOYMENT

Show details and current state of a specific resource in a Deployment Manager deployment

gcloud deployment-manager resources describe RESOURCE --deployment DEPLOYMENT

Preview a Deployment Manager deployment without actually creating resources

gcloud deployment-manager deployments create DEPLOYMENT --config CONFIG --preview

Update an existing Deployment Manager deployment with a new configuration file

gcloud deployment-manager deployments update DEPLOYMENT --config CONFIG

Cancel a Deployment Manager deployment that is in preview state

gcloud deployment-manager deployments cancel-preview DEPLOYMENT

List all manifests (config snapshots) for a Deployment Manager deployment

gcloud deployment-manager manifests list --deployment DEPLOYMENT

Show the expanded configuration snapshot for a specific Deployment Manager manifest

gcloud deployment-manager manifests describe MANIFEST --deployment DEPLOYMENT

List all Deployment Manager operations and their current status

gcloud deployment-manager operations list

Show detailed status and error information for a Deployment Manager operation

gcloud deployment-manager operations describe OPERATION

Stop an in-progress Deployment Manager deployment operation

gcloud deployment-manager deployments stop DEPLOYMENT

Remove a Deployment Manager deployment record without deleting the underlying resources

gcloud deployment-manager deployments delete DEPLOYMENT --delete-policy ABANDON

List all Deployment Manager deployments and output as JSON for scripting

gcloud deployment-manager deployments list --format json
↑ back to top

Deployments20 commands

Create a new deployment with a single replica of the specified image

kubectl create deployment DEPLOYMENT_NAME --image IMAGE_NAME

List all deployments and their ready replica counts in the current namespace

kubectl get deployments

Show detailed state, strategy, and events for a specific deployment

kubectl describe deployment DEPLOYMENT_NAME

Delete a deployment and all of its managed replica sets and pods

kubectl delete deployment DEPLOYMENT_NAME

Scale the number of pod replicas in a deployment to a specified count

kubectl scale deployment DEPLOYMENT_NAME --replicas REPLICA_COUNT

Update the container image of a deployment to trigger a rolling update

kubectl set image deployment/DEPLOYMENT_NAME CONTAINER_NAME=IMAGE_NAME

Watch the progress of a rolling update for a deployment until completion

kubectl rollout status deployment/DEPLOYMENT_NAME

Roll back a deployment to its previous revision

kubectl rollout undo deployment/DEPLOYMENT_NAME

Trigger a rolling restart of all pods in a deployment without changing the spec

kubectl rollout restart deployment/DEPLOYMENT_NAME

View the revision history and change causes for a deployment

kubectl rollout history deployment/DEPLOYMENT_NAME

List all replica sets and their desired, current, and ready pod counts

kubectl get replicasets

Apply a partial modification to a deployment using a JSON or YAML patch

kubectl patch deployment DEPLOYMENT_NAME -p PATCH_JSON

Create a Horizontal Pod Autoscaler to automatically scale a deployment based on CPU usage

kubectl autoscale deployment DEPLOYMENT_NAME --min MIN --max MAX --cpu-percent CPU_PERCENT

List all Horizontal Pod Autoscalers and their current scaling metrics

kubectl get hpa

Validate a deployment manifest locally without sending it to the cluster

kubectl apply -f DEPLOYMENT_FILE --dry-run=client

Export a deployment's full specification as YAML for inspection or backup

kubectl get deployment DEPLOYMENT -o yaml

Pause a deployment rollout to safely stage multiple changes

kubectl rollout pause deployment DEPLOYMENT

Resume a paused deployment rollout to continue the update

kubectl rollout resume deployment DEPLOYMENT

List pods matching a specific label selector to verify a deployment's pods

kubectl get pods -l app=APP_LABEL

Set or update an environment variable on all containers in a deployment

kubectl set env deployment DEPLOYMENT KEY=VALUE
↑ back to top

GKE20 commands

Create a new Google Kubernetes Engine cluster with specified node count

gcloud container clusters create CLUSTER_NAME --zone ZONE --num-nodes NUM_NODES

List all GKE clusters in the current project across all zones

gcloud container clusters list

Delete a GKE cluster and all its associated resources

gcloud container clusters delete CLUSTER_NAME --zone ZONE

Fetch kubeconfig credentials to enable kubectl access to a GKE cluster

gcloud container clusters get-credentials CLUSTER_NAME --zone ZONE

Resize the number of nodes in a GKE cluster node pool

gcloud container clusters resize CLUSTER_NAME --num-nodes NUM_NODES --zone ZONE

Add a new node pool to an existing GKE cluster

gcloud container node-pools create POOL_NAME --cluster CLUSTER_NAME --zone ZONE

List all node pools belonging to a specific GKE cluster

gcloud container node-pools list --cluster CLUSTER_NAME --zone ZONE

Update a GKE cluster configuration such as enabling node autoscaling

gcloud container clusters update CLUSTER_NAME --zone ZONE --enable-autoscaling --min-nodes MIN --max-nodes MAX

Stream live logs from a Deployment by referencing the Deployment object directly

kubectl logs deployment/orders-api -f

Update a Deployment's container memory limit using kubectl set resources

kubectl set resources deployment backend --limits=memory=512Mi

Upgrade a specific GKE node pool to a newer Kubernetes version

gcloud container clusters upgrade prod-cluster --node-pool=default-pool --cluster-version=1.28 --zone=us-central1-a

Enable cluster autoscaling on a GKE node pool with min/max node bounds

gcloud container node-pools update default-pool --cluster=prod-cluster --enable-autoscaling --min-nodes=2 --max-nodes=10 --zone=us-central1-a

Roll back a Kubernetes deployment to its previous revision

kubectl rollout undo deployment/api-server

Scale a Kubernetes deployment to a specific replica count and verify

kubectl scale deployment web-api --replicas=8

Create a ConfigMap from a file and inject it as environment variables into a deployment

kubectl create configmap web-config --from-file=config.properties

Configure GKE Workload Identity: bind IAM policy and annotate the Kubernetes service account

gcloud iam service-accounts add-iam-policy-binding gcs-reader@my-project.iam.gserviceaccount.com --role=roles/iam.workloadIdentityUser --member="serviceAccount:my-project.svc.id.goog[prod/ksa-reader]"

Show detailed configuration and status of a GKE cluster

gcloud container clusters describe CLUSTER_NAME --zone ZONE

Remove a node pool from a GKE cluster and drain its nodes

gcloud container node-pools delete POOL_NAME --cluster CLUSTER_NAME --zone ZONE

Show configuration details of a specific GKE node pool

gcloud container node-pools describe POOL_NAME --cluster CLUSTER_NAME --zone ZONE

List all GKE operations in a zone to monitor cluster creation or upgrade progress

gcloud container operations list --zone ZONE
↑ back to top

IAM20 commands

Create a custom IAM role from a YAML definition file

gcloud iam roles create devReadRole --project=my-project --file=role-definition.yaml

List all custom IAM roles defined in a specific project

gcloud iam roles list --project PROJECT_ID

Show the permissions and metadata for a specific IAM role

gcloud iam roles describe ROLE_ID

Create a custom IAM role in a project from a YAML permissions file

gcloud iam roles create ROLE_ID --project PROJECT_ID --file YAML_FILE

Add one or more permissions to an existing custom IAM role in a project

gcloud iam roles update ROLE_ID --project PROJECT_ID --add-permissions PERMISSION

Copy an existing IAM role to create a new custom role in a destination project

gcloud iam roles copy --source SOURCE_ROLE --destination DEST_ROLE --dest-project PROJECT_ID

Revoke a specific IAM role from a member on a project

gcloud projects remove-iam-policy-binding PROJECT_ID --member MEMBER --role ROLE

Replace the entire IAM policy on a project with a policy defined in a JSON file

gcloud projects set-iam-policy PROJECT_ID POLICY_FILE

List only the custom IAM roles defined within a specific project

gcloud iam roles list --project PROJECT_ID

Add a new permission to an existing custom IAM role

gcloud iam roles update ROLE_ID --project PROJECT_ID --add-permissions PERMISSION

Disable a custom IAM role so it cannot be granted to new members

gcloud iam roles disable ROLE_ID --project PROJECT_ID

Restore a previously deleted custom IAM role within the undelete window

gcloud iam roles undelete ROLE_ID --project PROJECT_ID

Retrieve the IAM policy for a resource hierarchy folder

gcloud resource-manager folders get-iam-policy FOLDER_ID

Retrieve the IAM policy for a GCP organization

gcloud organizations get-iam-policy ORG_ID

Grant an IAM role to a member at the folder level

gcloud resource-manager folders add-iam-policy-binding FOLDER_ID --member MEMBER --role ROLE

View the IAM policy that controls who can act as or impersonate a service account

gcloud iam service-accounts get-iam-policy SA_EMAIL

Grant workload identity access so a Kubernetes SA can impersonate a Google SA

gcloud iam service-accounts add-iam-policy-binding SA_EMAIL --role roles/iam.workloadIdentityUser --member MEMBER

Search across all IAM policies in a project to find specific role grants

gcloud asset search-all-iam-policies --scope projects/PROJECT_ID --query QUERY

Create a custom IAM role from a YAML or JSON role definition file

gcloud iam roles create ROLE_ID --project PROJECT_ID --file ROLE_DEFINITION_FILE

Delete a custom IAM role from a project (can be undeleted within 7 days)

gcloud iam roles delete ROLE_ID --project PROJECT_ID
↑ back to top

IAM & Service Accounts20 commands

Create a new IAM service account in the current project

gcloud iam service-accounts create SA_NAME --display-name DISPLAY_NAME

List all service accounts in the current project

gcloud iam service-accounts list

Generate and download a new JSON key file for a service account

gcloud iam service-accounts keys create KEY_FILE --iam-account SA_EMAIL

Grant an IAM role to a member on a specific project

gcloud projects add-iam-policy-binding PROJECT_ID --member MEMBER --role ROLE

Retrieve the full IAM policy (all role bindings) for a project

gcloud projects get-iam-policy PROJECT_ID

List all predefined and custom IAM roles available in the project

gcloud iam roles list

Delete a service account and revoke all its associated credentials

gcloud iam service-accounts delete SA_EMAIL

Show details including display name and unique ID for a service account

gcloud iam service-accounts describe SA_EMAIL

Update the display name of an existing service account

gcloud iam service-accounts update SA_EMAIL --display-name NEW_NAME

Disable a service account to prevent it from authenticating without deleting it

gcloud iam service-accounts disable SA_EMAIL

Re-enable a previously disabled service account

gcloud iam service-accounts enable SA_EMAIL

List all key IDs and their creation times for a service account

gcloud iam service-accounts keys list --iam-account SA_EMAIL

Revoke and delete a specific service account key by its ID

gcloud iam service-accounts keys delete KEY_ID --iam-account SA_EMAIL

Allow a user to impersonate and act as a service account

gcloud iam service-accounts add-iam-policy-binding SA_EMAIL --member user:USER_EMAIL --role roles/iam.serviceAccountUser

Grant a service account the Storage Admin role on a project

gcloud projects add-iam-policy-binding PROJECT_ID --member serviceAccount:SA_EMAIL --role roles/storage.admin

View all IAM bindings on a service account resource itself

gcloud iam service-accounts get-iam-policy SA_EMAIL

Remove a specific IAM role from a service account on a project

gcloud projects remove-iam-policy-binding PROJECT_ID --member serviceAccount:SA_EMAIL --role ROLE

Sign a binary blob using a service account to produce a cryptographic signature

gcloud iam service-accounts sign-blob --iam-account SA_EMAIL INPUT_FILE OUTPUT_FILE

Create a service account with a description in an explicitly specified project

gcloud iam service-accounts create SA_NAME --project PROJECT_ID --description DESCRIPTION

Generate a P12 format service account key for legacy authentication libraries

gcloud iam service-accounts keys create KEY_FILE --iam-account SA_EMAIL --key-file-type p12
↑ back to top

kubectl Advanced20 commands

Create a Role that allows getting and listing pods in the current namespace

kubectl create role POD_READER --verb=get,list --resource=pods

Create a ClusterRole that allows reading secrets across all namespaces

kubectl create clusterrole SECRET_READER --verb=get,list --resource=secrets

Bind a Role to a user so that user gains those permissions in the current namespace

kubectl create rolebinding ALICE_READER --role=pod-reader --user=alice

Bind a ClusterRole to a user, granting those permissions across the entire cluster

kubectl create clusterrolebinding ADMIN_BINDING --clusterrole=cluster-admin --user=admin

Apply a NetworkPolicy manifest from a file to restrict pod-to-pod traffic

kubectl apply -f network-policy.yaml

List all CustomResourceDefinitions installed in the cluster

kubectl get crds

Create a service account in a specific namespace

kubectl create serviceaccount APP_SA -n prod

List all RoleBindings across every namespace in the cluster

kubectl get rolebindings --all-namespaces

Check whether user bob can delete deployments in the staging namespace

kubectl auth can-i delete deployments --as=bob -n staging

Check whether the current user has all permissions on all resources cluster-wide

kubectl auth can-i '*' '*' --all-namespaces

Create a Role in the prod namespace that allows full ConfigMap management

kubectl create role CONFIGMAP_MANAGER --verb=get,list,create,update,delete --resource=configmaps -n prod

Grant a service account view access by binding a ClusterRole via a RoleBinding

kubectl create rolebinding APP_SA_BINDING --clusterrole=view --serviceaccount=default:app-sa

Install a CustomResourceDefinition into the cluster from a YAML manifest

kubectl apply -f crd.yaml

List all instances of a custom resource by its kind name

kubectl get CUSTOM_RESOURCE_KIND

Display the full spec and events for a NetworkPolicy in the prod namespace

kubectl describe networkpolicy POLICY_NAME -n prod

Apply RBAC roles and bindings from a file, updating any that have changed

kubectl auth reconcile -f rbac.yaml

Show the API documentation for the NetworkPolicy spec field

kubectl explain networkpolicy.spec

Check whether the current user can list secrets in the kube-system namespace

kubectl auth can-i list secrets -n kube-system

List all NetworkPolicy resources across every namespace in the cluster

kubectl get networkpolicies --all-namespaces

List all ClusterRoles defined in the cluster

kubectl get clusterroles
↑ back to top

Misc20 commands

Create a new Cloud SQL database instance with specified version and tier

gcloud sql instances create INSTANCE_NAME --database-version DATABASE_VERSION --tier TIER

Create a new Pub/Sub topic for publishing messages

gcloud pubsub topics create TOPIC_NAME

Create a new Pub/Sub subscription attached to an existing topic

gcloud pubsub subscriptions create SUBSCRIPTION_NAME --topic TOPIC_NAME

Read and display log entries from Cloud Logging with an optional filter

gcloud logging read FILTER --limit LIMIT

List all cryptographic keys in a Cloud KMS keyring

gcloud kms keys list --keyring KEYRING_NAME --location LOCATION

Enable a Google Cloud API or service for the current project

gcloud services enable SERVICE_NAME

List all APIs and services currently enabled in the project

gcloud services list --enabled

Submit a build to Cloud Build and push the resulting image to Container Registry

gcloud builds submit --tag gcr.io/PROJECT_ID/IMAGE_NAME

Create a new GCP project with a specified ID and display name

gcloud projects create PROJECT_ID --name NAME

Schedule a GCP project for deletion after a 30-day recovery window

gcloud projects delete PROJECT_ID

Show metadata including project number, labels, and lifecycle state for a project

gcloud projects describe PROJECT_ID

List all Cloud Billing accounts accessible to the current user

gcloud billing accounts list

Attach a billing account to a GCP project to enable paid services

gcloud billing projects link PROJECT_ID --billing-account BILLING_ACCOUNT_ID

Disable an API service on the current project

gcloud services disable SERVICE_NAME

Create a new Secret Manager secret and set its initial value from a file

gcloud secrets create SECRET_NAME --data-file FILE

Read and output the latest version of a Secret Manager secret

gcloud secrets versions access latest --secret SECRET_NAME

List all secrets stored in Secret Manager for the current project

gcloud secrets list

List all Cloud KMS key rings in a specific region

gcloud kms keyrings list --location LOCATION

List only the APIs currently enabled on the active project

gcloud services list --enabled

Create a new Cloud KMS symmetric encryption key in a key ring

gcloud kms keys create KEY_NAME --location LOCATION --keyring KEYRING --purpose encryption
↑ back to top

Namespaces20 commands

List all namespaces in the cluster and their status

kubectl get namespaces

Create a new namespace to isolate resources within the cluster

kubectl create namespace NAMESPACE_NAME

Delete a namespace and all resources contained within it

kubectl delete namespace NAMESPACE_NAME

List all pods within a specific namespace using the -n flag

kubectl get pods -n NAMESPACE

Show detailed information about a Kubernetes namespace including resource quotas and limits

kubectl describe namespace NAMESPACE_NAME

Set the default namespace for the current kubectl context so you don't need -n on every command

kubectl config set-context --current --namespace NAMESPACE_NAME

Export a namespace definition as YAML

kubectl get namespace NAMESPACE -o yaml

List all workloads, services, and other resources within a namespace

kubectl get all -n NAMESPACE

Delete all deployments, pods, services and other resources within a namespace

kubectl delete all --all -n NAMESPACE

Create a ResourceQuota to limit total resource consumption within a namespace

kubectl create quota QUOTA_NAME --namespace NAMESPACE --hard=pods=10,requests.cpu=4

Show all resource quotas and their current usage in a namespace

kubectl get resourcequota -n NAMESPACE

Show current consumption versus limits for a specific resource quota

kubectl describe resourcequota QUOTA_NAME -n NAMESPACE

List LimitRange policies that set default and maximum resource limits in a namespace

kubectl get limitrange -n NAMESPACE

List all recent events in a specific namespace to diagnose resource issues

kubectl get events -n NAMESPACE

Check whether a specific user has permission to list pods in a namespace

kubectl auth can-i list pods --namespace NAMESPACE --as USER

Add a label to a namespace, commonly used for network policy targeting

kubectl label namespace NAMESPACE KEY=VALUE

Apply a manifest file into a specific namespace

kubectl apply -f MANIFEST_FILE --namespace NAMESPACE

List all service accounts in a specific namespace

kubectl get serviceaccounts -n NAMESPACE

Apply a LimitRange manifest to set default CPU and memory limits in a namespace

kubectl apply -f limitrange.yaml -n NAMESPACE

List all pods across every namespace in the cluster

kubectl get pods --all-namespaces
↑ back to top

Networking20 commands

Create bidirectional VPC Network Peering between two projects

gcloud compute networks peerings create peer-a-to-b --network=vpc-a --peer-project=project-b --peer-network=vpc-b --project=project-a

List all VPC networks in the current project

gcloud compute networks list

Show detailed information about a specific VPC network

gcloud compute networks describe NETWORK_NAME

Create a new VPC network with custom subnet mode for fine-grained subnet control

gcloud compute networks create NETWORK_NAME --subnet-mode custom

List all VPC firewall rules in the current project

gcloud compute firewall-rules list

Create a firewall rule to allow TCP traffic on a specific port within a VPC network

gcloud compute firewall-rules create RULE_NAME --allow tcp:PORT --network NETWORK_NAME

List all subnets across all VPC networks in the current project

gcloud compute networks subnets list

Create a new subnet within a VPC network with a specified IP range

gcloud compute networks subnets create SUBNET --network NETWORK --region REGION --range RANGE

Show detailed configuration of a subnet including its CIDR range and secondary ranges

gcloud compute networks subnets describe SUBNET --region REGION

Delete a VPC network after removing all its resources

gcloud compute networks delete NETWORK

Update an existing VPC firewall rule to change allowed protocols or ports

gcloud compute firewall-rules update RULE_NAME --allow PROTOCOL:PORT

Delete a VPC firewall rule from the current project

gcloud compute firewall-rules delete RULE_NAME

Show the full configuration of a specific VPC firewall rule

gcloud compute firewall-rules describe RULE_NAME

List all static IP addresses reserved in the current project

gcloud compute addresses list

Show the IP address value and status of a reserved static address

gcloud compute addresses describe ADDRESS_NAME --region REGION

Release a reserved static IP address back to the shared pool

gcloud compute addresses delete ADDRESS_NAME --region REGION

List all VPC routes in the current project

gcloud compute routes list

List all load balancer forwarding rules in the current project

gcloud compute forwarding-rules list

List all backend services configured for load balancing

gcloud compute backend-services list

Expand the IP range of an existing subnet to a larger CIDR prefix

gcloud compute networks subnets expand-ip-range SUBNET --region REGION --prefix-length PREFIX
↑ back to top

Nodes20 commands

List all nodes in the cluster with their status and Kubernetes version

kubectl get nodes

Show detailed information including capacity, conditions, and allocated resources for a node

kubectl describe node NODE_NAME

Mark a node as unschedulable to prevent new pods from being assigned to it

kubectl cordon NODE_NAME

Mark a previously cordoned node as schedulable again to accept new pods

kubectl uncordon NODE_NAME

Safely evict all pods from a node in preparation for maintenance

kubectl drain NODE_NAME --ignore-daemonsets --delete-emptydir-data

Apply a taint to a node to repel pods that do not tolerate the taint

kubectl taint nodes NODE_NAME KEY=VALUE:EFFECT

Display CPU and memory usage metrics for all nodes in the cluster

kubectl top node

Add or update a label on a node for scheduling constraints and selection

kubectl label nodes NODE_NAME KEY=VALUE

List all nodes with extended details including internal IP, OS image, and container runtime

kubectl get nodes -o wide

List all cluster nodes with their full set of labels

kubectl get nodes --show-labels

Remove a label from a node by appending a dash to the key name

kubectl label node NODE_NAME KEY-

Remove a taint from a node by appending a dash to the key name

kubectl taint nodes NODE_NAME KEY-

Export a node's full specification including conditions and allocatable resources as YAML

kubectl get node NODE_NAME -o yaml

Show node CPU and memory usage sorted by highest CPU consumption

kubectl top nodes --sort-by cpu

Filter the node list to only nodes matching a specific label selector

kubectl get nodes --selector KEY=VALUE

Extract the allocatable CPU and memory resources from a specific node

kubectl get node NODE_NAME -o jsonpath='{.status.allocatable}'

Remove a node object from the cluster (after draining it first)

kubectl delete node NODE_NAME

Extract the kubelet version from every node to verify upgrade status

kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.kubeletVersion}'

Add or update an annotation on a node

kubectl annotate node NODE_NAME KEY=VALUE

Mark a node as unschedulable using a JSON patch without draining it

kubectl patch node NODE_NAME -p '{"spec":{"unschedulable":true}}'
↑ back to top

Operations20 commands

Create a Cloud Logging sink to export audit logs to Cloud Storage

gcloud logging sinks create audit-export storage.googleapis.com/compliance-logs-bucket --log-filter='logName:cloudaudit.googleapis.com'

Write a log entry to a named Cloud Logging log for testing or manual audit purposes

gcloud logging write LOG_NAME "MESSAGE"

List all available log names in the current project

gcloud logging logs list

List all log sinks configured to export logs to external destinations

gcloud logging sinks list

List all log-based metrics defined in the current project

gcloud logging metrics list

List all Cloud Monitoring dashboards in the current project

gcloud monitoring dashboards list

Create a log sink to export matching log entries to Cloud Storage, BigQuery, or Pub/Sub

gcloud logging sinks create SINK_NAME DESTINATION --log-filter FILTER

Delete a log export sink from the current project

gcloud logging sinks delete SINK_NAME

Show the destination and filter configuration for a log sink

gcloud logging sinks describe SINK_NAME

Create a log-based metric to count or extract values from matching log entries

gcloud logging metrics create METRIC_NAME --description DESC --log-filter FILTER

Delete a log-based metric from the current project

gcloud logging metrics delete METRIC_NAME

List log buckets available for storing log data in a region

gcloud logging buckets list --location LOCATION

List all Cloud Monitoring alerting policies in the current project

gcloud monitoring policies list

List all notification channels configured for Cloud Monitoring alerts

gcloud monitoring channels list

Query Cloud Logging for error-level logs from Compute Engine instances

gcloud logging read "resource.type=gce_instance AND severity>=ERROR" --limit 20

Read Cloud Audit Logs for admin activity in the current project

gcloud logging read "logName=projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Factivity" --limit 10

List all log views available for a specific log bucket

gcloud logging views list --bucket LOG_BUCKET --location LOCATION

Show the full widget configuration of a Cloud Monitoring dashboard

gcloud monitoring dashboards describe DASHBOARD_NAME

Update the log filter on an existing log export sink

gcloud logging sinks update SINK_NAME --log-filter NEW_FILTER

List recent error events from Cloud Error Reporting for a specific service

gcloud beta error-reporting events list --service SERVICE
↑ back to top

Pods20 commands

List all pods in the current namespace

kubectl get pods

List all pods across every namespace in the cluster

kubectl get pods --all-namespaces

Show detailed information including events and conditions for a specific pod

kubectl describe pod POD_NAME

Delete a specific pod from the current namespace

kubectl delete pod POD_NAME

Open an interactive shell session inside a running pod container

kubectl exec -it POD_NAME -- /bin/sh

Print the stdout logs from a specific pod container

kubectl logs POD_NAME

Forward a local port to a port on a specific pod for debugging access

kubectl port-forward pod/POD_NAME LOCAL_PORT:REMOTE_PORT

Copy files between a pod container and the local filesystem

kubectl cp POD_NAME:REMOTE_PATH LOCAL_PATH

Display CPU and memory usage metrics for pods in the current namespace

kubectl top pod

Create and run a single pod with the specified container image

kubectl run POD_NAME --image IMAGE_NAME

List all pods along with their associated label key-value pairs

kubectl get pods --show-labels

List pods with additional details including node name and IP address

kubectl get pods -o wide

Filter and list pods matching a specific label selector

kubectl get pods -l KEY=VALUE

Output the full YAML specification of a specific pod resource

kubectl get pod POD_NAME -o yaml

Add or update an annotation on a specific pod resource

kubectl annotate pod POD_NAME KEY=VALUE

Add or update a label on a specific pod for selection and organization

kubectl label pod POD_NAME KEY=VALUE

List pods sorted by their start time to identify the most recently started pods

kubectl get pods --sort-by=.status.startTime

Force-restart all pods in a namespace by deleting them (deployments recreate them)

kubectl delete pods --all -n NAMESPACE

Block until a pod reaches the Ready state or the timeout expires

kubectl wait pod POD_NAME --for=condition=Ready --timeout=60s

Extract the container image names for all pods in the current namespace

kubectl get pods -o jsonpath='{.items[*].spec.containers[*].image}'
↑ back to top

Pub/Sub20 commands

Grant a service account the Pub/Sub Publisher role on a specific topic

gcloud pubsub topics add-iam-policy-binding order-events --member=serviceAccount:app-sa@my-project.iam.gserviceaccount.com --role=roles/pubsub.publisher

List all Pub/Sub topics in the current project

gcloud pubsub topics list

Delete a Pub/Sub topic and detach all its subscriptions

gcloud pubsub topics delete TOPIC_NAME

List all Pub/Sub subscriptions in the current project

gcloud pubsub subscriptions list

Pull and acknowledge pending messages from a Pub/Sub subscription

gcloud pubsub subscriptions pull SUB_NAME

Publish a message string to a Pub/Sub topic from the command line

gcloud pubsub topics publish TOPIC_NAME --message MESSAGE

Show configuration including ack deadline and push endpoint for a Pub/Sub subscription

gcloud pubsub subscriptions describe SUBSCRIPTION

Delete a Pub/Sub subscription and stop message delivery

gcloud pubsub subscriptions delete SUBSCRIPTION

Extend the acknowledgement deadline for an in-flight Pub/Sub message

gcloud pubsub subscriptions modify-message-ack-deadline SUBSCRIPTION --ack-deadline 60 --ack-ids ACK_ID

Rewind or fast-forward a Pub/Sub subscription to a specific timestamp

gcloud pubsub subscriptions seek SUBSCRIPTION --time TIME

Show configuration and associated subscriptions for a Pub/Sub topic

gcloud pubsub topics describe TOPIC

Create a Pub/Sub snapshot to preserve the current message backlog for a subscription

gcloud pubsub snapshots create SNAPSHOT --subscription SUBSCRIPTION

List all Pub/Sub snapshots in the current project

gcloud pubsub snapshots list

Create a Pub/Sub subscription with a custom acknowledgement deadline of 60 seconds

gcloud pubsub subscriptions create SUBSCRIPTION --topic TOPIC --ack-deadline 60

Create a push subscription that delivers messages to an HTTPS endpoint

gcloud pubsub subscriptions create SUBSCRIPTION --topic TOPIC --push-endpoint URL

Pull and automatically acknowledge up to 10 messages from a Pub/Sub subscription

gcloud pubsub subscriptions pull SUBSCRIPTION --max-messages 10 --auto-ack

Allow anyone to publish messages to a Pub/Sub topic without authentication

gcloud pubsub topics add-iam-policy-binding TOPIC --member allUsers --role roles/pubsub.publisher

Acknowledge a specific Pub/Sub message by its ack ID to prevent redelivery

gcloud pubsub subscriptions ack SUBSCRIPTION --ack-ids ACK_ID

Update the HTTPS push endpoint URL on an existing push subscription

gcloud pubsub subscriptions modify-push-config SUBSCRIPTION --push-endpoint NEW_URL

List all Pub/Sub topics in JSON format for scripting or automation

gcloud pubsub topics list --format json
↑ back to top

Resource Operations20 commands

Apply a YAML or JSON resource configuration file to create or update resources

kubectl apply -f FILENAME

Create resources from a YAML or JSON file, failing if they already exist

kubectl create -f FILENAME

Delete all resources defined in a YAML or JSON configuration file

kubectl delete -f FILENAME

Show differences between the live resource state and a local configuration file

kubectl diff -f FILENAME

List all common resource types (pods, services, deployments, etc.) in the current namespace

kubectl get all

List all supported resource types, their short names, and API groups in the cluster

kubectl api-resources

List all available API group versions supported by the cluster

kubectl api-versions

Display the schema and documentation fields for a Kubernetes resource type

kubectl explain RESOURCE

List all persistent volumes in the cluster and their bound status

kubectl get persistentvolumes

List all persistent volume claims and their binding status in the current namespace

kubectl get persistentvolumeclaims

List all batch jobs and their completion status in the current namespace

kubectl get jobs

List all CronJobs and their schedules in the current namespace

kubectl get cronjobs

List all DaemonSets and their desired and available pod counts

kubectl get daemonsets

List all StatefulSets and their ready replica counts in the current namespace

kubectl get statefulsets

List all network policies controlling traffic flow between pods

kubectl get networkpolicies

Replace an existing Kubernetes resource with the definition in a file

kubectl replace -f FILE

List all workloads, services and core resources across every namespace

kubectl get all --all-namespaces

Create a resource and save its configuration as an annotation for future apply operations

kubectl create -f FILE --save-config

Apply all manifests in a directory and delete labelled resources not present in the directory

kubectl apply --prune -f DIRECTORY -l APP=LABEL

Validate a manifest against the live API server without creating the resource

kubectl create -f FILE --dry-run=server -o yaml
↑ back to top

Services20 commands

List all services and their cluster IPs and ports in the current namespace

kubectl get services

Create a service to expose a deployment's pods to network traffic

kubectl expose deployment DEPLOYMENT_NAME --port PORT --type TYPE

Show detailed information including endpoints for a specific service

kubectl describe service SERVICE_NAME

Remove a service and stop routing traffic to its backing pods

kubectl delete service SERVICE_NAME

Open a service's live configuration in an editor for in-place modification

kubectl edit service SERVICE_NAME

List all ingress resources and their associated hosts and paths

kubectl get ingress

List all endpoints showing the backing pod IPs for each service

kubectl get endpoints

Expose a single pod as a LoadBalancer service with an external IP

kubectl expose pod POD_NAME --port PORT --type LoadBalancer

Expose a deployment as a NodePort service accessible on every cluster node

kubectl expose deployment DEPLOYMENT --port PORT --target-port TARGET_PORT --type NodePort

Export a service definition as YAML to inspect its selectors and ports

kubectl get service SERVICE -o yaml

Change the type of a service from ClusterIP to LoadBalancer using a JSON patch

kubectl patch service SERVICE -p '{"spec":{"type":"LoadBalancer"}}'

Create an internal ClusterIP service with a specific port mapping

kubectl create service clusterip SERVICE --tcp=PORT:TARGET_PORT

Create a NodePort service that forwards traffic to a specified target port

kubectl create service nodeport SERVICE --tcp=PORT:TARGET_PORT

Create a LoadBalancer service that provisions an external cloud load balancer

kubectl create service loadbalancer SERVICE --tcp=PORT

Create an Ingress resource to route HTTP traffic to a service

kubectl create ingress INGRESS --rule HOST/PATH=SERVICE:PORT

Delete an Ingress resource and remove its routing rules

kubectl delete ingress INGRESS

Apply a NetworkPolicy manifest to restrict ingress or egress traffic between pods

kubectl apply -f networkpolicy.yaml

List all NetworkPolicy resources in a specific namespace

kubectl get networkpolicies -n NAMESPACE

Forward a local port to a Kubernetes service for local testing without a public endpoint

kubectl port-forward service/SERVICE LOCAL_PORT:SERVICE_PORT

Export the default service account definition for the current namespace as YAML

kubectl get serviceaccount default -o yaml
↑ back to top

Terraform20 commands

Initialise a Terraform working directory, downloading providers and modules

terraform init

Preview the infrastructure changes Terraform will make without applying them

terraform plan

Apply the Terraform configuration to create or update real infrastructure

terraform apply

Destroy all infrastructure resources managed by the current Terraform configuration

terraform destroy

Check Terraform configuration files for syntax errors and internal consistency

terraform validate

Reformat Terraform configuration files to the canonical style

terraform fmt

Print the output values defined in the Terraform configuration

terraform output

List all resources tracked in the current Terraform state file

terraform state list

Display a human-readable view of the current Terraform state

terraform show

Import an existing infrastructure resource into the Terraform state without recreating it

terraform import RESOURCE_ADDRESS RESOURCE_ID

Generate a Terraform execution plan and save it to a file for later use

terraform plan -out=tfplan

Apply a previously saved Terraform execution plan file

terraform apply tfplan

Apply a Terraform configuration with an inline variable override

terraform apply -var='project_id=my-project'

Create a new Terraform workspace for environment isolation

terraform workspace new WORKSPACE_NAME

Switch to an existing Terraform workspace

terraform workspace select WORKSPACE_NAME

Apply Terraform changes to a single specific resource, ignoring others

terraform apply -target=google_compute_instance.web

Move a resource to a different address in the Terraform state file without recreating it

terraform state mv OLD_RESOURCE_ADDRESS NEW_RESOURCE_ADDRESS

Remove a resource from Terraform state without destroying the real infrastructure

terraform state rm RESOURCE_ADDRESS

Mark a Terraform-managed resource for forced recreation on the next apply

terraform taint RESOURCE_ADDRESS

Apply Terraform changes without prompting for interactive confirmation

terraform apply -auto-approve
↑ back to top

Reading commands is one thing — knowing them under exam pressure is another.

Practice with interactive quizzes →

Free easy mode · Premium hard mode · Adaptive learning