Skip to content

Instantly share code, notes, and snippets.

@mwhittaker
Last active March 14, 2020 18:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mwhittaker/8a0d2481cabc7f59dbf9 to your computer and use it in GitHub Desktop.
Save mwhittaker/8a0d2481cabc7f59dbf9 to your computer and use it in GitHub Desktop.
Google Cloud Platform

Google Cloud Platform

Table of Contents

Common Commands

  • Create an instance named instance-1 in the us-central1-a zone

      gcloud compute instances create instance-1 --zone us-central1-a
    
  • Create an f1-micro instance named instance-1 in the us-central1-a zone

      gcloud compute instances create instance-1 --zone us-central1-a --machine-type f1-micro
    
  • Create an instance named instance-1 in the us-central1-a zone running Ubuntu 14.04

      gcloud compute instances create instance-1 --zone us-central1-a --image ubuntu-14-04
    
  • Create an instance named instance-1 in the us-central1-a zone in the network default

      gcloud compute instances create instance-1 --zone us-central1-a --network default
    
  • Create an instance named instance-1 in the us-central1-a zone in the project project

      gcloud compute instances create instance-1 --zone us-central1-a --project project
    
  • Create an instance named instance-1 with all the fix-ins.

      gcloud compute instances create instance-1
          --zone us-central1-a
          --machine-type f1-micro
          --image ubuntu-14-04
          --network default
          --project project
    
  • Create an instance with startup script startup.sh.

      gcloud compute instances create instance-1
          --zone us-central-1a
          --metadata-from-file startup-script=startup.sh
    
  • Create a new firewall rule allowing inbound tcp traffic on all ports in the default network for machines tagged with tag ``alibaba`

      gcloud compute firewall-rules create default-allow-all
          --allow tcp:1-65535
          --network default
          --target-tags alibaba
    
  • Tag instance-1 with tag alibaba

      gcloud compute instances add-tags instance-1
          --zone us-central1-a
          --tags alibaba
    
  • Untag 'instance-1' with tag 'alibaba'

      gcloud compute instances remove-tags instance-1
          --zone us-central1-a
          --tags alibaba
    
  • List instances

      gcloud compute instances list
    
  • List external ip address of instance-1

      gcloud compute instances list instance-1 --format yaml | grep natIP | awk '{print $2}'
    
  • List current project

      gcloud config list
    
  • Set current project to example

      gcloud config set project example
    
  • Make gs://dir/file publicly readable.

      gsutil acl set public-read gs://dir/file
    

Resources

Google Cloud Platform

Google Compute Engine

Google Cloud Storage

Google Cloud Dataflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment