Fundamentals of Google Compute Engine – Part 2

Reading Time: 4 minutes

This part of the series Fundamentals of Google Compute Engine will cover how to create and manage the lifecycle of virtual machine instances from the Google Cloud Console.

In case you haven’t been following the blog yet, here is the link to the first part.

Prerequisites

A Google account with billing enabled. (If it’s your first time you can set it up with any credit/debit card with international transaction enabled and you’ll receive free credits from Google.)

Ways to create a VM instance

There are three ways to create a virtual machine instance.

1.With the Google Cloud Console.

2.Via the gcloud command-line tool.

3.With the Compute Engine REST API.

Create a VM instance from Google Cloud Console

The goal of this blog is to create a virtual machine instance and run an HTTP server on it. Let’s begin.

Getting started is as easy as logging into your Google Cloud Console and creating a project with any name you like. Projects allow you to organize all your Google Cloud resources. Once you’ve created a project, you can see project details on your dashboard. The project information will consist of the project name so you can identify your project, the Project ID so Google Cloud Platform can identify your project, and a Project Number so the support team can assist you in case of any difficulties.

Steps to create a VM instance

Step 1 – On the top left of the screen, click the navigation menu icon. Next, select Compute Engine and VM instances.

Image 1.

Step 2 – On the next screen click on Create Instance.

Image 2.

Step 3 – Clicking on create instance will take you to this page.

Image 3.

The first thing you need to do is specify the name of the instance. Next, specify the region and zone where the instance will be created. Next, choose the machine type for your instance. From the wide variety of machines available, you can choose the one that suits your needs. The machine can even be customized to meet your specific requirements.

Step 4 – Furthermore, you can choose where the virtual machine will boot from based on the boot disk you choose. To do so, click on Change under Boot disk(Its a network storage device with durable storage that your instances can access like a physical disk on a desktop or a server).

Image 4.
Image 5.

The operating system and specific version can be selected here based on your requirements.

Step 5 – You can select the service account that will be used by this instance. Just think of the service account as a way for the Google Cloud Platform to identify and authorize your virtual machine if it needs to interact with other GCP services. Then, check the Allow HTTP traffic checkbox since we want to run an HTTP server on this instance.

Image 6.

Click on create to see the virtual machine instance in action.

Step 6 – The following screen shows that your instance is running.

Image 7.

Step 7 – Next, click SSH to connect with your instance remotely.

Image 8.

Step 8 –  On the next screen, click Connect.

Image 9.

Step 9 – Install apache2 webserver on your instance by executing the following commands from terminal.

 > sudo su

 > apt update

 > apt -y install apache2

 > service start apache2 start

 > echo “Hello World” > /var/www/html/index.html

Image 10.

Step 10 – Navigate to the console and then click on External IP.

Image 11.

Congrats on having your web server up and running.

Image 12.

Step 11 – In order to stop, reset, delete your instance and perform other operations, click on the more action icon.

Image 13.

Warning

Always terminate your virtual machines instances to avoid being charged while it is unused.

References

To know more about Compute Engine, you can visit this link.

To read more tech blogs, feel free to visit Knoldus Blogs.

Written by 

Akshat Mathur is a Software Consultant at Knoldus Inc. He has worked on Java, Angular 11, and Spring Boot for more than three years. Learning is his passion and solving problems is his forte.

1 thought on “Fundamentals of Google Compute Engine – Part 26 min read

Comments are closed.