Category Archives: Cloud

Gcloud Command Reference

Gcloud Command Reference

Some trick configuration

To set the project property in the core section, run:

$ gcloud config set project myProject

To set the zone property in the compute section, run:

$ gcloud config set compute/zone us-central1-a

To disable prompting for scripting, run:

$ gcloud config set disable_prompts true

To set a proxy with the appropriate type, and specify the address and port on which to reach it, run:

$ gcloud config set proxy/type http
$ gcloud config set proxy/address
$ gcloud config set proxy/port 8080

Show your running instances

$ gcloud compute instances list
test3-jump-001 us-central1-a f1-micro RUNNING
test3-node-001 us-central1-a n1-standard-1 RUNNING
test3-node-002 us-central1-a n1-standard-1 RUNNING
test3-node-003 us-central1-a n1-standard-1 RUNNING
test3-node-004 us-central1-a n1-standard-1 RUNNING
test3-node-005 us-central1-a n1-standard-1 RUNNING

Working with Buckets

To set create a new bucket, run:

$ gsutil mb gs://mySuperNewBucket

To enable versioning on it, run:

$ gsutil versioning set on gs://mySuperNewBucket

To remove all files on the bucket

$ gsutil rm -r gs://mySuperNewBucket

To remove the bucket (needs to be empty)

$ gsutil rb gs://mySuperNewBucket

Listing zones 

To show all available zones for your account, run:

$ gcloud compute zones list
us-east1-b us-east1 UP
us-east1-c us-east1 UP
us-east1-d us-east1 UP
us-east4-c us-east4 UP
us-east4-b us-east4 UP
us-east4-a us-east4 UP
us-central1-c us-central1 UP
us-central1-a us-central1 UP

Listing machine-types and show CPU memory sizes

You could filter per region including a filter on it, example:

$ gcloud compute machine-types list --filter="zone ~ ^us-central1-a"
f1-micro us-central1-a 1 0.60
g1-small us-central1-a 1 1.70
n1-highcpu-16 us-central1-a 16 14.40
n1-highcpu-2 us-central1-a 2 1.80
n1-highcpu-32 us-central1-a 32 28.80
n1-highcpu-4 us-central1-a 4 3.60
n1-highcpu-64 us-central1-a 64 57.60
n1-highcpu-8 us-central1-a 8 7.20
n1-highcpu-96 us-central1-a 96 86.40
n1-highmem-16 us-central1-a 16 104.00
n1-highmem-2 us-central1-a 2 13.00
n1-highmem-32 us-central1-a 32 208.00
n1-highmem-4 us-central1-a 4 26.00
n1-highmem-64 us-central1-a 64 416.00
n1-highmem-8 us-central1-a 8 52.00
n1-highmem-96 us-central1-a 96 624.00
n1-standard-1 us-central1-a 1 3.75
n1-standard-16 us-central1-a 16 60.00
n1-standard-2 us-central1-a 2 7.50
n1-standard-32 us-central1-a 32 120.00
n1-standard-4 us-central1-a 4 15.00
n1-standard-64 us-central1-a 64 240.00
n1-standard-8 us-central1-a 8 30.00
n1-standard-96 us-central1-a 96 360.00

Connect to a compute instance using the gcloud credentials

To access one instance through your gcloud credentials, run:

$ gcloud compute --project "myCoolProjectName" ssh --zone "us-east1-b" "myCoolInstanceName"

Google Cloud gcloud multiple accounts and basic usage

Google Cloud gcloud tool Basics and Multiple Accounts

For use gcloud tool follow this simple steps:

Install the gcloud tool

Visit this page:

Download the archive file for your system, uncompress it and run:


And follow the script next steps.

Initial config

gcloud init

And follow the script next steps.

List your instances

With this command you will check if the configuration is working and list your instances.

gcloud compute instances list

Multiple Accounts

You can use multiple accounts running the gcloud init command OR using the command gcloud config set account
Using the set account, use the gcloud compute instances list to auth your new account and configure your project.

Useful commands

To update all installed components to the latest version:

gcloud components update

Displays all Google Compute Engine images in a project:

gcloud compute images list

To list Google Compute Engine machine types:

gcloud compute machine-types list

To list all addresses in a project in table form, run:

gcloud compute addresses list

It’s a very easy tool 🙂

More info:

Ansible and Google Compute Engine

Install dependencies

pip install apache-libcloud

Then install the gcloud. Visit:

Create and Download your service account p12

Convert the p12 format to pem

openssl pkcs12 -in ~/.ssh/foo.p12 -passin pass:notasecret -nodes -nocerts | openssl rsa -out ~/.ssh/foo.pem

To list google images

gcloud compute images list

To list google machine-type

gcloud compute machine-types list

To check your service account mail

Create a playbook

cat > gce_def.yml
- name: Compute Engine demo
  hosts: localhost
  gather_facts: False
    pid: my-first111134
    pem: /etc/ansible/pkey.pem
    - name: Create instance
        instance_names: demo1,demo2
        zone: us-central1-b
        machine_type: n1-standard-1
        image: debian-7-wheezy
        project_id: "{{ pid }}"
        pem_file: "{{ pem }}"
        service_account_email: "{{ email }}"

List running instances

gcloud compute instances list