Google Cloud GCloud Commands Cheat Sheet

Google Cloud Config

PURPOSECOMMAND
List projectsgcloud config listgcloud config list project
List projectsgcloud config listgcloud config list project
Show project infogcloud compute project-info describe
Switch projectgcloud config set project <project-id>
Set the active accountgcloud config set account <ACCOUNT>
Set default regiongcloud config set compute/region us-west
Set default zonegcloud config set compute/zone us-west1-b
List configurationsgcloud config configurations list
Activate configurationgcloud config configurations activate

EzoicGoogle Cloud IAM

PURPOSECOMMAND
get project rolesgcloud projects get-iam-policy
copy roles across org and projectsgcloud iam roles copy
get project rolesgcloud projects get-iam-policy
copy roles across org and projectsgcloud iam roles copy

EzoicGoogle Cloud Auth

PURPOSECOMMAND
Display a list of credentialed accountsgcloud auth list
Authenticate client using service accountgcloud auth activate-service-account --key-file <key-file>
Auth to GCP Container Registrygcloud auth configure-docker
Print token for active accountgcloud auth print-access-token, gcloud auth print-refresh-token
Revoke previous generated credentialgcloud auth <application-default> revoke

Google Cloud Storage

PURPOSECOMMAND
List all buckets and filesgsutil lsgsutil ls -lh gs://<bucket-name>
Create bucketgsutil mb gs://<bucket-name>
Download filegsutil cp gs://<bucket-name>/<dir-path>/app.txt
Upload filegsutil cp <filename> gs://<bucket-name>/<directory>/
Delete filegsutil rm gs://<bucket-name>/<filepath>
Move filegsutil mv <src-filepath> gs://<bucket-name>/<directory>/<dest-filepath>
Copy foldergsutil cp -r ./conf gs://<bucket-name>/
Show disk usagegsutil du -h gs://<bucket-name/<directory>
Make all files readablegsutil -m acl set -R -a public-read gs://<bucket-name>/
Create signed url with durationgsutil signurl -d 1m

Google Kubernetes Engine

PURPOSECOMMAND
create clustergcloud container clusters create cluster-name --num-nodes 1
List all container clustersgcloud container clusters list
Set kubectl contextgcloud container clusters get-credentials <cluster-name>
Set default clustergcloud config set container/cluster cluster-name
resize existing clustergcloud container clusters resize --num-nodes

Google Cloud Compute Engine

PURPOSECOMMAND
List all instancesgcloud compute instances list , gcloud compute instance-templates list
Show instance infogcloud compute instances describe "<instance-name>" --project "<project-name>" --zone "us-west2-a"
Stop an instancegcloud compute instances stop instance-name
Start an instancegcloud compute instances start instance-name
Create an instancegcloud compute instances create vm1 --image image-1 --tags test --zone "<zone>" --machine-type f1-micro
Create premptible instancegcloud compute instances create "preempt" --preemptible
SSH to instancegcloud compute ssh --project "<project-name>" --zone "<zone-name>" "<instance-name>"
Images listgcloud compute images list

Virtual Private Network

PURPOSECOMMAND
List all networksgcloud compute networks list
Detail of one networkgcloud compute networks describe <network-name> --format json
Create networkgcloud compute networks create <network-name>
Create subnetgcloud compute networks subnets create subnet1 --network subnet-1 --range 10.0.0.0/24
List all firewall rulesgcloud compute firewall-rules list
List all forwarding rulesgcloud compute forwarding-rules list
Describe one firewall rulegcloud compute firewall-rules describe <rule-name>
Create firewall rulegcloud compute firewall-rules create my-rule --network default --allow tcp:22
Update firewall rulegcloud compute firewall-rules update default --network default --allow tcp:80

Components

PURPOSECOMMAND
List down the componentsgcloud components list
Update the componentsgcloud components update
Install the componentsgcloud components install <component-name>

Deployment Manager

PURPOSECOMMAND
Create deploymentsgcloud deployment-manager deployments create
Update deploymentsgcloud deployment-manager deployments update

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started