Azure vs GCP part 12: Virtual Machine - Scaling (GCP)
Tags: azure, gcp, cloud
Published: 2018-03-16 14:17:53

---
title: "Azure vs GCP part 12: Virtual Machine - Scaling (GCP)"
published: true
description: In this series, I compare Azure and GCP as C# developer
tags: azure,gcp,cloud
cover_image: https://thepracticaldev.s3.amazonaws.com/i/m57mmv4hgz9xrskaital.PNG
---

In [previous article](https://dev.to/kenakamu/azure-vs-gcp-part-11-virtual-machine-gcp--5657), I use GCP VM (GCE) to host my application, as single instance.

I look into scaling options [like I did for Azure](https://dev.to/kenakamu/azure-vs-gcp-part-10-virtual-machine---scaling-azure--4ci0) for GCP.

# Availability

Repeat from Azure post, but one of the reasons why I recommend multi-instance is availability. There are two types of concerns.

- Hardware failure
- Software update

# Managed Instance Groups

A group contains identical VMs and offer auto-scale. It uses **instance template** as seed image to add additional VM when load exceeds threshold. There are two types of managed instance groups.

### Zonal managed instance group
All VMs runs in same group. [This article](https://cloud.google.com/compute/docs/regions-zones/#choosing_a_region_and_zone) 
says "single failure events will affect only a single zone". Thus I assume it may cover software update, but I still have issue with hardware failure. 

### Regional managed instance group
VMs run in multiple zones in a region. This should cover hardware failure too, unless entire region goes down.

# Load balancer
GCP also offers load balancer but it gives more option than Azure. 

### Global external load balancing

- HTTP(S) load balancing: Distributes HTTP(S) traffic among groups of instances based on proximity to the user, the requested URL, or both.
- SSL Proxy load balancing: Distributes SSL traffic among groups of instances based on proximity to the user.
- TCP Proxy load balancing: Distributes TCP traffic among groups of instances based on proximity to the user.

### Regional external/internal load balancing
Distribute network traffic in one region
- Network load balancing: Distributes traffic among a pool of instances within a region. Network load balancing can balance any kind of TCP/UDP traffic.
- Internal load balancing: Distributes traffic from Google Cloud Platform virtual machine instances to a group of instances in the same region.

# Let's try!

Enough talk, now let me try.

### Create Custom Image
To start off, I need to create windows image which contains application.

1\. Login to VM which contains the application via RDP.
![image](https://thepracticaldev.s3.amazonaws.com/i/labgi3ow464gzqn7nrhb.PNG)

2\. Open PowerShell as administrator and run following command.

```powershell
GCESysprep
``` 
3\. Go to "Images" and click "CREATE IMAGE".

4\. Specify necessary parameters. Set source as Disk and source disk which you just generalized. Click "Create".

![image](https://thepracticaldev.s3.amazonaws.com/i/5pqdwakry5xq4p389yv6.PNG)

### Create Instance Template
Next, create instance template from the custom image.

1\. Go to "Instance templates" and click "Create instance template".
![template](https://thepracticaldev.s3.amazonaws.com/i/761lufm9g4kly1msyvtw.PNG)

2\. Enter name and select machine type. Click "Change" for boot disk.
![template](https://thepracticaldev.s3.amazonaws.com/i/zbqaot79dqe399o1yba7.PNG)

3\. Click "Custom images" and select the created image.
![template](https://thepracticaldev.s3.amazonaws.com/i/o8k40uwc8dw5f06f0ddg.PNG)

4\. If the application requires access to any resources in GCP, set "Identity and API access". In this case I don't need any. Enable "Allow HTTP traffic". Click Create.
![template](https://thepracticaldev.s3.amazonaws.com/i/ohpvfx7jatiwgx1c5hej.PNG)

### Create Instance Groups
Now, as I have template image, I go ahead to create instance group.

1\. Go to "Insatnce groups" and click "Create Instance Group".
![group](https://thepracticaldev.s3.amazonaws.com/i/8uy152jm9ofe5arfgwwp.PNG)

2\. Enter name, and specify "Location". I select "Multi-zone" here.
![group](https://thepracticaldev.s3.amazonaws.com/i/h6pr88lmzsbvchqpjrzt.PNG)

3\. Specify "Instance template" as created template, and set "Autoscaling" to "On". I use default values but you can tweak it.
![group](https://thepracticaldev.s3.amazonaws.com/i/z2b4efdoslb4sncvnei7.PNG)

4\. In addition to autoscaling, I can set Autohealing. 
![group](https://thepracticaldev.s3.amazonaws.com/i/akbwb93kdwjd8joleeo7.PNG)

5\. Wait until creation completes. Then select the created instance group. There are running instances showing with public IP.
![group](https://thepracticaldev.s3.amazonaws.com/i/adcpe6krp2ud00buifew.PNG)

6\. Access to the public IP to check the application.
![group](https://thepracticaldev.s3.amazonaws.com/i/whjbqk0nvsmptb10ll79.PNG)

### Create Load Balancer
When autoscaling kicked in, there are multiple instances. To give users single access point, add load balancer.

1\. Go to "Network services" | "Load balancing", then click "Create load balancer".
![lb](https://thepracticaldev.s3.amazonaws.com/i/1qc9ti7pk7h61uop8243.PNG)

2\. As I need to load balance HTTP, select "HTTP(S) Load Balancing".
![lb](https://thepracticaldev.s3.amazonaws.com/i/dda8z149ekuxikf9uzjk.PNG)

3\. Enter name nad click Create. Select "Backend configuration" and create new background service.
![lb](https://thepracticaldev.s3.amazonaws.com/i/0dwhc758wetqglopb1ow.PNG)

4\. Select created instance group, and select balancing rule. I use default rule here. Click "Done".
![lb](https://thepracticaldev.s3.amazonaws.com/i/ztc3wd1vgokcov2qm2uk.PNG)

5\. Click "Health Check" and create new one.
![lb](https://thepracticaldev.s3.amazonaws.com/i/swqbw66ldo5lelwnw79q.PNG)

6\. Now I can click "Create" button.

7\. I use default rules and configuration for the rest. Click "Create" to create the load balancer. Wait until creation completes.

8\. Once load balancer created, select it. Check the global IP.
![lb](https://thepracticaldev.s3.amazonaws.com/i/cy2lt018roq2h29fuhv4.PNG)

9\. Access to the IP to confirm the page is loaded.
![lb](https://thepracticaldev.s3.amazonaws.com/i/v0t67q6f3lpzved6lvtn.PNG)

### Quote
As I am using Free trial account, there are certain quota that I cannot exceed. If I keep accessing the endpoint and let keep auto scale happen, then I exceed my limitation.

1\. Go to "Instance Groups" and open the one I created. There is a VM with warning. It says I exceeds quota.
![quota](https://thepracticaldev.s3.amazonaws.com/i/zl88fokhk3dr47lode49.PNG)

2\. Go to "IAM & admin" | "Quotas". You see have 8 CPU limitation for the location.
![quota](https://thepracticaldev.s3.amazonaws.com/i/y6uu0o2g4a2nlflpidst.PNG)

# Summary
The way it auto scale is similar to Azure, such as creating seed image and set auto scale, with load balancer in front. However there are several differences how each cloud platform treats VMs. 

As a developer, I feel Azure gives me better documentation, but GCP gives me better experience to configure scaling environment especially when using custom image.

There are tons of other features I may need to look at, but I move on to different technology from next article. Either function or container.

# Reference
[Creating a Windows Image](https://cloud.google.com/compute/docs/instances/windows/creating-windows-os-image)
[Autoscaling Groups of Instances](https://cloud.google.com/compute/docs/autoscaler/)