Google Compute Engine


What is Google Compute Engine


This is an IAAS(Infrastructure as a Service) component that allows us to spin up, manage, and customize the compute servers in the Google Cloud. The compute server is often called Virtual Machine or VM instance, as this would be the preferred term in the Cloud World. A VM can hold any customized versions of Linux / Windows images provided by GCP.  Even you can import a disk image from the on-premise environment to GCE directly. We will talk about the persistent disk and volatile disks in the later section. 

Machine Types


GCP allows the predefined machine types to satisfy the application needs. We can also define our own custom types as well. Predefined types are categorized into three classes. 
  1. Standard machine type
  2. High memory machine type
  3. High CPU machine type
  4. f1/g1 micro burst machine type

Standard types are more suitable for day-to-day apps/small capacity apps which are not really powered intensive. These types allocate 3.75Gig RAM per vCPU. (example: n1 series )

High Memory machine types allocate 6.50Gig per CPU. (example: n1-highmem series)

High CPU machine types allocate 0.9Gig RAM per vCPU. (example n1-highcpu-series)

F1-micro types are suitable for tasks that complete in a short period. Since this offers for temporary use cases, it can take advantage of the additional physical CPU if needed. 

For more details check out the machine types here. 

Images


GCE offers you to choose operating systems using public images or you can develop the custom images as per the business requirements. Public images are maintained by Google or third party vendors. Whereas custom images can be created in a particular project and only available to that project. On the other hand, you can also import the custom images from on-premise into GCP by paying only storage costs. 

For more details, check out the image lists here.

Ways to create a VM in GCE


There are four ways broadly used to create a Virtual Machine instance in GCE. 
  1. Web console
  2. Command-line tool gcloud/gshell
  3. API calls
  4. Deployment manager

Customize VM configurations


As you see the above methods for creating the VM instance, there are several components bound to customize as per the requirements like operating systems, compute zone, machine type, VPC, storage option, so on and so forth. Let us see the important customization parameters below,

Compute Zone


A location where the VM resides. A region has one or more zones geographically where the resources that live in. Some resources live in a zone, such as for instance disks, vpc subnet is referred to as zonal resources. Likewise some resources such as external IP are regional resources. If you want to have the maximum availability for your VM, then distribute the VM across multiple availability zones. 

Availability Policies 


This component majorly has three options,
  1. Preemptibility
  2. Automatic restart
  3. On host maintenance 

Preemptibility


Preemptible VM instances are available at a lower price than a regular instance, as these instances can terminate at any time if those resources are needed to be reclaimed for other tasks. Preemptible types also have a 24 hours time limit for special use-case after which it will be terminated. 

This type is recommended to use only for the applications which can accept the disruption and that are fault-tolerant. Unlike regular VMs, preemptible VMs are,

  • Cannot migrate to any other zone/region
  • Cannot work with software updates
  • Will be restarted forcibly during maintenance 
  • Suitable for short-lived jobs
  • Highly recommended to have shutdown scripts, which helps to clear the job termination

Auto-restart


It refers to the behavior that VM takes after a hardware failure or a system failure. If set to auto-restart, then the system will try creating a new VM. 

Keep in mind that auto-restart will not work for VM if that was terminated due to user actions.

On-host maintenance 


When any maintenance events occur at hardware/software updates require your VM to be moved to a different host. If this option is enabled, then the instance will perform the live migration which prevents the users from facing disruptions. 

Keep in mind that this live migration will not change the VM configurations, rather it moves to the other host without any interruptions.

Load Balancing


GCE offers the traffic distribution pattern with a load balancer for web applications and groups up the VM instances at the backend. The traffic distribution is based on user proximity or content-type. User proximity means redirecting the request comes from Asia to instances located in Asia for example. Content-type means redirecting the request based on the specific content requests to particular instances. 

Auto-Scaling


This option allows you to add/remove the VMs from the instance group based on certain criteria. 
This method makes the application to handle the traffic and resource management in an efficient and optimized way. 

Startup Scripts


This option is for setting up the bash/Powershell scripts to perform the initial actions when VM gets booted. This option is specified in the metadata server using the gcloud tool as well as the web console.

Use the metadata flag, when you create the new instance using gcloud.

Example
gcloud compute instances create example --metadata startup-script=’#! /bin/bash
sudo su -
apt-get update
apt-get install -y apache
service httpd start’

Use the add-metadata flag, when you want to assign the startup scripts for the existing instance. We can also keep the scripts in GCS and assign them to the metadata file parameter.  

gcloud compute instances add-metadata example --metadata-from-file startup-script=gs://bucketname/filename.sh\

Let us see how to handle these parameters when creating a new VM in GCE in the next tutorial


Recent Posts