03 Virtual Machines
03 Virtual Machines
Virtual Machines
VMs are the most common infrastructure component, and in Google Cloud, they’re
provided by Compute Engine. A VM is similar, but not identical, to a hardware
computer. VMs consists of a virtual CPU, some amount of memory, disk storage, and
an IP address. Compute Engine is Google Cloud’s service to create VMs; it is very
flexible and offers many options, including some that can't exist in physical hardware.
For example, a micro VM shares a CPU with other virtual machines, so you can get a
VM with less capacity at a lower cost. Another example of a function that can't exist in
hardware is that some VMs offer burst capability, meaning that the virtual CPU will run
above its rated capacity for a brief period, using the available shared physical CPU.
The main VM options are CPUs, memory, disks, and networking.
Proprietary + Confidential
Agenda
01 Compute Engine
Lab: Creating Virtual Machines
03 Images
04 Disk Options
Now this is going to be a very robust module; there's a lot of detail to cover here with
how virtual machines work on Google Cloud. First we'll start with the basics of
Compute Engine, followed by a quick little lab to get you more familiar with creating
virtual machines.
Then, we’ll look at the different CPU and memory options that enable you to create
different configurations.
Next, we will look at images and the different disk options available with Compute
Engine.
After that, we will discuss very common Compute Engine actions that you might
encounter in your day-to-day job. This will be followed by an in-depth lab that explores
many of the features and services covered in this module.
Compute Engine
01
Proprietary + Confidential
Now the difference is, Compute Engine gives you the utmost in flexibility: run
whatever language you want—it's your virtual machine. This is purely an
infrastructure as a service or IaaS model.
You have a VM and an operating system, and you can choose how to manage it and
how to handle aspects, such as autoscaling, where you’ll configure the rules about
adding more virtual machines in specific situations. Autoscaling will be covered later
in the course.
The primary work case of Compute Engine is any general workload, especially an
enterprise application that was designed to run on a server infrastructure. This makes
Compute Engine very portable and easy to run in the cloud.
Compute Engine
So what is Compute Engine? At its heart, it's physical servers that you're used to,
running inside the Google Cloud environment, with a number of different
configurations.
Both predefined and custom machine types allow you to choose how much memory
and how much CPU you want. You choose the type of disk you want, whether you
want to use persistent disks backed up by standard hard drives or solid-state drives,
local SSDs, Cloud Storage, or a mix. You can even configure the networking
interfaces and run a combination of Linux and Windows machines. We will discuss
these options in more detail later in the module.
Proprietary + Confidential
● Per-second billing
● Instance metadata
● Sustained use discounts
● Startup and shutdown
scripts ● Committed use discounts
Several different features will be covered throughout this module, such as machine
rightsizing, startup and shutdown scripts, metadata, availability policies, OS patch
management, and pricing and usage discounts.
Proprietary + Confidential
Compute
Compute Engine provides several different machine types that we’ll discuss later in
this module. If those machines don’t meet your needs, you can also customize your
own machine.
Your choice of CPU will affect your network throughput. Specifically, your network will
scale at 2 gigabits per second for each CPU core, except for instances with 2 or 4
CPUs which receive up to 10 gigabits per second of bandwidth.
There is a theoretical maximum throughput of 200 gigabits per second for an instance
with 176 vCPU, when you choose an C3 machine series.
When you're migrating from an on-premises setup, you're used to physical cores,
which have hyperthreading. On Compute Engine, each virtual CPU (or vCPU) is
implemented as a single hardware hyper-thread on one of the available CPU
Platforms.
For an up-to-date list of all the available CPU platforms, please refer to the
documentation page.
Proprietary + Confidential
Storage
Disks
After you pick your compute options, you want to choose your disk.
You have three options: Standard, SSD, or local SSD. So basically, do you want the
standard spinning hard disk drives (HDDs), or flash memory solid-state drives
(SSDs)? Both of these options provide the same amount of capacity in terms of disk
size when choosing a persistent disk. Therefore, the question really is about
performance versus cost, because there's a different pricing structure.
Basically, SSDs are designed to give you a higher number of IOPS per dollar versus
standard disks, which will give you a higher amount of capacity for your dollar.
Local SSDs have even higher throughput and lower latency than SSD persistent
disks, because they are attached to the physical hardware. However, the data that
you store on local SSDs persists only until you stop or delete the instance. Typically, a
local SSD is used as a swap disk, just like you would do if you want to create a
ramdisk, but if you need more capacity, you can store those on a local SSD. You can
create instances with up to 24 separate 375-GB local SSD partitions for a total of 9
TB of local SSD space for each instance.
Standard and non-local SSD disks can be sized up to 257 TB for each instance. The
performance of these disks scales with each GB of space allocated.
Proprietary + Confidential
Networking
You’ll also notice that you can do regional HTTPS load balancing and network load
balancing. This doesn’t require any pre-warming because a load balancer isn't a
hardware device that needs to analyze your traffic. A load balancer is essentially a set
of traffic engineering rules that are coming into the Google network, and VPC is
applying your rules destined for your IP address subnet range. We’ll learn more about
load balancers later in the course.
For a quick walk through of the VM instance creation process, refer to this demo.
Proprietary + Confidential
VM access
For accessing a VM, the creator of an instance has full root privileges on that
instance.
On a Linux instance, the creator has SSH capability and can use the Google Cloud
console to grant SSH capability to other users.
On a Windows instance, the creator can use the console to generate a username and
password. After that, anyone who knows the username and password can connect to
the instance using a Remote Desktop Protocol, or RDP, client.
We listed the required firewall rules for both SSH and RDP here, but you don’t need to
define these if you are using the default network that we covered in the previous
module.
Refer to these links, for more information on SSH key management and creating
passwords for Windows instances.
Proprietary + Confidential
VM lifecycle
Restart
Reset
Export
Root disk System Access system Terminated
Persistent disk Image Cloud SSH | RDP image
Storage
Snapshot Availability
Delete
persistent Policy
Additional Modify disk
Boot
disks Use
Move VM to
different
Live migrate zone
When you define all the properties of an instance and click Create, the instance
enters the provisioning state. Here the resources such as CPU, memory, and disks
are being reserved for the instance, but the instance itself isn’t running yet. Next, the
instance moves to the staging state where resources have been acquired and the
instance is prepared for launch. Specifically, in this state, Compute Engine is adding
IP addresses, booting up the system image, and booting up the system.
After the instance starts running, it will go through pre-configured startup scripts and
enable SSH or RDP access. Now, you can do several things while your instance is
running. For example, you can live migrate your virtual machine to another host in the
same zone instead of requiring your instance to be rebooted. This allows Google
Cloud to perform maintenance that is integral to keeping the infrastructure protected
and reliable, without interrupting any of your VMs. While your instance is running, you
can also move your VM to a different zone, take a snapshot of the VM’s persistent
disk, export the system image, or reconfigure metadata. We will explore some of
these tasks in later labs.
Some actions require you to stop your virtual machine; for example, if you want to
upgrade your machine by adding more CPU. When the instance enters this state, it
will go through pre-configured shutdown scripts and end in the terminated state. From
this state, you can choose to either restart the instance, which would bring it back to
its provisioning state, or delete it.
You also have the option to reset a VM, which is similar to pressing the reset button
on your computer. This actions wipes the memory contents of the machine and resets
the virtual machine to its initial state. The instance remains in the running state
through the reset.
Proprietary + Confidential
There are different ways you can change a VM state from running. Some methods
involve the Google Cloud console and the gcloud command, while others are
performed from the OS, such as for reboot and shutdown.
It’s important to know that if you are rebooting, stopping, or even deleting an instance,
the shutdown process will take about 90 sec. For a preemptible VM, if the instance
does not stop after 30 seconds, Compute Engine sends an ACPI G3 Mechanical Off
signal to the operating system. Remember that when writing shutdown scripts for
preemptible VMs.
Proprietary + Confidential
Automatic restart
● Automatic VM restart due to crash or maintenance event
○ Not preemption or a user-initiated terminate
On host maintenance
● Determines whether host is live-migrated or terminated due to a maintenance event.
Live migration is the default.
Live migration
● During maintenance event, VM is migrated to different hardware without interruption.
● Metadata indicates occurrence of live migration.
As we mentioned previously, Compute Engine can live migrate your virtual machine to
another host due to a maintenance event to prevent your applications from
experiencing disruptions. A VM’s availability policy determines how the instance
behaves in such an event.
The default maintenance behavior for instances is to live migrate, but you can change
the behavior to terminate your instance during maintenance events instead. If your
VM is terminated due to a crash or other maintenance event, your instance
automatically restarts by default, but this can also be changed.
These availability policies can be configured both during the instance creation and
while an instance is running by configuring the Automatic restart and On host
maintenance options.
For more information on live migration, please refer to the documentation page.
Proprietary + Confidential
OS patch management:
● Patch compliance reporting
● Patch deployment
OS updates are a part of managing an infrastructure. Let’s see how we can manage
the updates to a fleet of Windows VMs.
When you provision a premium image, there is a cost associated with the image. This
cost includes both the usage of the OS but also the patch management of the OS.
Using Google Cloud, we can easily manage the patching of your OSes.
Managing patches effectively is a great way to keep your infrastructure up-to-date and
reduce the risk of security vulnerabilities. But without the right tools, patching can be
daunting and labor intensive.
There are several tasks that can be performed with patch management. You can :
When a VM is terminated, you do not pay for memory and CPU resources. However,
you are charged for any attached disks and reserved IP addresses.
Proprietary + Confidential
In the terminated state, you can perform any of the actions listed here, such as
changing the machine type, but you cannot change the image of a stopped VM.
Also, not all of the actions listed here require you to stop a virtual machine. For
example, VM availability policies can be changed while the VM is running, as
discussed previously.
Proprietary + Confidential
Lab Intro
Creating Virtual Machines
Let’s take some of the Compute Engine concepts that we just discussed and apply
them in a lab.
Proprietary + Confidential
Lab objectives
Let’s take some of the Compute Engine concepts that we just discussed and apply
them in a lab.
In this lab, you explore virtual machine instance options by creating several standard
VMs and a custom VM. You also connect to those VMs using both SSH for Linux
machines and RDP for Windows machines.
Proprietary + Confidential
Compute Options
02
(vCPU and Memory)
Now that you have completed the lab, let’s dive deeper into the compute options that
are available to you in Google Cloud, by focusing on CPU and memory.
Proprietary + Confidential
Creating a VM
01
console.google.com
You have three options for creating and configuring a VM. You can use the Google
Cloud console as you did in the previous lab, the Cloud Shell command line, or the
RESTful API. If you’d like to automate and process very complex configurations, you
might want to programmatically configure these through the RESTful API by defining
all the different options for your environment.
If you plan on using the command line or RESTful API, we recommend that you first
configure the instance through the console and then ask Compute Engine for the
equivalent REST request or command line, as we showed you in my demo earlier.
This way you avoid any typos and get dropdown lists of all the available CPU and
memory options.
Speaking of CPU and memory options, let’s look at the different machine types that
are currently available.
Proprietary + Confidential
Machine family
Machine series
Machine type
When you create a VM, you select a machine type from a machine family that
determines the resources available to that VM. There are several machine families
you can choose from and each machine family is further organized into machine
series and predefined machine types within each series.
Alternatively, you can create custom machine types. These let you specify the number
of vCPUs and the amount of memory for your instance.
Proprietary + Confidential
General-purpose
Compute-optimized
Memory-optimized
Accelerator-optimized
● General-purpose
● Compute-optimized
● Memory-optimized, and
● Accelerator-optimized
The general-purpose machine family has the best price-performance with the most
flexible vCPU to memory ratios, and provides features that target most standard and
cloud-native workloads.
The E2 machine series is suited for day-to-day computing at a lower cost, especially
where there are also no application dependencies on a specific CPU architecture.
E2 VMs provide a variety of compute resources for the lowest price on Compute
Engine, especially when paired with committed-use discounts. You simply pick the
amount of vCPU and memory that you want, and Google provisions it for you.
Standard E2 VMs have between 2 to 32 vCPUs with a ratio of 0.5 GB to 8 GB of
memory per vCPU.
They are a great choice for web servers, small to medium databases, development
and test environments, and many applications that don't have strict performance
requirements. They offer a compatible performance baseline with the current N1 VMs
for those of you who have been using them.
The E2 machine series also contains shared-core machine types that use
context-switching to share a physical core between vCPUs for multitasking. Different
shared-core machine types sustain different amounts of time on a physical core. In
general, shared-core machine types can be more cost-effective for running small,
non-resource intensive applications than standard, high-memory, or high-CPU
machine types. Shared-core E2 machine types have 0.25 to 1 vCPUs with 0.5 GB to
8 GB of memory.
N2 and N2D are the next generation following N1 VMs, offering a significant
performance jump.
N2 and N2D are the most flexible VM types and provide a balance between price and
performance across a wide range of VM shapes, including enterprise applications,
medium-to-large databases, and many web and app-serving workloads. Committed
use and sustained use discounts are supported.
N2 VMs support the latest second generation scalable processor from Intel with up to
128 vCPUs and 0.5 to 8 GB of memory per vCPU. Cascade Lake is the default
processor for machine types up to 80 vCPUs. For larger machine types Ice Lake is
the default processor for specific regions and zones.
N2D are AMD-based general purpose VMs. They leverage the latest EPYC Milan and
EPYC Rome processors, and provide up to 224 vCPUs per node.
Tau T2D VMs are optimized for cost-effective performance of demanding scale-out
workloads.
T2D VMs are built on the latest 3rd Gen AMD EPYCTM processors and offer full x86
compatibility. They are suited to scale-out workloads including web servers,
containerized microservices, media transcoding, and large-scale Java applications.
T2D VMs come in predefined VM shapes, with up to 60 vCPUs per VM and 4 GB of
memory per vCPU.
If you have containerized workloads, Tau VMs are supported by Google Kubernetes
Engine to help optimize price-performance. You can add T2D nodes to your GKE
clusters by specifying the T2D machine type in your GKE node pools.
The compute-optimized machine family has the highest performance per core on
Compute Engine and is optimized for compute-intensive workloads.
C2 VMs are the best fit VM type for compute-intensive workloads, including AAA
gaming, electronic design automation, and high-performance computing across
simulations, genomic analysis, or media transcoding. They might also be applications
that have very expensive per core licensing and thus would benefit from higher per
core performance.
The C2 series comes in different machine types ranging from 4 to 60 vCPUs, and
offers up to 240 GB of memory. You can also attach up to 3 TB of local storage to
these VMs for applications that require higher storage performance.
The C2D machine series provides the largest VM sizes and are best-suited for
high-performance computing (HPC). The C2D series also has the largest available
last-level cache (LLC) cache per core.
The C2D machine series come in different machine types ranging from 2 to 112
vCPUs, and offer 4 GB of memory per vCPU. You can also attach up to 3 TB of local
storage to these machine types for applications that require higher storage
performance. C2D VMs are available on the third generation AMD EPYC Milan
platform.
Compute-optimized machines:
https://cloud.google.com/compute/docs/compute-optimized-machines
Proprietary + Confidential
The memory-optimized machine family provides the most compute and memory
resources of any Compute Engine machine family offering. They are ideal for
workloads that require higher memory-to-vCPU ratios than the high-memory machine
types in the general-purpose machine family.
The M1 machine series has up to 4 TB of memory, while the M2 machine series has
up to 12 TB of memory. These machine series are well-suited for large in-memory
databases such as SAP HANA, as well as in-memory data analytics workloads.
Both the M1 and M2 machine series offer the lowest cost per GB of memory on
Compute Engine, making them a great choice for workloads that utilize higher
memory configurations with low compute resources requirements. Additionally, they
offer up to 30% sustained use discounts and are also eligible for committed use
discounts, bringing additional savings of greater than 60% for three-year
commitments.
Memory-optimized machines:
https://cloud.google.com/compute/docs/memory-optimized-machines
Proprietary + Confidential
If none of the predefined machine types match your needs, you can independently
specify the number of vCPUs and the amount of memory for your instance. Custom
machine types are ideal for the following scenarios:
● When you have workloads that are not a good fit for the predefined machine
types that are available to you.
● Or when you have workloads that require more processing power or more
memory, but don't need all of the upgrades that are provided by the next larger
predefined machine type.
It costs slightly more to use a custom machine type than an equivalent predefined
machine type, and there are still some limitations in the amount of memory and
vCPUs you can select:
Selected custom machine type can allow to have up to 8 GB of memory per vCPU.
However, this might not be enough memory for your workload. At an additional cost,
you can get more memory per vCPU beyond the 8 GB limit. This is referred to as
extended memory, and you can learn more about this on this documentation page.
Proprietary + Confidential
Finland
Netherlands
Berlin
Warsaw
London
Montréal Belgium Frankfurt
Toronto Paris Zurich
Oregon Iowa* Turin Milan
Salt Lake City Madrid
N. Virginia Seoul
Las Vegas Columbus Tokyo
Los Angeles S. Carolina
Dallas Tel Aviv Osaka
Dammam Delhi
Doha Taiwan
Hong Kong
Mumbai
Singapore
Jakarta
zone
Current region Future region
*Exception: region has 4 zones.
with 3 zones with 3 zones
The first thing you want to consider when choosing a region and zone is the
geographical location in which you want to run your resources. This map shows the
current and planned Google Cloud regions and number of zones. For up-to-date
information on the available regions and zones, please refer to the documentation
page.
Each zone supports a combination of Ivy Bridge, Sandy Bridge, Haswell, Broadwell,
and Skylake platforms. When you create an instance in the zone, your instance will
use the default processor supported in that zone. For example, if you create an
instance in the us-central1-a zone, your instance will use a Sandy Bridge processor.
Proprietary + Confidential
Pricing
● Resource-based pricing:
○ Each vCPU and each GB of memory is billed separately
● Discounts:
○ Sustained use
○ Committed use
○ Preemptible and Spot VM instances
● Recommendation Engine
○ Notifies you of underutilized instances
Google Cloud offers a variety of different options to keep the prices low for Compute
Engine resources:
All vCPUs, GPUs, and GB of memory are charged a minimum of 1 minute. For
example, if you run your virtual machine for 30 seconds, you will be billed for 1 minute
of usage. After 1 minute, instances are charged in 1-second increments.
Compute Engine uses a resource-based pricing model, where each vCPU and each
GB of memory on Compute Engine is billed separately rather than as part of a single
machine type. You still create instances using predefined machine types, but your bill
reports them as individual vCPUs and memory used.
There are several discounts available but the discount types cannot be combined:
The ability to customize the amount of memory and CPU through custom machine
types allows for further pricing customization. Speaking of sizing your machine,
Compute Engine provides VM sizing recommendations to help you optimize the
resource use of your virtual machine instances. When you create a new instance,
recommendations for the new instance will appear 24 hours after the instance has
been created.
Compute Engine also has Free Usage Limits. For the exact terms, please refer to the
documentation page.
Proprietary + Confidential
Sustained use discounts for up to 30% Sustained use discounts for up to 20%
General-purpose N1 predefined and custom General-purpose N2 and N2D predefined and
machine types, memory-optimized machine types, custom machine types, and compute-optimized
shared-core machine types, and sole-tenant nodes machine types
25% - 50% 80% of base rate 25% - 50% 86.78% of base rate
50% - 75% 60% of base rate 50% - 75% 73.3% of base rate
75% - 100% 40% of base rate 75% - 100% 60% of base rate
Up to 30% net discount for instances that run the entire month
Sustained use discounts are automatic discounts that you get for running specific
Compute Engine resources (vCPUs, memory, GPU devices) for a significant portion
of the billing month. For example, when you run one of these resources for more than
25% of a month, Compute Engine automatically gives you a discount for every
incremental minute you use for that instance. The discount increases with usage, and
you can get up to a 30% net discount for instances that run the entire month.
This tables shown on this slide describes the discount you get at each usage level of
a VM instance. To take advantage of the full 30% discount, create your VM instances
on the first day of the month, because discounts reset at the beginning of each month.
Sustained use
discounts
increase with use
The graph on this slide demonstrates how your effective discount increases with use.
For example, if you use a virtual machine for 50% of the month, you get an effective
discount of 10%. If you use it for 75% of the month, you get an effective discount of
20%. If you use it for 100% of the month, you get an effective discount of 30%. You
can also use the Google Cloud Pricing Calculator to estimate your sustained use
discount for any arbitrary workload. For the calculator, please refer to this page.
Compute Engine calculates sustained use discounts based on vCPU and memory
usage across each region and separately for each of the following categories:
Let’s go through an example where you have two instances that are in the same
region but have different machine types and run at different times of the month.
Compute Engine breaks down the number of vCPUs and amount of memory used
across all instances that use predefined machine types and combines the resources
to qualify for the largest sustained usage discounts possible. As shown on this slide,
you run the following two instances in the us-central1 region during a month:
● For the first half of the month, you run an n1-standard-4 instance with 4
vCPUs and 15 GB of memory
● For the second half of the month, you run a larger n1-standard-16 instance
with 16 vCPUs and 60 GB of memory
In this scenario, Compute Engine reorganizes these machine types into individual
vCPUs and memory resources and combines their usage to create the following
resources, as shown on the bottom:
Preemptible
● You can request that CPU quota for a region be split between regular and preemption
○ Default: preemptible VMs count against region CPU quota
As we mentioned earlier, a preemptible VM is an instance that you can create and run
at a much lower price than normal instances. See whether you can make your
application function completely on preemptible VMs, because a 60-91 percent
discount is a significant investment in your application.
Now, just to reiterate, these VMs might be preempted at any time, and there is no
charge if that happens within the first 1 minute. Also, preemptible VMs are only going
to live for up to 24 hours, and you only get a 30-second notification before the
machine is preempted. It’s also worth noting that there are no live migrations nor
automatic restarts in preemptible VMs, but something that we will highlight is that you
can actually create monitoring and load balancers that can start up new preemptible
VMs in case of a failure. In other words, there are external ways to keep restarting
preemptible VMs if you need to.
One major use case for preemptible VMs is running a batch processing job. If some of
those instances terminate during processing, the job slows but does not completely
stop. Therefore, preemptible instances complete your batch processing tasks without
placing additional workload on your existing instances, and without requiring you to
pay full price for additional normal instances:
https://cloud.google.com/compute/docs/instances/preemptible#what_is_a_preemptibl
e_instance
Now, let’s take a look at Spot VMs.
Proprietary + Confidential
Spot VMs
● Spot VMs and preemptible VMs share the same pricing model
● Spot VMs are finite Compute Engine resources, so they might not always be available
● Best practice use cases help you get the most of using Spot VMs
Spot VMs are the latest version of preemptible VMs. Spot VMs are virtual machine
(VM) instances with the spot provisioning model. New and existing preemptible VMs
continue to be supported, and preemptible VMs use the same pricing model as Spot
VMs. However, Spot VMs provide new features that preemptible VMs do not support.
For example, preemptible VMs can only run for up to 24 hours at a time, but Spot
VMs do not have a maximum runtime.
Like preemptible VMs, Compute Engine might preempt Spot VMs if it needs to
reclaim those resources for other tasks. The probability that Compute Engine stops
Spot VMs for a system event is low, but might vary from day to day and from zone to
zone depending on current conditions. Spot VMs are finite Compute Engine
resources, so they might not always be available. Like preemptible VMs, it’s worth
noting that Spot VMs can't live-migrate to become standard VMs while they are
running. Spot VMs also can’t be set to automatically restart when there is a
maintenance event.
There are many best practices which can help you get the most of using Spot VMs.
For example, resources for Spot VMs come out of excess and backup Google Cloud
capacity. Capacity for Spot VMs is often easier to get for smaller machine types,
meaning machine types with less resources like vCPUs and memory.
For more information on best practices, see
https://cloud.google.com/compute/docs/instances/create-use-spot#best-practices.
And for more information on Spot VMs, see
https://cloud.google.com/compute/docs/instances/spot
Proprietary + Confidential
You can
bring
your own
license!
If you have workloads that require physical isolation from other workloads or virtual
machines in order to meet compliance requirements, you want to consider sole-tenant
nodes.
The diagram on the left shows a normal host with multiple VM instances from multiple
customers. A sole tenant node as shown on the right also has multiple VM instances,
but they all belong to the same project. Currently, the only available node type can
accommodate VM instances up to 96 vCPUs and 624 GB of memory. You can also fill
the node with multiple smaller VM instances of various sizes, including custom
machine types and instances with extended memory. Also, if you have existing
operating system licenses, you can bring them to Compute Engine using sole-tenant
nodes while minimizing physical core usage with the in-place restart feature
To learn how to create nodes and place your instances on those nodes, please refer
to the documentation page.
Proprietary + Confidential
● Secure Boot
● Integrity monitoring
Another compute option is to create shielded VMs. Shielded VMs offer verifiable
integrity of your VM instances, so you can be confident that your instances haven't
been compromised by boot- or kernel-level malware or rootkits.
Shielded VM's verifiable integrity is achieved through the use of Secure Boot, virtual
trusted platform module or vTPM-enabled Measured Boot, and integrity monitoring.
Shielded VMs is the first offering in the Shielded Cloud initiative. The Shielded Cloud
initiative is meant to provide an even more secure foundation for all of Google Cloud
by providing verifiable integrity and offering features, like vTPM shielding or sealing,
that help prevent data exfiltration.
In order to use these shielded VM features, you need to select a shielded image. We'll
learn about images in the next section.
Proprietary + Confidential
Confidential VMs are a breakthrough technology that allows you to encrypt data in
use—while it’s being processed. Google Cloud’s approach to encrypt data in use is
simple, easy-to-use deployment without making any code changes to their
applications or having to compromise on performance. You can collaborate with
anyone, all while preserving the confidentiality of your data.
You can select the Confidential VM service when creating a new VM using the Google
Cloud console, the Compute Engine API, or the gcloud command-line tool.
Proprietary + Confidential
03 Images
What’s in an image?
● Boot loader
● Operating system
● Software
● Customizations
When creating a virtual machine, you can choose the boot disk image. This image
includes the boot loader, the operating system, the file system structure, any
pre-configured software, and any other customizations.
Proprietary + Confidential
Images
Custom images
● Create new image from VM: pre-configured and installed SW
● Import from on-prem, workstation, or another cloud
● Management features: image sharing, image family, deprecation
As you saw in the previous lab, you can choose from both Linux and Windows
images. Some of these images are premium images, as indicated in parentheses with
a p. These images will have per-second charges after a 1-minute minimum, with the
exception of SQL Server images, which are charged per minute after a 10-minute
minimum. Premium image prices vary with the machine type. However, these prices
are global and do not vary by region or zone.
You can also use custom images. For example, you can create and use a custom
image by pre-installing software that's been authorized for your particular
organization.
You also have the option of importing images from your own premises or workstation,
or from another cloud provider. This is a no-cost service that is as simple as installing
an agent, and we highly recommend that you look at it. You can also share custom
images with anybody in your project or among other projects, too.
Proprietary + Confidential
Machine images
A machine image is a Compute Engine resource that stores all the configuration,
metadata, permissions, and data from one or more disks required to create a virtual
machine (VM) instance. You can use a machine image in many system maintenance
scenarios, such as instance creation, backup and recovery, and instance cloning.
Machine images are the most ideal resources for disk backups as well as instance
cloning and replication.
Disk Options
04
At this point you've chosen an operating system, but that operating system is going to
be included as part of some kind of disk. So let’s look at the disk options.
Proprietary + Confidential
Boot disk
Every single VM comes with a single root persistent disk, because you're choosing a
base image to have that loaded on.
This image is bootable in that you can attach it to a VM and boot from it, and it is
durable in that it can survive if the VM terminates. To have a boot disk survive a VM
deletion, you need to disable the “Delete boot disk when instance is deleted” option in
the instance’s properties.
As we discussed earlier, there are different types of disks. Let’s explore these in more
detail.
Proprietary + Confidential
Persistent disks
Network storage appearing as a block device ● Disk resizing: even running and attached!
The first disk that we create is what we call a persistent disk. That means it's going to
be attached to the VM through the network interface. Even though it's persistent, it's
not physically attached to the machine. This separation of disk and compute allows
the disk to survive if the VM terminates. You can also perform snapshots of these
disks, which are incremental backups that we’ll discuss later.
The choice between HDD and SSD disks comes down to cost and performance. To
learn more about disk performance and how it scales with disk size, please refer to
the documentation page.
Another cool feature of persistent disks is that you can dynamically resize them, even
while they are running and attached to a VM.
You can also attach a disk in read-only mode to multiple VMs. This allows you to
share static data between multiple instances, which is cheaper than replicating your
data to unique disks for individual instances.
Zonal persistent disks offer efficient, reliable block storage. Regional persistent disks
provide active-active disk replication across two zones in the same region. Regional
persistent disks deliver durable storage that is synchronously replicated across zones
and are a great option for high-performance databases and enterprise applications
that also require high availability. When you configure a zonal or regional persistent
disk, you can select one of the following disk types.
By default, Compute Engine encrypts all data at rest. Google Cloud handles and
manages this encryption for you without any additional actions on your part. However,
if you wanted to control and manage this encryption yourself, you can either use
Cloud Key Management Service to create and manage key encryption keys (which is
known as customer-managed encryption keys) or create and manage your own key
encryption keys (known as customer-supplied encryption keys).
Proprietary + Confidential
Now, local SSDs are different from persistent disks in that they are physically attached
to the virtual machine. Therefore, these disks are ephemeral but provide very high
IOPS. For up-to-date numbers we recommend referring to the documentation.
Currently, local SSDs are 375 GB in size and you can attach up to 24 local SSD
partitions for a total of 9 TB per instance.
Data on these disks will survive a reset but not a VM stop or terminate, because these
disks can’t be reattached to a different VM.
Proprietary + Confidential
RAM disk
● tmpfs
● May need a larger machine type if RAM was sized for the application
You can simply use tmpfs if you want to store data in memory. This will be the fastest
type of performance available if you need small data structures. We recommend a
high-memory virtual machine if you need to take advantage of such features, along
with a persistent disk to back up the RAM disk data.
Proprietary + Confidential
Use case General, bulk file Very random High IOPS and low latency and
storage IOPS low latency risk of data loss
In summary, you have several different disk options. Persistent disks can be rebooted
and snapshotted, but local SSDs and RAM disks are ephemeral.
We recommend choosing a persistent HDD disk when you don't need performance
but just need capacity. If you have high performance needs, start looking at the SSD
options. The persistent disks offer data redundancy because the data on each
persistent disk is distributed across several physical disks.
Local SSDs provide even higher performance, but without the data redundancy.
Finally, RAM disks are very volatile but they provide the highest performance.
Proprietary + Confidential
Shared-core 16
Standard
High-memory
High-CPU 128
Memory-optimized
Compute-optimized
Now, just as there is a limit on how many Local SSDs you can attach to a VM, there is
also a limit on how many persistent disks you can attach to a VM. As illustrated in this
table, this limit depends on the machine type. For the Shared-core machine type, you
can attach up to 16 disks. For the Standard, High Memory, High-CPU,
Memory-optimized, and Compute-optimized machine types, you can attach up to 128
disks. So you can create massive amounts of capacity for a single host.
Now remember that little nuance when we told you about how throughput is limited by
the number of cores that you have? That throughput also shares the same bandwidth
with Disk IO. So if you plan on having a large amount of Disk IO throughput, it will
also compete with any network egress or ingress throughput. So remember that,
especially if you will be increasing the number of drives attached to a virtual machine.
Proprietary + Confidential
There are many differences between a physical hard disk in a computer and a
persistent disk, which is essentially a virtual networked device.
First of all, if you remember with normal computer hardware disks, you have to
partition them. Essentially, you have a drive and you’re carving up a section for the
operating system to get its own capacity. If you want to grow it, you have to
repartition, and if you want to make changes you might even have to reformat. If you
want redundancy, you might create a redundant disk array, and if you want
encryption, you need to encrypt files before writing them to the disk.
With cloud persistent disks, things are very different because all that management is
handled for you on the backend. You can simply grow disks and resize the file system
because disks are virtual networked devices. Redundancy and snapshot services are
built in and disks are automatically encrypted. You can even use your own keys, and
that will ensure that no party can get to the data except you.
Proprietary + Confidential
Common Compute
Engine Actions
05
Now that we have covered all the different compute, image, and disk options, let’s
look at some common actions that you can perform with Compute Engine.
Proprietary + Confidential
startup-script-url=URL shutdown-script-url=URL
Every VM instance stores its metadata on a metadata server. The metadata server is
particularly useful in combination with startup and shutdown scripts, because you can
use the metadata server to programmatically get unique information about an
instance, without additional authorization. For example, you can write a startup script
that gets the metadata key/value pair for an instance's external IP address and use
that IP address in your script to set up a database. Because the default metadata
keys are the same on every instance, you can reuse your script without having to
update it for each instance. This helps you create less brittle code for your
applications.
Storing and retrieving instance metadata is a very common Compute Engine action.
We recommend storing the startup and shutdown scripts in Cloud Storage, as you will
explore in the upcoming lab of this module.
Proprietary + Confidential
Zone 1 Zone 2
Another common action is to move an instance to a new zone. For example, you
might do so for geographical reasons or because a zone is being deprecated.
If you move your instance within the same region, you can automate the move by
using the gcloud compute instances move command. To move your VM, you must
shut down the VM, move it to the destination zone or region, and then restart it. After
you move your VM, update any references that you have to the original resource,
such as any target VMs or target pools that point to the earlier VM. During the move,
some server-generated properties of your VM and disks change.
Snapshot Service
Compute Engine
Cloud
Storage
root data
Snapshots have many use cases. For example, they can be used to backup critical
data into a durable storage solution to meet application, availability, and recovery
requirements. These snapshots are stored in Cloud Storage, which is covered later.
Proprietary + Confidential
Snapshot Service
Snapshots can also be used to migrate data between zones. We just discussed this
when going over the manual process of moving an instance between two regions, but
this can also be used to simply transfer data from one zone to another. For example,
you might want to minimize latency by migrating data to a drive that can be locally
attached in the zone where it is used.
Proprietary + Confidential
Compute Engine
Snapshot Service
Which brings me to another snapshot use case of transferring data to a different disk
type. For example, if you want to improve disk performance, you could use a
snapshot to transfer data from a standard HDD persistent disk to a SSD persistent
disk.
Proprietary + Confidential
Now that I’ve covered some of the snapshot use cases, let’s explore the concept of a
disk snapshot.
First of all, this slide is titled persistent disk snapshots because snapshots are
available only to persistent disks and not to local SSDs.
Snapshots are different from public images and custom images, which are used
primarily to create instances or configure instance templates, in that snapshots are
useful for periodic backup of the data on your persistent disks.
Snapshots are incremental and automatically compressed, so you can create regular
snapshots on a persistent disk faster and at a much lower cost than if you regularly
created a full image of the disk.
Compute Engine
PD SSD
root
Another common Compute Engine action is to resize your persistent disk. The added
benefit of increasing storage capacity is to improve I/O performance. This can be
achieved while the disk is attached to a running VM without having to create a
snapshot.
Now, while you can grow disks in size, you can never shrink them, so keep this in
mind.
Proprietary + Confidential
Lab Intro
Working with Virtual Machines
Lab objectives
In this lab, you'll be setting up an application server. Now this example happens to be
a gaming application, but it applies to many other use cases. You will configure the
VM and also add capacity for a production gaming system, and you will build the
infrastructure that you need for production activities. This includes backups and
graceful shutdown and restart services.
Proprietary + Confidential
Quiz
Proprietary + Confidential
Question #1
Question
Question #1
Answer
Explanation:
VMs in Compute Engine are a collection of networked services. This includes disks
(persistent disks) which are network-attached. In some cases, the Google Cloud VM
behaves unlike hardware or other kinds of virtual machines; for example, when a
multi-tenant virtual CPU "bursts," using excess capacity beyond the VM spec.
Proprietary + Confidential
Question #2
Question
Question #2
Answer
Explanation:
Sustained use discounts are automatic discounts that you get for running specific
Compute Engine resources (vCPUs, memory, GPU devices) for a significant portion
of the billing month. To take advantage of the full 30% discount, create your VM
instances on the first day of the month, because discounts reset at the beginning of
each month.
Proprietary + Confidential
Question #3
Question
Question #3
Answer
Explanation:
Persistent Disks are not physical disks, they are a virtual-networked service. Each
persistent disk remains encrypted either with system-defined keys or with
customer-supplied keys.
Proprietary + Confidential
In this module, we covered the different compute, image, and disk options within
Compute Engine, along with some common actions. The two labs provided you with
real world applications of most of the topics covered in this course.
Remember that there are many compute options to choose from. If a predefined
machine type does not meet your needs, you can customize your own VM and you
can even create a sole-tenant node. You can also install different public and custom
images on the boot disks of your instances and you can attach more disks if needed.