GCP gcloud commands
[basic syntax]
gcloud <global flags> <service/product> <group/area> <command> <flags> <parameters>
example:
gcloud — project=medium-blog-demo compute instances list
— project → this is <global flags>. You can use either “=” or space to provide value of this flag
compute → this is <service/product>
instances → this is <group/area> of this service/product
list → this is <command>
[general ]
- gcloud topic filters — it is a helper man page to know about how to use filters
- gcloud services list — available
[Projects related]
- gcloud projects list → list all the project you have including project_Id, Name, project_number
- gcloud config list → list your configuration
- gcloud config set project medium-blog-demo → set the project to medium-blog-demo
- gcloud config get-value project → to get the project value from your configuaration
[ configuration]
- gcloud init — interactive workflow to set common properties in a config
- gcloud config configurations list — list all configurations
- gcloud config configurations create newconfig → this is very similar to mkdir newdconfig command to create a container for new configurations.
- gcloud config configurations activate newconfig → this is very similar to cd newconfig to enter into/switch to the newconfig
- gcloud config list -> similar to ls to list all properties in a configuration
- gcloud — configuration=newconfig config list → to ls ~/newconfig
- gcloud config configurations describe newconfig → similar to ls ~/newconfig
- gcloud config set [account/project/region/zone] [webber-demo/webber-proj-demo, asiaeast-1, xx]
[cloud storage]
For storage, you will use gstutil instead. link is here
[cloud compute engine]
- gcloud compute instances list
- gcloud — project medium-blog-demo compute list
- gcloud compute instances create medium-demo-vm
- gcloud compute machine-types list → the output is quite long! You can find instance type information including NAME, ZONE, CPUS, MEMORY_GB, DEPRECATED
- gcloud compute instances create — machine-type=f1-micro medium-blog-demo-vm → create a vm with specified machine type f1-micro.
- gcloud compute ssh medium-blog-demo → this command will also execute ssh keygen to generate a key shown in below figure

7. check out metadata by visiting metadata.google.internal
# Check out the metadata
curl metadata.google.internal/computeMetadata/v1/
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/project/
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/project/project-id
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/project/attributes/
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/project/attributes/ssh-keys
# Look at some instance metadata
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/instance/
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/instance/name
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/
curl -H "Metadata-Flavor: Google" metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/email
8. gcloud compute instances delete medium-blog-demo-vm → delete a vm