Google Cloud Quick Reference
  • Quick Reference for GCP Cloud Shell
  • Running Docker on Ubuntu 16.4
  • Google Kubernetes Engine - Quick Reference
Powered by GitBook
On this page

Quick Reference for GCP Cloud Shell

Cloud Shell Quick Start - Google Cloud Platform

Set the default Project

$ gcloud compute set project <PROJECT ID>

set project will use the selected project as the default project while working in the cloud shell.

you can use compute/region and compute/zone to specify the zone or region

gcloud config set compute/region REGION 
gcloud compute project-info describe --project PROJECT_ID

create an image with a start up script for Apache.

gcloud compute instances create web-server \
--image-family debian-9 \
--image-project debian-cloud \
--zone us-central1-b \
--tags http-server \
--metadata startup-script="#! /bin/bash
  sudo apt-get update
  sudo apt-get install apache2 -y
  sudo service apache2 restart
  echo '<!doctype html><html><body><h1>Web Server</h1></body>
  </html>' | sudo tee /var/www/html/index.html
  EOF"

Create an Unmanaged instance group

note: un-managed instance groups do not offer auto scaling. typical use case can be for applying load balancing for existing configurations or groups of non identical instances meaning virtual machines.

gcloud compute instance-groups unmanaged create web-group \
--zone us-central1-b

gcloud compute instance-groups unmanaged add-instances web-group
--instances web-server \
--zone us-central1-b

Create an HTTP health check

gcloud compute health-checks create http http-health-check

Create a managed instance group

When creating managed instance groups we are utilizing the the image template created for the managed instance group. you can create an image template before creating an managed instance group or while created the managed instance group.

Managed instance groups gives us with the ability to scale out our resources automatically in the event of heavy traffic. when using load balancing configurations on the google cloud platform target pools or managed instance groups are required when using the auto scale features.

gcloud compute --project "your project name here" instance-groups managed create "instance-group-autoscale" --region "us-east1" --base-instance-name "instance-group-autoscale" --template "instance-template-1" --size "1"

gcloud compute --project "your project name here" instance-groups managed set-autoscaling "instance-group-autoscale" --region "us-east1" --cool-down-period "60" --max-num-replicas "10" --min-num-replicas "1" --target-cpu-utilization "0.8"
   

Regional groups are recommended over zonal groups

With regional groups your workloads are spread across multiple zones from the same region. Static external IP addresses are considered regional resources while persistent disk and instances are considered zonal.

Zonal groups - Spans instances across the same zone. zonal resources can only be used by other resources in the same zone.

Working with machine types

When using cloud shell we can see the available machine types using this command.when using this command all available machine types will be listed, bur what if we wanted to see only the first 5?

gcloud compute machine-types list #gives a list of all available machine types 

let’s get only the first 5 machine types from that list

gcloud compute machine-types list --limit 5 

custom machine types When creating a custom machine type memory must be in increments of 256 MB 1vCPU would need at least 1GB of memory, if your using a shared 1vCPU then the 0.6 GB would work but only under that configuration.

you can add extended memory to custom machine types. Predefined machine types are not supported, an instance can have up to 6.5 GB memory per 1vCPU.

gcloud compute instances create example-instance --custom-cpu 4 --custom-memory 5 #creates an instance with 4 vCPU and 5 GB memory 

NextRunning Docker on Ubuntu 16.4

Last updated 6 years ago