GCP gcloud CLI Commands Cheat Sheet
1. Project & Configuration
Authenticate gcloud:
gcloud auth login
List current config:
gcloud config list
Set active project:
gcloud config set project [PROJECT_ID]
List projects:
gcloud projects list
2. Compute Engine (VMs)
Create VM:
gcloud compute instances create [INSTANCE_NAME] --zone=[ZONE] --machine-type=[TYPE]
--image-family=[FAMILY] --image-project=[PROJECT]
List VMs:
gcloud compute instances list
Delete VM:
gcloud compute instances delete [NAME]
SSH to VM:
gcloud compute ssh [INSTANCE_NAME]
3. Cloud Storage
Create bucket:
gcloud storage buckets create gs://[BUCKET_NAME] --location=[REGION]
Upload file:
gcloud storage cp [LOCAL_FILE] gs://[BUCKET_NAME]/
List buckets:
gcloud storage ls
Delete file:
gcloud storage rm gs://[BUCKET_NAME]/[FILE]
4. IAM
Add IAM policy:
gcloud projects add-iam-policy-binding [PROJECT_ID] --member='user:[EMAIL]' --role='roles/viewer'
Create service account:
gcloud iam service-accounts create [NAME] --display-name='[DESCRIPTION]'
List roles:
gcloud iam roles list
5. Kubernetes (GKE)
Create GKE cluster:
gcloud container clusters create [CLUSTER_NAME] --zone=[ZONE] --num-nodes=3
Get credentials:
gcloud container clusters get-credentials [CLUSTER_NAME] --zone=[ZONE]
List pods:
kubectl get pods
6. App Engine
Create app:
gcloud app create --region=[REGION]
Deploy app:
gcloud app deploy
Open app:
gcloud app browse
7. Cloud Functions
Deploy function:
gcloud functions deploy [NAME] --runtime=[RUNTIME] --trigger-http --allow-unauthenticated
List functions:
gcloud functions list
8. Cloud Pub/Sub
Create topic:
gcloud pubsub topics create [TOPIC_NAME]
Create subscription:
gcloud pubsub subscriptions create [SUB_NAME] --topic=[TOPIC_NAME]
9. Billing & APIs
Enable API:
gcloud services enable compute.googleapis.com
List billing accounts:
gcloud billing accounts list