Gcloud Cookbook

By   10-05-2017 · 2 minute read · 306 words


Dump current configuration

gcloud config list

List projects

gcloud projects list

Switch projects

gcloud config set project project-name

List compute instance sizes

gcloud compute machine-types list

Describe compute instance

gcloud compute describe instances <instance name>

List Regions

gcloud compute regions list

List zones

gcloud compute zones list

List firewall rules

gcloud compute firewall-rules list

List routes

gcloud compute routes list

Create custom network

gcloud compute networks create <network-name> --mode custom

Describe network

gcloud compute networks describe <network-name>

Create subnet

gcloud compute networks subnets create <subnet-name> --network <network-name> --region us-east1 --range 192.168.5.0/24

Create firewall rule

gcloud compute firewall-rules create jenkins-net-allow-ssh --allow tcp:22 --network jenkins-net --source-ranges 0.0.0.0/0 --target-tags ssh
gcloud compute firewall-rules create jenkins-net-allow-internal --allow tcp:1-65535,udp:1-65535,icmp --network jenkins-net --source-ranges 192.168.5.0/24
gcloud compute firewall-rules create jenkins-net-allow-http --allow tcp:80 --network jenkins-net --source-ranges 0.0.0.0/0 --target-tags http

Create vm instance

gcloud compute instances create <instance-name> --subnet build-subnet --zone us-east1-b --tags ssh,http

List images based on regex

gcloud compute images list --regexp .*debian.*

List images but exclude all standard images provided by Google.

gcloud compute images list --no-standard-images

Create vm instance based off image

gcloud compute instances create java-foundation --subnet build-subnet --zone us-east1-b --tags ssh --image debian-8-jessie-v20170717 --image-project debian-cloud --machine-type g1-small

Stop vm instance

gcloud compute instances stop java-foundation --zone us-east1-b

Describe compute instance

gcloud compute instances describe java-foundation --zone us-east1-b --format yaml

Delete compute instance.

gcloud compute instances delete <instance-name> --zone us-east1-b

Delete compute instance but keep disks

gcloud compute instances delete <instance-name> --keep-disks boot --zone us-east1-b

Delete multiple vm instances

gcloud compute instances delete test-01 test-02 --zone us-east1-a

Create image based on existing disk

gcloud compute images create debian-openjdk-java-7-jre --source-disk java-foundation --source-disk-zone us-east1-b

Describe image

 gcloud compute images describe <image-name> --format yaml

Create instance based off image

gcloud compute instances create <instance-name> --subnet <subnet-name> --zone us-east1-b --tags ssh --image <image-name>

List disks in each zone

gcloud compute disks list --zones us-east1-b

gcp, cheetsheet  

comments powered by Disqus