Chapter 9. Compute Engine:
Virtual Machines
What are virtual machines (VMs)?
Using persistent storage with virtual machines
How auto-scaling works
Spreading traffic across multiple machines with a load balancer
Compute Engine’s pricing structure
Virtual machines are chopped-up pieces of a single physical system that are
shared between several people.
Decouple the virtual machine from the physical machine,
Without any downtime or significant changes in performance.
Automatic scaling, hosting provider can automatically provision more or
fewer virtual machines based on incoming traffic or CPU usage.
All you need is a simple VM that you can SSH into and run a server or two.
Customize your virtual machines or balance server requests across a set of many
machines.
Disk storage makes up the base of your instance.
9.2. Block storage with Persistent Disks
A persistent disk in varying sizes (for example, 100 GB or 1 TB)
Storage service that looked and acted like a regular disk but was replicated and
highly available.
9.2.1. Disks as resources
Create and manage disks separately from VMs.
At any time, a persistent disk can be in one of three states:
Unattached—You’ve created the disk, but it’s not mounted on any VMs.
Attached in read-only mode—The VM can only read from the disk.
Attached in read-write mode—The VM can both read and write to the disk.
Default value when creating a disk in GCE is the unattached state.
Attach disks to a VM in two different modes (read-only and read-write)
9.2.2. Attaching and detaching disks
Compute Engine section and choose Disks in the left-side navigation.
To be attached to an instance, a disk must live in the same zone as that instance.
SSDs have much faster random operations, and traditional drives are adequate
for large sequential operations.
Input/output operations per second is an input/output performance measurement used to characterize computer storage.
Disk size and performance are directly related, such that larger disks can handle
more input/output operations per second (IOPS).
Disk is in the attached–read-only state, which means that it can continue
to be attached to other VMs,
9.2.3. Using your disks
Plugging your external hard drive into the VM.
Mount the disk device and then format it.
Mount command as well as by calling the mkfs.ext4 shortcut to format the disk with the ext4 file system..
9.2.4. Resizing disks
Resize a disk for a variety of reasons. Running out of space.
Size of the disk directly correlates to its speed: the bigger the disk, the faster it is.
You can always make a disk larger by increasing the size, but you can’t make
a disk smaller.
9.2.5. Snapshots
Freeze your computer at a point in time and be able to jump right to that checkpoint?
Act as those checkpoints for the data on your disk,
Allowing you to jump around in time by restoring a snapshot to a disk.
Snapshots use differential storage storing only what’s changed from one snapshot
to the next. create a snapshot, change one block of data second snapshot will only
store the difference.
Once you have a snapshot of a disk, you can create a new disk based on the content
from the snapshot.
Snapshot consistency
If you’re writing to your disk, and you take a snapshot in between two important
disk operations?
Snapshots can protect your data over time.
9.2.6. Images
Images are similar to snapshots in that both can be used as the source of content
when you create a new disk.
Images are meant as starting templates for your disk.
Snapshots are meant as a form of backup to pinpoint your disk’s content
at a particular time.
9.2.7. Performance
Create a disk that’s larger than you need for storage if you want to meet performance
requirements.
Several classes of persistent disk are available.
SSD (Solid State Drive) is a type of nonvolatile storage media that stores persistent data on
solid-state flash memory.
Unlike a hard disk drive (HDD), an SSD has no moving parts to break or spin up or down.
A traditional HDD consists of a spinning disk with a read/write head on a
mechanical arm called an actuator.
Local SSD disks provide the most performance.
Standard disks are great if you need lots of space and don’t need super-high
performance.
9.2.8. Encryption
Storing data in the cloud brings different risks than storing data locally on your
home computer.
Unauthorized access to your data .
Google encrypts the data stored on your disks.
Copy the bytes directly, they’d be useless without the encryption keys.
Google comes up with its own random encryption key for your disk and stores
that in a secure place with access logged.
You can elect to keep these keys for yourself and give Google the key only
when you need to decrypt the disk.
Wrapping a key involves encrypting it with a public encryption key so that it can only be
decrypted by the corresponding private key.
9.3. Instance groups and dynamic resources
Autoscaling, ability to expand or contract the number of VMs running to handle
requests based on how much traffic is being sent to them.
Experiences a request load that varies over the course of the day.
Start of the day, the system sees around 1,000 queries every second, growing
quickly until about noon, and it only slows as it approaches 3,000 queries per
second.
GCE’s setup can use the concept of autoscaling.
Monitor the overall CPU usage of the currently running instances and decide
whether to turn on more.
9.3.2. Rolling updates
New software package that you want to deploy across a bunch of machines.
Upgrade, say, half of the instances, while leaving the other half alone in case
the newest
Instance groups can do this using something called rolling updates.
Creating a new instance template that turns on a simple Apache web server.
9.3.3. Autoscaling
Look at various measures of health to decide when to replace an instance or
grow and shrink the cluster as a whole.
If a single instance becomes unresponsive, the instance group can mark it as dead
and replace it with a new one.
If instances become overloaded, the instance group can increase the size of the pool
to accommodate the unexpected load on the system.
CPU limit for a set amount of time, the instance
group can retire some of the instances to remove unnecessary cost.
9.7. Understanding pricing
You need to consider three factors for pricing with GCE:
1. Computing capacity using CPUs and memory
2. Storage using persistent disks
3. Network traffic leaving Google Cloud
9.7.1. Computing capacity
The most common way of using GCE is with a predefined instance type,
such as n1-standard-1
9.7.3. Preemptible prices
Preemptible VMs have special price reductions in exchange for the restrictions on
these instances.
Around 80% cheaper than the standard hourly prices. If you’re cost-conscious,
9.7.4. Storage
Each of these classes has a different cost
Table 9.5. Data storage rates based on location and disk type
9.7.5. Network traffic
Most VMs you create will be sending data back to customers
Look at both where the traffic comes from and where it’s going.
Table 9.6. Network prices per GB of data for most locations
9.8.1. Flexibility
GCE is that it’s as flexible as you can get in a cloud computing environment.
You found that you needed some special load balancing feature, you could
9.8.3. Performance
GCE scores particularly well.
Being as close to bare metal as you’ll get in Google Cloud means that you have the
fewest possible abstraction layers between your code and the physical CPU doing the
work
9.8.4. Cost
GCE is relatively low on the cost scale, given that you’re only paying for raw virtual
machines and disks.
Summary
Virtual machines are virtualized computing resources, a bit like slices of a physical
computer somewhere.
GCE offers virtual machines for rent priced by the hour as well as persistent replicated
disks to store data for the machines.
Automatically turn machines on and off based on a template, allowing you to
automatically scale your system up and down.
VMs can turn on and off quickly and easily, preemptible VMs can reduce costs
significantly.
Create a virtual machine
Enable Compute Engine API
Create an Instance
Chose a Name and a Zone
Regions and zones
Compute Engine resources are hosted in multiple locations worldwide.
These locations are composed of regions and zones. A region is a specific
geographical location where you can host your resources.
Resources that live in a zone, such as virtual machine instances or zonal persistent disks, are referred to as zonal resources. Other resources, like static external IP addresses, are regional. Regional resources can be used by any resource in that region, regardless
of zone, while zonal resources can only be used by other resources in the same
zone.
Choose your CPU
Rightsizing is the process of optimizing the resources allocated to an application or
workload in order to achieve the best balance between performance and cost.
It involves adjusting the computing resources, such as CPU, memory, and storage,
to match the needs of your workloads while minimizing expenses.
Choose your Operating System and disk size
No comments:
Post a Comment