This lab is part of the foundations training at OCTO Technology Australia.
In this quick lab, we will play with the Google Cloud Compute Engine.
At the end of the lab you will be able to:
- create buckets and files on Google Cloud Storage, and make some files public
- create a compute engine instance on Google Compute Engine
- create instance templates and instance groups and play with auto scaling
- configure and use a multi-regions load balancer
This lab should take approximately 60 minutes. You will need to use your own google cloud account.
Google Compute Engine (GCE) is the Infrastructure as a Service (IaaS) component of Google Cloud Platform. Google Compute Engine enables users to launch virtual machines (VMs) on demand. VMs can be launched from the standard images provided or by using custom images created by users.
Let's start with a bit of terminology, your applications will use:
- vm, a virtual machine
- instance templates, convenient way to save a VM instance's configuration so you can use it later to create new VM instances or groups of VM instances
- managed instance groups, which uses an instance template to create a group of identical instances. Compute Engine offers two different types of instance groups: managed and unmanaged instance groups, we will focus on managed instances group here.
- Google to the Google Cloud console
- Click on Project List (in the header next to the Google Cloud Platform Logo), the "Create Project"
- Give it a "Name", select a billing account, then use the "Create" button
For more information about this prerequisite step please refer to the official documentation.
-
Create a bucket (Gcp menu > Storage > Storage)
-
Upload the following 2 files which you can find in the labs-files directory:
- Belgium configuration: frontend-belgium.py
- Sydney configuration: frontend-sydney.py
We could use exactly the same file in different region, the only reason we are 2 of those it to be able to customize the messages served by the python endpoints.
-
Make objects public using the cloud shell. To do this click the 'activate cloud shell' terminal in the toolbar and run the following commands:
gsutil acl ch -u AllUsers:R gs://era-boot/frontend-belgium.py
gsutil acl ch -u AllUsers:R gs://era-boot/frontend-sydney.py
The syntax for accessing resources is:
gs://[BUCKET_NAME]/[OBJECT_NAME]
. For more information on the cloud shell and gsutil see : https://cloud.google.com/storage/docs/gsutil
Instance templates (Compute engine > Instance Templates):
We will launch our instance from an Instance Template, we will need two of these because there are two bootstrap actions (one to set up the sydney instance, and one for belgium)
- 1 CPU (default)
- Debian (default)
- Firewall > Allow HTTP Traffic
- Startup script (Automation > Startup script):
wget https://storage.googleapis.com/era-boot/frontend-sydney.py sudo python frontend-sydney.py &
- Leave all other options as default
Click on the template and then use the 'copy' option from the toolbar, this will load the previous selections. Then just change the startup script as below.
wget https://storage.googleapis.com/era-boot/frontend-belgium.py sudo python frontend-belgium.py &
Instance Groups (Compute Engine > Instance Groups)
Create an instance group with the following settings (leave as default those not mentioned)
- Single Zone
- Region: Sydney
- Select the correct instance template
- Autoscaling: ON
- Autoscaling: CPU usage!
- Healthchecks: create a new healthcheck, Protocol: HTTP 80, Health critieria: 5 5 2 2
- Initial Delay: 120s
Click on instance template > create VM to create a new VM from the template The point of creating client instances is to be able to ssh in to these clients and call the backend service from each of these two regions.
- Name: era-client-syd
- Machine type: Micro
- Region: Sydney
- Allow HTTP traffic
- Name: era-client-bel
- Machine type: Micro
- Region: Belgium
- Allow HTTP traffic
(VM Instances > Connect > SSH)
- Curl internal IP of instance group
- curl http://10.152.0.2/
You should see 'Hello from Sydney' and 'Bonjour from Europe' from the different instances
(Network services > Load Balancer)
-
Create a http load balancer and assign a name.
-
Create a backend service and assign the details of your instance group.
- Add healthcheck group
- Add instance group
- Set CPU utilisation to 60%
-
Don't add anything for Host and Path Rules
-
Create Frontend configuration
- Era-front-1
- Http
- Ip v4
Review, finalise and create. This will take about 5 minutes!
Check the load balancer has been created (swap with your IP):
curl http://35.241.43.206/
Do this with the following command (change IP address):
- Then raise the CPU from local shell
while true; do curl http://35.241.43.206/service ; done
- Check monitoring => menu instances
- Then kill bash loop
- Wait for the cluster to calm down
- Simple Zone
- Region: Belgium
- Select good instance template
- Autoscaling: ON
- Autoscaling: CPU usage!
- Healthchecks: era-hc HTTP 80 / 5 5 2 2
- Initial Delay: 120s
gcloud compute backend-services add-backend era-backend-bel-42 --instance-group=era-ig-bel --region=europe-west1
- You now have 1 Load balancer service with 2 backends!
Be sure to delete all resources used!