Create Virtual Machine Instance In Compute Engine In The Google Cloud Platform

Introduction 

 
In this article, we will learn How to create VM Instances with Google Cloud Platform’s Compute Engine. We will start with creating VM Instance with GCP Console and then achieve the same thing with the GCP Command Line utility i.e. GCloud. Then we will install the NGINX web server and host the web page and access it on another VM machine and through the internet.
 
Let’s begin.
 

Creating a Virtual Machine Instance with Google Cloud Platform Console

 
Step 1
 
Login with Google Cloud Platform by visiting here (Google provides $300 as a free trial, but for that, you need to link your credit card).
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 2
 
Once logged in to google cloud platform, you will see the dashboard as shown below.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 3
 
Click on Computer Engine -> Then click on VM Instances.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 4
 
In the next screen, i.e. VM Instances page, you will see a create a VM instance button as shown below. (In case if any VM already, then the user will see the VM Instance detail in the grid).
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 5
 
Click on New VM Instance in order to create a new VM from scratch. Provide the VM Instance a valid Name (as in the example, I have given name as my-vm-1). Select Region, Zone, and machine configuration as per your need. 
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 6
 
Select Boot Disk. As in the example, I am using a Debian operating system which is basically a Linux based OS.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 7
 
As I am planning to host a web page so I am allowing HTTP traffic in Firewall. Click on the create button in order to create the VM.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 8
 
On clicking on the Create button, it will take less than a minute in order to create the selected VM Instance.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 9
 
Once the VM instance is ready, you will see a green tick symbol in front of your VM name. External and Internal I.P. is visible once the VM instance is ready.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 

Create VM instance with GCloud command-line utility of Google Cloud Platform

 
Step 1
 
Click on the top Cloud Shell button in order to use command-line access to create the VM Instance.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 2
 
A Cloud Shell terminal will be open from where you can run commands in order to create the Virtual machine instance.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 3
 
Run the below command in the GCP Cloud Shell terminal.
 
gcloud compute zones list | grep us-central1
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 4
 
Suppose I want to create a VM instance in the us-central1-b zone, then we can set the zone by using the below command in the command shell.
 
gcloud config set compute/zone us-central1-b
 
Step 5
 
Run the below command with your machine required machine configuration. In the below example, I have created a VM Instance with name my-vm-2 with n1-standard-1 machine type and of Debian OS with default subnet. We have already set the zone as us-central1-b in the previous step. 
 
gcloud compute instances create “my-vm-2” –machine-type “n1-standard-1” –image-project “debian-cloud” –image “debain-9-stretch-v20190213” –subnet “default”
 
Step 6
 
After successful execution of the command (which will basically take around a minute to be ready for use), your VM Instance will be visible as shown in below image.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 

Setting up the NGINX server in one of the VM Instance

 
Step 1
 
Click on connect with SSH in my-vm-2 VM Instance. Once connected with SSH, ping my-vm-1 VM machine in order to check whether they are able to communicate. As clearly seen, I am able to ping my-vm-1 instance successfully.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 2
 
Now let’s connect with my-vm-1 with SSH.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 3
 
Now, install nginx-light server which is a free, open-source, high-performance HTTP server as shown in the below image.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 4
 
Once nginx-light server is installed, let’s edit the default web page of the nginx server with the nano text editor available in the Debian Linux based operating system using the below command,
 
sudo nano /var/www/html/index.nginx-debian.html
 
Step 5
 
On running the above command, the HTML page will be open in the Nano Text Editor as shown below. I have edited the default document and add the “Hi from Anoop Sharma” paragraph.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 6
 
After saving the above file, I am using the Curl which is a free and open-source command-line tool available in order to check the response from the server.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 7
 
Let’s exit from the my-vm-1 VM instance and hit the http://my-vm-1 URL from my-vm-2 VM instance. In the below image, you can clearly see that we are successfully able to hit the URL with curl.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
Step 8
 
Now, click on the external I.P. Address of the my-vm-1 as shown in the below image.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
Step 9
 
A web page will be open which is served through my-vm-1 VM Instance.
 
Create Virtual Machine Instance In Compute Engine In Google Cloud Platform
 
I hope this article will help you in getting started with the computing engine in Google Cloud Platform. 


Similar Articles