Support us on YouTube by Subscribing our YouTube Channel. Click here to Subscribe our YouTube Channel

Tuesday, 4 August 2020

Create Virtual Machine instance in Compute Engine in Google Cloud Platform

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.
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).
2. Once logged in to google cloud platform, you will see the dashboard as shown below.
3. Click on Compute Engine -> then click on VM Instances.
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)
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.
6. Select Boot Disk. As in the example, I am using a Debian operating system which is basically a Linux based OS.
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.
8. On clicking on the Create button, it will take less than a minute in order to create the selected VM Instance.
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 VM instance with gcloud command-line utility of Google Cloud Platform
1. Click on the top Cloud Shell button in order to use command-line access to create the VM Instance.
2. A Cloud Shell terminal will be open from where you can run commands in order to create the Virtual machine instance.
3. Run the below command in the GCP Cloud  Shell terminal.
gcloud compute zones list | grep us-central1
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
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” 
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:


Setting up the NGINX server in one of the VM Instance:
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.
2. Now let’s connect with my-vm-1 with SSH.
3. Now, install nginx-light server which is a free, open-source, high-performance HTTP server as shown in the below image.
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
5. On running the above command, 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.
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.

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.
8. Now, click on the external I.P. Address of the my-vm-1 as shown in the below image.
9. A web page will be open which is served through my-vm-1 VM Instance.
Hope this article will help you in getting started with the compute engine in Google Cloud Platform. 
Thanks,

Protected by Copyscape - Do not copy content from this page.

0 comments:

Post a Comment

Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook