Google Cloud Platform (GCP) CLI

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/OptionExampleDescription
gcloud initgcloud initInitialize, authorize, and configure the gcloud CLI
gcloud auth logingcloud auth loginAuthorize gcloud to access Google Cloud using your user account credentials
gcloud config setgcloud config set project my-projectSet a configuration value (e.g., project, region, zone)
gcloud config listgcloud config listList all active configuration settings

Project Management #

Command/OptionExampleDescription
gcloud projects creategcloud projects create my-projectCreate a new project
gcloud projects listgcloud projects listList all projects
gcloud projects deletegcloud projects delete my-projectDelete a project

Compute Engine #

Command/OptionExampleDescription
gcloud compute instances creategcloud compute instances create my-instance --zone=us-central1-aCreate a new VM instance
gcloud compute instances listgcloud compute instances listList all VM instances
gcloud compute instances startgcloud compute instances start my-instance --zone=us-central1-aStart a VM instance
gcloud compute instances stopgcloud compute instances stop my-instance --zone=us-central1-aStop a VM instance
gcloud compute instances deletegcloud compute instances delete my-instance --zone=us-central1-aDelete a VM instance

Cloud Storage #

Command/OptionExampleDescription
gsutil lsgsutil lsList all buckets
gsutil mbgsutil mb gs://my-bucketCreate a new bucket
gsutil rmgsutil rm -r gs://my-bucketRemove a bucket and its contents
gsutil cpgsutil cp file.txt gs://my-bucket/Copy a file to a bucket
gsutil rsyncgsutil rsync -r . gs://my-bucketSynchronize a directory with a bucket

IAM (Identity and Access Management) #

Command/OptionExampleDescription
gcloud iam roles listgcloud iam roles listList all roles
gcloud iam service-accounts creategcloud iam service-accounts create my-saCreate a new service account
gcloud iam service-accounts listgcloud iam service-accounts listList all service accounts
gcloud projects add-iam-policy-bindinggcloud projects add-iam-policy-binding my-project --member=serviceAccount:my-sa@my-project.iam.gserviceaccount.com --role=roles/editorAdd IAM policy binding to a project

Kubernetes Engine #

Command/OptionExampleDescription
gcloud container clusters creategcloud container clusters create my-cluster --zone=us-central1-aCreate a new Kubernetes cluster
gcloud container clusters listgcloud container clusters listList all Kubernetes clusters
gcloud container clusters deletegcloud container clusters delete my-cluster --zone=us-central1-aDelete a Kubernetes cluster
gcloud container clusters get-credentialsgcloud container clusters get-credentials my-cluster --zone=us-central1-aGet credentials for a Kubernetes cluster

App Engine #

Command/OptionExampleDescription
gcloud app creategcloud app create --region=us-centralCreate a new App Engine application
gcloud app deploygcloud app deployDeploy the app to App Engine
gcloud app browsegcloud app browseOpen the deployed app in a web browser
gcloud app logs tailgcloud app logs tailStream the logs from App Engine

Cloud Functions #

Command/OptionExampleDescription
gcloud functions deploygcloud functions deploy my-function --runtime nodejs10 --trigger-http --entry-point myFunctionDeploy a new cloud function
gcloud functions callgcloud functions call my-functionCall a deployed cloud function
gcloud functions deletegcloud functions delete my-functionDelete a cloud function
gcloud functions logs readgcloud functions logs read my-functionRead 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.

Google Cloud Platform (GCP) CLI

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.