This is just the formatted version of the post originally created by Sarath Tamminana in Medium: Google Cloud Platform Command line cheat sheet
-
To authenticate a user account with gcloud and minimal user output
gcloud auth login \ --brief
-
To list all credentialed accounts and identify the current active account
gcloud auth list
-
To revoke credentials for a user account (like logging out)
gcloud auth revoke [email protected]
-
To authorize gcloud to access Google Cloud Platform using an existing service account while also specifying a project
gcloud auth activate-service-account [email protected] \ --key-file=/path/key.json \ --project=sampleproject
-
To set an existing account to be the current active account, run:
gcloud config set core/account [email protected]
-
If you don’t have an existing account, create one using:
gcloud init
-
To list the active account name:
gcloud auth list \ --filter=status:ACTIVE \ --format=”value(account)”
-
To list the inactive account names with prefix test:
gcloud auth list \ --filter=”-status:ACTIVE account:test*” \ --format=”value(account)”
-
To obtain access credentials for your user account
gcloud auth login
-
To list down the service accounts
gcloud iam service-accounts list
-
To create a role
gcloud iam roles create
-
To list down the roles
gcloud iam roles list
-
To list down the projects
gcloud projects list
-
To describe the roles
gcloud iam roles describe
-
To create a configuration
gcloud config configurations create quantiphi
-
To list down the configurations
gcloud config configurations list
-
To activate the configuration
gcloud config configurations activate quantiphi
-
To set an account
gcloud config set account [email protected]
-
To list down the projects
gcloud projects list
-
To set the projects
gcloud config set project quantiphi-project
-
To list down all the active configurations
gcloud config list
-
To set the region
gcloud config set compute/region us-west1
-
To set the zone
gcloud config set compute/zone us-west1-a
-
To list down the regions
gcloud compute regions list
-
To list down the zones using filter
gcloud compute zones list \ --filter=region:us-central1
-
To get the IAM policy into an yaml file
gcloud projects get-iam-policy (project_id) > filename.yaml
-
To set the IAM policy using yaml file
gcloud projects set-iam-policy project_id filename.yaml
-
To bind an IAM policy to a specific user
gcloud projects add-iam-policy-binding project_id \ --member user:[email protected] \ --role roles/editor
-
To list billing accounts
gcloud beta billing
-
To link a billing account with a project
gcloud alpha billing projects link my-project \ --billing-account 0X0X0X-0X0X0X-0X0X0X
-
To create a disk
gcloud compute disks create
-
To resize the disks
gcloud compute disks resize
-
To list down the deprecated images
gcloud compute images list/describe/create/deprecate
-
To create a instance disabling auto termination of disk
gcloud compute instances create instance-1 \ --no-auto-delete \ --disk exampledisk
-
To create a network in custom mode
gcloud compute networks create ace-exam-vpc1 \ --subnet-mode=custom
-
To create a network and enabling flow-logs
gcloud beta compute networks subnets create cert-exam-vpc-subnet1 \ --network=cert-exam-vpc1 \ --region=us-west2 \ --range=10.10.0.0/16 \ --enable-private-ip-google-access \ --enable-flow-logs
-
Expanding the IP address range
gcloud compute networks subnets expand-ip-range cert-exam-subnet1 \ --prefix-length 16
-
listing down the clusters
gcloud container clusters list
-
Getting details of the cluster
gcloud container clusters describe \ --zone us-central1-a standard-cluster-1
-
Listing down Kubernetes nodes
kubectl get nodes
-
Listing down the Kubernetes pods
kubectl get pods
-
Describing the nodes
kubectl describe nodes
-
Describing the pods
kubectl describe pods
-
Creating a cluster
gcloud container clusters create example-cluster
-
Resizing the cluster
gcloud container clusters resize standard-cluster-1 \ --node-pool default-pool \ --size 5 \ --region=us-central1
-
Auto-scaling
gcloud container clusters update standard-cluster-1 \ --enable-autoscaling \ --min-nodes 1 \ --max-nodes 5 \ --zone us-central1-a \ --node-pool default-pool
-
listing down the deployments
kubectl get deployments
-
Scale the deployments
kubectl scale deployment nginx-1 \ --replicas 5
-
Auto scaling the deployments
kubectl autoscale deployment nginx-1 \ --max 10 \ --min 1 \ --cpu-percent 80
-
Deleting the deployments
kubectl delete deployment nginx-1
-
List down the services
kubectl get services
-
Running the deployment
kubectl run hello-server \ --image=gcr.io/google/samples/hello-app:1.0 \ --port 8080
-
Exposing the deployment
kubectl expose deployment hello-server \ --type=”LoadBalancer”
-
Deleting the service
kubectl delete service hello-server
-
Listing down the images
gcloud container images list
-
Describing the images properties
gcloud container images describe gcr.io/appengflex-project-1/nginx
-
Deploying the application on to app engine
gcloud app deploy app.yml
-
Stopping the versions of app-engine
gcloud app versions stop v1 v2
-
Splitting the traffic
gcloud app services set-traffic serv1 \ --splits v1=.4,v2=.6
-
To deploy a function with all the specifications
gcloud functions deploy cloud_storage_function_quant \ --runtime python37 \ --trigger-resource gcp-ace-quant-test-bucket \ --trigger-event google.storage.object.finalize
-
Deleting a cloud function
gcloud functions delete
-
List down the components
gcloud components list
-
Update the components
gcloud components update
-
Install the components
gcloud components install <component-name>
-
Create an SQL database
gcloud sql databases create
-
Connect to the sql
gcloud sql connect ace-exam-mysql –user=root
-
Create a backup
gcloud sql backups create \ --async \ --instance ace-exam-mysql
-
Export the data from cloudsql instance
gcloud sql instances export sql quantiphi-mysql1 gs://quantiphi-buckete1/quantiphi-mysqlexport.sql \ --database=mysql
-
Topic creation
gcloud pubsub topics create [TOPIC-NAME]
-
Subscribtion create
gcloud pubsub subscriptions create [SUBSCRIPTION-NAME] \ --topic [TOPIC-NAME]
-
Publish a message to specific topic
gcloud pubsub topics publish topic1 \ --message “Quantiphi-AI/ML”
-
Pull the messages
gcloud pubsub subscriptions pull \ --auto-ack sub1
-
Creating a cluster
gcloud dataproc clusters create cluster-bc3d \ --zone us-west2-a
-
Submitting the jobs
gcloud dataproc jobs submit spark \ --cluster cluster-bc3d \ --jar Quantiphi.jar
-
Listing down the jobs
bq ls -j -a project
-
Creating indexes in Datastore
gcloud datastore create-indexes
-
Export all kinds in the exampleNs namespace in the exampleProject project to the exampleBucket
gcloud datastore export gs://exampleBucket \ --namespaces=’exampleNs’ \ --project=’exampleProject’
-
Lists all your buckets
gsutil ls
-
Help on the topic
gsutil help <topic>
-
Bucket creation
gsutil mb gs://quanti-bucket
-
Deletes the bucket.
gsutil rm gs://<bucket_name>
-
Files - copies the local filename into the bucket
gsutil cp <filename> gs://<bucket_name>/
-
Copies the local filename into the directory
gsutil cp <filename> gs://<bucket_name>/directory/
-
Moves the local src_filename to the directory and renames it as quanti-fi1
gsutil mv <src_filename> gs://<bucket_name>/directory/quanti-fi1
-
Deletes the file_or_dir object.
gsutil rm gs://<bucket_name>/file_or_dir
-
Changing the storage class
gsutil rewrite -s [STORAGE_CLASS] gs://[PATH_TO_OBJECT]
-
Modifying the access control list
gsutil acl ch -u [SERVICE_ACCOUNT_ADDRESS]:W gs://[BUCKET_NAME]
-
Assigning roles
gsutil iam ch user : <user_email>:<role1,role2> gs://<BUCKET>
-
Getting Versioning status
gsutil versioning get gs://bucket
-
Enabling versioning
gsutil versioning set on gs://bucket
-
Life cycle status
gsutil lifecycle get gs://bucket > filename.json
-
Setting the life cycle version
gsutil lifecycle set filename.json gs://bucket