Rinu Goldgin Dhanaraj

Software Consultant

Google Cloud – Virtual Machines

A high level overview of various compute and processing options offered in GCP 

  1. Compute Engine
  2. Kubernetes Engine
  3. App Standard Engine
  4. App Flexible Engine
  5. Cloud Functions

So what is Compute Engine?

Its nothing but a bare metal VM a.k.a IaaS – Infrastructure as a Service. It allows us to choose the CPU, Memory, Storage, Networking and Operating Systems.

Compute Options

  • N/W  throughput scales 2 Gbps per vCPU
  • Max of 32 Gbps with 16 vCPU
    • or 100 Gbps with T4
    • or V100 GPUs

Note: A vCPU is equal to 1 h/w hyper thread.

Storage

  • SSD
    • Higher iops
    • High capacity
  • Local SSD
    • lower latency
    • data is lost when instance is stopped
    • ideal for swap disk
    • upto 3TB for each instance
  • Standard HDD

Networking

GCP offers various networking features

  • Default Network
  • Custom Network
  • Firewall Rules
    • IP based
    • Instance/group tags
  • Regional HTTPs load balancing
  • Network load balancing
  • Global & Multi regional subnetworks
Creating a VM
  • GUI Interface
    • Navigate to VM Instances–>Create Instance
  • cloud shell command line
    • gcloud compute instances create INSTANCE_NAME
  • REST API

Machine Types

  • Standard
    • 1vCPU upto 96vCPUs
    • 3.75GB upto 360GB
    • Max 128 PD (persistent disk)
    • PD  Size – 64 TB
  • High-memory
    • 2 vCPUs upto 96vCPUs
    • 13 GB upto 624GB
    • Max 128 PD (persistent disk)
    • PD  Size – 64 TB
  • High-CPU
    • 2 vCPU upto 96vCPUs
    • 1.8 GB upto 86.4 GB
    • Max 128 PD (persistent disk)
    • PD  Size – 64 TB
  • Memory-optimized
    • 40 vCPUs upto 961 vCPUs
    • 961 GB upto 3844 GB
    • Max 128 PD (persistent disk)
    • PD  Size – 64 TB
  • Compute-optimized
    • 4 vCPU upto 60 vCPUs
    • 16 GB upto 240GB
    • Max 128 PD (persistent disk)
    • PD  Size – 64 TB
  • Shared-co re
    • micro/small
      • 0.2 / 0.5 vCPU
      • .6 GB
      • 16 PD
      • 3TB
  • Custom
    • memory & vCPUs are defined as custom
    • either 1 vCPU or even no.of vCPU
    • .9 GB upto 6.5 GB memory
    • Memory to be ini multiplies of 256 MB

Note: Pre-defined machine types has pre-determined mem & cpu ration.

Images

  • Public base images
    • Linux
    • Windows
  • Custom images
    • import from your local / custom location

Boot Disk

  • VM comes with a single root persistent disk
  • Image loaded on to root disk during first boot
    • Bootable
    • Durable – can survive vm termination
  • Persistent Disks
    • HDD or SSD 
    • Attached to VM using n/w interface
    • Bootable / Durable
    • Snapshopts
    • Performance
    • Disk resizing
      • can grow but not shrink
    • Encryption Keys
      • Google Managed
      • Customer Managed
      • Customer supplied
  • Local SSD
    • Ephemeral 
    • high iops
    • Data survive on reset
    • Data loss on VM stop / terminate
    • VM specific
    • Snapshot not available
  • RAM Disk / tmpfs
    • faster than local disk
    • slower than memory
VM Access & Lifecycle
  • Linux VMs
    • SSH from GCP console
    • CloudShell via Cloud SDK
    • SSH from computer
      • use a “key pair”
      • ensure firewall rule to allow tcp:22
  • Windows VMs
    • RDP clients
    • Powershell terminal
    • Ensure to set windows password
    • Firewall rule to allow
      • tcp:3389

VM Life Cycle

The following are the different status which covers the life cycle of a vm, when we use the “create” option it enters the first stage called the provisioning where resources are allocated. In the next stage it enters the staging where the instances is prepared for launch. At the instance running state, app scripts can be executed.

  • Provisioning
    • Virtual CPUs
    • Memory
    • Root disk
    • Persistent disk
  • Staging
    • IP address
      • Internal
      • External
    • System Image
    • Boot
  • Running
    • Start-up script
    • Access
      • SSH/RDP
    • Modify use
      • Export system image
      • Snapshot persistent disk
      • Move VM to different zone
      • read/update metadata
    • Reset
      • resets the vm to initial state
  • Stopping
    • Shutdown script
    • Delete
    • Availability Policy
Different operations impact on the VM state from running
 
  • reset
    • Methods
      • console, gcloud, API, OS
    • Scripts
      • Shutdown – N/A
    • State
      • remains running
  • restart
    • Methods
      • console, gcloud, API, OS
    • Scripts
      • Shutdown – N/A
    • State
      • terminated to running
  • reboot
    • Methods
      • OS: sudo reboot
    • ~90s for shutdown
    • State
      • running->running
  • stop
    • Methods
      • console, gcloud, API
    • ~90s for shutdown
    • State
      • running->terminated
  • shutdown
    • Methods
      • OS: sudo shutdown
    • ~90s for shutdown
    • State
      • running->terminated
  • delete
    • Methods
      • console, gcloud, API
    • ~90s for shutdown
    • State
      • running->N/A
  • preemption
    • automatic
    • ~30s
    • State – n/a

Availability policy

  • Auto restart
    • restart due to vm crash
  • on-host maintenance
  • Live migration
    • During host maintenance, the VM is set for live migration. However, you can have the VM terminated instead of migrated.

Notes:

  1. No Charge for stopped VM
  2. Change machine type
  3. tags
  4. modify custom vm or metadata
  5. once stopped cant change the vm image.
  6. You can’t convert a non-preemptible instance into a preemptible one. This choice must be made at VM creation. A preemptible instance can be interrupted at any time and is available at a lower cost.

Commands

Check RAM installed sudo dmidecode -t 17
Check no.processors - nproc
Check no.of CPUs - lscpu
Check Memory - free

Billing

  • Per-sec billling
  • Resource based billing
  • Discounts
    • sustained use
    • committed use
    • Preemptible VM instances
      • 24 hr max
      • 30s prior notification before termination
      • no auto restart 
      • no live migrate
      • low price
  • Free usage limits
Previous Article