Creating a VM From Scratch


Introduction to Google Compute Engine

The course is part of this learning path

Start course

This course will introduce you to the Google Compute Engine. 

Learning Objectives

  • What Google Compute Engine is
  • How it differs from the other Google compute offerings
  • How to create virtual machine instances from scratch, from a template, and from a machine image

Intended Audience

  • Cloud Architects
  • System Administrators
  • GCP Developers
  • Anyone preparing for a Google Cloud certification


  • Basic understanding of Virtual Machines
  • Access to a GCP account



So, in this lesson, I'm going to demonstrate how to create and manage Virtual Machines using Google Compute Engine. Now, Compute Engine has a ton of options and it can feel a little overwhelming to use at first. So, be aware, I'm not going to try to cover every single detail. Instead, I just want to focus on the main features. So, don't be surprised when I skip over some things. So, the easiest way to get started using compute engine is to log into the GCP console. Now you can see here that I've already done that. Once you're on the main page, you want to navigate to Compute Engine. Now you can do this by either clicking on the navigation window and then scroll down to where it says Compute Engine or you can search for Compute Engine using the search bar. The initial page here is going to show you a list of your current VMs if you have any. So, if you're using a new account, your screen should look something like this. You'll notice that there are a lot of different options on the left side of the screen. And this is because you can manage a lot more than just VMs in Compute Engine.

But today, we're going to ignore most of that. In Compute Engine, you will typically be working with both virtual machines and virtual machine instances. Now it's important to understand the difference between the two. A virtual machine is an object that describes what the emulated server should look like. An instance is a running copy of the VM. So, it basically works like any other piece of software. You can think of the VM as an executable file and the instances are like running copies of the executable. So, if you want to spin up a new VM, you need to click on the 'Create Instance' button either here or here. Now there are four main ways to create a VM instance. You can create it from scratch, you can create it from a template, you can create it from a machine image or you can create it using the Marketplace. Now I'm only going to cover the first three and Marketplace will be covered in its own dedicated course. So, let's begin by creating a VM instance from scratch. All you have to do is fill out this form in the middle column. You'll notice on the right side, there's a pricing estimate based off of all your currently selected options. So, as you choose different options here in the middle, the price on the right is either going to increase or decrease. So, the first thing you should do is pick a name for your instance.

Now, this will help us distinguish it from other instances. I'm going to call mine demo-vm1. The next option I want to look at is region and zone. Now these determine where your VM instance is going to be physically located. Region describes the general geographic region. You can pick a location in North America, South America, Europe, Asia or Australia. Now, zone represents a specific data center in that region. And as you can see, there are multiple zones per region. Now, each VM instance must be assigned to a specific region and zone. Be aware that if that zone goes down, then it's going to take all the assigned instances with it. So, you might want to consider having multiple copies of your VMs spread across multiple zones. The next section I want to look at is machine configuration. This determines how much processing power and memory will be assigned to your VM. Now machine types are broken up into four families. General-purpose machines are generally the cheapest and probably the most commonly used. Compute-optimized machines are a lot more powerful, but also a lot more expensive. Memory-optimized machines are usually even more expensive. If you really need a server with almost six terabytes of memory, then you can get it. And finally, there are these GPU machines.

Now Google also likes to refer to these as accelerator-optimized. These are best for handling any workloads that involve graphics processing or even machine learning jobs. You can further customize your machine configuration by choosing a series and a type. Now series generally corresponds to the hardware generation, and higher numbers usually represent newer, more powerful processors. Machine type allows you to select the exact number of virtual CPUs and memory for your VM. As you can see, there are several predefined types to choose from, but you can also create your own custom machine type as well. Just remember, whenever you make a change to the configuration, you want to review the estimates here. A small change can make a big impact. So, the next section I want to look at is this container section. Now, generally, most people will probably want to use a managed service like Cloud Run for running containers. However, if you want to manage everything manually then you can use Compute Engine if you wish. Just click on the button here, specify the container you want to deploy, and then configure any additional parameters as needed.

This boot disk section lets you specify what your main local storage device will look like. Typically, you'll use this to pick an operating system and then set the amount of disk space available. You can see by default it assigned me a 10 gigabyte drive with Debian Linux installed, but that's easy enough to change. There are multiple Linux flavors available including CentOS, RedHat, and Ubuntu. And there are Microsoft options like Windows server and even SQL server. Now, if you know you're going to do a lot of reading and writing, then you can pick a higher speed disk type here. And if you need lots of extra storage, you can increase the amount here. Now remember, this just controls the main boot disk. You can also create and attach additional drives, but that's something that I'm going to demonstrate later. Here are the identity and API management section, lets you control the permissions allocated to your instance. Now there's going to be times where you're going to want your VM instance to be able to access other Google Cloud resources. So, maybe you need to store some records in a Cloud SQL database. In order to do that, you're going to have to grant it the appropriate permissions. Here, you can assign your instance a service account, which will control what it is allowed to do, or you can directly control which Google Cloud APIs you can connect to. This last option here allows you to enable some common firewall rules.

If your VM instance is going to be running some sort of web interface, then you can use these to easily open up ports 80 and 443. Now, there are even more settings available under advanced options but we already covered quite a lot, so let's go ahead and accept the rest of the defaults and click on 'Create'. Instance creation can take a while depending upon your exact selections. So, to save us some time, I'm going to fast forward. So, now the instance has been provisioned and it is up and running. We can see that it's been assigned two IPs; one public and one private. Now because we did not customize the network settings under the advanced section, it set this all up for us automatically. So, now that it is up and running, we can view the full details by clicking on the name. This screen will tell you everything you need to know about your VM. Also, it will allow you to make some changes. Just click on the edit button at the top of the page. However, you're going to notice that most of these options cannot be changed. If you want to change something like the machine type, then what you actually need to do is delete the existing VM and then create a new one instead. However, you are allowed to do minor edits like make changes to the network settings. Now, this details page allows you to do several other operations; however, those are usually quicker to do on the main page. So, let me return to that.

If you click on this more actions icon, you can see all the options that are available. So, if you need to reboot your VM, you can select stop and then start, and you can also use this to suspend or resume your VM as well. Now two other important features you need to know about are logging and monitoring. Google keeps detailed logs about everything that happens to your instances. Things like when they start up, when they shut down, and when something was changed. These logs explorer page can help you identify problems and then figure out what caused them. You also need to know about monitoring. Now, monitoring lets you know important metrics about your instances. You can look at things like CPU utilization and network traffic. If your CPU suddenly spikes or if your network traffic drops to zero, you're going to want to know. So, this dashboard will help you verify that everything is working as expected and it will notify you of any concerning trends. You might notice that some of the metrics are not currently getting populated. And this is because by default, Google can only monitor basic metrics. Now if you want more detailed information, like memory or disk utilization, you're going to need to install the Ops Agent.

Ops Agent is a program that runs on your virtual machine and it's used to report advanced metrics to Google. It supports both Linux and Windows and it runs alongside your other software. Also, it's really easy to install. You can click on this button and have Google install it for you. Or if you want, you can manually install it yourself. I'm going to show you how to do a manual installation because you can use the same process to install any custom software you want. So, first, I need to go back to the VM instance page and then I want to connect to my VM. To do that, I just need to click on the 'Connect via SSH' button here. Now, this is going to open a terminal window and it's going to allow me to issue commands to my Linux instance. While this is using an SSH connection, it's all being managed by Google. And because of that, this only currently works using the browser. Now, if I wanted to directly connect from my laptop without using the web interface, I would have to create and upload my own custom SSH keys. This is something that I'll demonstrate later. So, now that I'm logged in, I can type in and run any standard Linux commands.

So, at this point, I can use my package manager to install or update any components. But what I want to do is paste in this command that will download the installation script for the Ops Agent. And now, I can run the script with this command. Now, if this was a Windows VM instead, then the manual installation process would be slightly different. So, now the installation of the Ops Agent has finished, let me go back to the monitoring page and verify that everything is working. It's no longer asking me to install the agent and it's starting to pick up telemetry data for memory utilization and disk utilization. So, that covers all the basics for creating an instance from scratch.


About the Author
Learning Paths

Daniel began his career as a Software Engineer, focusing mostly on web and mobile development. After twenty years of dealing with insufficient training and fragmented documentation, he decided to use his extensive experience to help the next generation of engineers.

Daniel has spent his most recent years designing and running technical classes for both Amazon and Microsoft. Today at Cloud Academy, he is working on building out an extensive Google Cloud training library.

When he isn’t working or tinkering in his home lab, Daniel enjoys BBQing, target shooting, and watching classic movies.