GCP CLI Cheatsheet
#
The Google Cloud Platform Command Line Interface (gcloud CLI) is a tool to manage and configure Google Cloud resources. It provides the primary CLI to interact with Google Cloud services.
Configuration
#
Command/Option | Example | Description |
---|
gcloud init | gcloud init | Initialize, authorize, and configure the gcloud CLI |
gcloud auth login | gcloud auth login | Authorize gcloud to access Google Cloud using your user account credentials |
gcloud config set | gcloud config set project my-project | Set a configuration value (e.g., project, region, zone) |
gcloud config list | gcloud config list | List all active configuration settings |
Project Management
#
Command/Option | Example | Description |
---|
gcloud projects create | gcloud projects create my-project | Create a new project |
gcloud projects list | gcloud projects list | List all projects |
gcloud projects delete | gcloud projects delete my-project | Delete a project |
Compute Engine
#
Command/Option | Example | Description |
---|
gcloud compute instances create | gcloud compute instances create my-instance --zone=us-central1-a | Create a new VM instance |
gcloud compute instances list | gcloud compute instances list | List all VM instances |
gcloud compute instances start | gcloud compute instances start my-instance --zone=us-central1-a | Start a VM instance |
gcloud compute instances stop | gcloud compute instances stop my-instance --zone=us-central1-a | Stop a VM instance |
gcloud compute instances delete | gcloud compute instances delete my-instance --zone=us-central1-a | Delete a VM instance |
Cloud Storage
#
Command/Option | Example | Description |
---|
gsutil ls | gsutil ls | List all buckets |
gsutil mb | gsutil mb gs://my-bucket | Create a new bucket |
gsutil rm | gsutil rm -r gs://my-bucket | Remove a bucket and its contents |
gsutil cp | gsutil cp file.txt gs://my-bucket/ | Copy a file to a bucket |
gsutil rsync | gsutil rsync -r . gs://my-bucket | Synchronize a directory with a bucket |
IAM (Identity and Access Management)
#
Command/Option | Example | Description |
---|
gcloud iam roles list | gcloud iam roles list | List all roles |
gcloud iam service-accounts create | gcloud iam service-accounts create my-sa | Create a new service account |
gcloud iam service-accounts list | gcloud iam service-accounts list | List all service accounts |
gcloud projects add-iam-policy-binding | gcloud projects add-iam-policy-binding my-project --member=serviceAccount:my-sa@my-project.iam.gserviceaccount.com --role=roles/editor | Add IAM policy binding to a project |
Kubernetes Engine
#
Command/Option | Example | Description |
---|
gcloud container clusters create | gcloud container clusters create my-cluster --zone=us-central1-a | Create a new Kubernetes cluster |
gcloud container clusters list | gcloud container clusters list | List all Kubernetes clusters |
gcloud container clusters delete | gcloud container clusters delete my-cluster --zone=us-central1-a | Delete a Kubernetes cluster |
gcloud container clusters get-credentials | gcloud container clusters get-credentials my-cluster --zone=us-central1-a | Get credentials for a Kubernetes cluster |
App Engine
#
Command/Option | Example | Description |
---|
gcloud app create | gcloud app create --region=us-central | Create a new App Engine application |
gcloud app deploy | gcloud app deploy | Deploy the app to App Engine |
gcloud app browse | gcloud app browse | Open the deployed app in a web browser |
gcloud app logs tail | gcloud app logs tail | Stream the logs from App Engine |
Cloud Functions
#
Command/Option | Example | Description |
---|
gcloud functions deploy | gcloud functions deploy my-function --runtime nodejs10 --trigger-http --entry-point myFunction | Deploy a new cloud function |
gcloud functions call | gcloud functions call my-function | Call a deployed cloud function |
gcloud functions delete | gcloud functions delete my-function | Delete a cloud function |
gcloud functions logs read | gcloud functions logs read my-function | Read logs for a cloud function |
This cheatsheet covers the most commonly used GCP CLI commands and options, helping you to manage configurations, projects, compute instances, storage, IAM, Kubernetes, App Engine, and Cloud Functions effectively.