GCP Compute Engine Instance Lifecycle

10 Apr
  1. Choosing Google Cloud Storage and Data Solutions
  2. Choosing a Google Cloud Deployment Platform
  3. Designing Google Cloud Networks
  4. Designing Reliable Systems
  5. GCP Compute Engine Instance Lifecycle
  6. Disaster Planning and Recovery Strategies
  7. Designing Secured Systems in GCP

VM Lifecycle

A VM instance can transition through many states as part of its lifecycle. This article will give you a brief overview of GCP VM lifecycle stages and explain how it will transition in each stage.

vm-lifecycle-3

  • 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.
  • 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 action 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.
  • The VM may also enter a repairing state. Repairing occurs when the VM encounters an internal error or the underlying machine is unavailable due to maintenance. During this time, the VM is unusable. You are not billed when a VM is in repair.
  • VMs are not covered by the Service level agreement (SLA) while they are in repair. If repair succeeds, the VM returns to one of the above states.
  • Finally, when you suspend the VM, it enters in the suspending state, before being suspended. You can then resume the VM or delete it.

Changing VM State

vm-lifecycle-2

  • 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.)
  • Compute Engine can live migrate your virtual machine to another host due to a maintenance event to prevent your applications from experiencing disruptions.

Availability Policy: Automatic Changes (Scheduling Options)

  • 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.
  • 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.

Charges for stopped (terminated) VMs

  • Attached disks
  • Reserved IP address
  • Memory and CPU resources not changed

Actions supported on a terminated VMs

  • Change the machine type.
  • Migrate the VM instance to another network.
  • Add or remove attached disks; change auto-delete settings.
  • Modify instance tags.
  • Modify custom VM or project-wide metadata.
  • Remove or set a new static IP.
  • Modify VM availability policy.
  • Can’t change the image of a stopped VM.


Leave a Reply

Your email address will not be published. Required fields are marked *