Here’s a cheat sheet for common Google Cloud Platform (GCP) commands and operations using the Google Cloud SDK (gcloud) and other relevant tools:
Google Cloud SDK Installation
Install Google Cloud SDK:
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-<VERSION>-<OS>-<ARCH>.tar.gz
tar -zxvf google-cloud-sdk-<VERSION>-<OS>-<ARCH>.tar.gz
./google-cloud-sdk/install.sh
Authentication and Configuration
Authenticate with Google Cloud:
gcloud auth login
Set Default Project:
gcloud config set project your-project-id
Set Default Zone/Region:
gcloud config set compute/zone your-zone
Compute Engine
List Compute Engine Instances:
gcloud compute instances list
Create Compute Engine Instance:
gcloud compute instances create instance-name --image-family image-family --image-project image-project
SSH into Compute Engine Instance:
gcloud compute ssh instance-name
Google Cloud Storage
List Buckets:
gsutil ls
Copy File to Bucket:
gsutil cp local-file.txt gs://your-bucket/
Copy File from Bucket:
gsutil cp gs://your-bucket/file.txt local-file.txt
Cloud Functions
List Cloud Functions:
gcloud functions list
Deploy Cloud Function:
gcloud functions deploy function-name --runtime runtime --trigger-http --allow-unauthenticated
Kubernetes Engine
List Kubernetes Clusters:
gcloud container clusters list
Create Kubernetes Cluster:
gcloud container clusters create cluster-name
Deploy Application to Kubernetes:
kubectl apply -f your-app.yaml
Cloud SQL
List Cloud SQL Instances:
gcloud sql instances list
Create Cloud SQL Instance:
gcloud sql instances create instance-name --database-version MYSQL_5_7 --tier db-n1-standard-1 --region your-region
BigQuery
List BigQuery Datasets:
bq ls
Run BigQuery Query:
bq query --use_legacy_sql=false 'SELECT * FROM your-dataset.your-table'
Pub/Sub
List Pub/Sub Topics:
gcloud pubsub topics list
Create Pub/Sub Topic:
gcloud pubsub topics create your-topic
IAM (Identity and Access Management)
List IAM Service Accounts:
gcloud iam service-accounts list
Create IAM Service Account:
gcloud iam service-accounts create your-service-account --description "Your Service Account" --display-name "Service Account"
These commands cover some basic GCP CLI operations. Adjust the parameters according to your specific use case and explore the Google Cloud SDK documentation for more options and details: Google Cloud SDK Reference.