Google Cloud Series, Part 1: How To Create A Virtual Machine

What is Google Cloud Platform?

Google Cloud platform (GCP) is large set of physical assets. This includes computers, hard disks, processors and virtual assets (such as Virtual Machines) that are contained in Google Cloud data centers. Each data center is present in a global region, and each of these regions is a collection of zones. Each zone occupies its own separate space within the same region. This organization structure provides facilities like data redundancy in case of zone failure, reduced latency by locating resources closer to client, and more control over resources used to improve the service and reduce the cost.

With GCP, physically buying the hardware is a non-issue. You can use all the hardware/software Google provides as services.  These services allow access to the underlying hardware. When you begin development, you’ll notice your product is just a combination of services from Google–plus your code.

To Get Started…

You’ll need a Google account with billing enabled. If you are using GCP for the first time, create a billing account using any credit/debit card with international transaction enabled and you will get free credits from Google.

First step will be to log in to your Google cloud console and create a new project (name it whatever you like). You might be curious about the role of this project in creating a virtual machine. But any cloud platform resource that you allocate and use must belong to a project.

After creating the project, you’ll see it on your dashboard. This project info contains the project name, ID (which will help GCP identify your project), and number, which will be used by the support team should you require assistance.

There are three ways to create a virtual machine:

  1. Create using Google Cloud Console.

  2. Create using “gcloud” command line tool.

  3. Create using Compute Engine REST API

We’re going to focus on Google Cloud Console and Google Cloud Command Line Tool.

Creating Virtual Machine Using Google Cloud Console

Click menu icon on the top left of the screen:

Navigate to Compute engine and VM instances. It may take some time the first time you click on VM instances, but once its initialized you will see something like this: (keep in mind you need to enable billing for your project to see this).

Click on “Create”, then you will see this page:

You can specify the name of the instance that you want to create. Specify the zone in which you want to create this instance. You can select the machine type that you want to use for your instance. There are large number of machines available from which you can select, depending upon your requirement. You can even customize and create your own machine type.

You can also choose the boot disk from which you want to use to boot this virtual machine.

You can select the service account which will be used by this instance. Service account isn’t important right now–think of it as a way GCP identifies and authorizes your virtual machine to communicate with other services of GCP.

To allow incoming and outgoing traffic, there are firewall rules. These are applied to Virtual Machines using tags.

There are customizations available related to management, disks, SSH etc., but, for now, click “Create”.

This creation process is asynchronous, but once the instance is created you will see a green checkmark with the name of the instance.

Congratulations! You have successfully created a virtual machine. So what’s next?

Click on the SSH link. You will be able to see the console of your virtual instance. Now you have the root access for it without doing anything else. Log in as root user by running:

sudo su -

This will log you in as root and you will see something like this:

Where “instance-1” is the name of your instance.  Now, you need to update your OS by running:

apt-get update

This will update your instance with all the security patches, among other things, and finally install the nginx server.

apt-get install nginx -y

Once installation is done, check if nginx is running with:

ps auwx | grep nginx

Now go to your console and click on the external IP. You should see the default page:

Having your own server can be just that easy.

You can do all these things with “gcloud” also. Generally “gcloud” will be used when you want to create instances using scripts. But for now let’s see how can we create a simple instance with all the default values.

Creating Virtual Machine Using gcloud

gcloud is a command line tool available from Google we can install in our systems, or we can use Google command shell which offers many pre-installed packages with a memory of about 5GB. For this purpose, we will be using Google command shell. You can open cloud shell by clicking on the icon on the top right of the screen.

Once opened, you can create a virtual machine instance using command:

gcloud compute instances create instance-1 --zone us-central1-c

Virtual Machine is a zonal resource, so we must specify the zone in which we want to create our instance. You cannot have instances with the same name, in same zone, under same project. You can explore more options under compute using:

gcloud compute instances create — help

When prompted, create a passphrase for your vm instance. Click enter if you want to create an empty passphrase.

 

Stay tuned for Part 2 of this GCP series where we will explore, more in depth, the “gcloud” command line tool.

Stay-Up-To-Date

Keep in the loop with the latest in emerging technology and Mutual Mobile