Google Cloud Platform: Move VM Instance to different region/zone

M. Ilham Margatama
4 min readMar 7, 2023

--

As a full-stack developer, I have always been interested in exploring different cloud platforms and learning new things. Recently, I have been using Google Cloud Platform (GCP) extensively, and I am impressed with its features and flexibility.

One of the challenges I faced while using GCP was moving a virtual machine (VM) instance to a different zone or region. This can be a daunting task, especially for someone new to GCP. However, the process can be simple with some knowledge and guidance.

In this article, I will walk you through the steps involved in moving a VM instance to a different zone or region on GCP with zero downtime of course.

Step 1: Create a machine image

Before moving a VM instance to a different zone or region, you need to create a machine image. This is done to ensure that you can recreate the instance in the new zone or region without losing any data or configuration settings. To create a machine image, navigate to the “Machine images” section of the GCP console, and click the “Create Machine Image” button. You will be prompted to fill out some form like the image below then click “Create”.

Step 2: Create a new instance from the machine image

Once the machine image is created, you can use it to create a new instance in the desired zone or region. You can do this by navigating to the “Machine images” section of the GCP console, selecting the image you just created, and clicking the “Create Instance” button. You will be prompted to configure the instance, including selecting the zone or region where you want to create the instance.

Step 3: Verify the new VM instance

After the new instance is created, you should verify that it is working correctly. You can do this by logging in to the instance and checking that all the necessary services and applications are running.

Once you have verified that the new VM instance is working correctly, you should clean up the resources that are no longer needed. This is an important step to ensure that you are not incurring any unnecessary costs on your GCP account.

Step 4: Modify the DNS Record

After you have moved your VM instance to a different zone or region on the Google Cloud Platform (GCP), you may need to modify the DNS record to ensure that your website or application remains accessible. Here are the steps to modify the DNS record:

  1. Log in to your DNS provider: The first step is to log in to your DNS provider. This could be a domain registrar, a DNS hosting provider, or a third-party service.
  2. Locate the DNS record: Once you are logged in, locate the DNS record that corresponds to your website or application. This will typically be an “A” record or a “CNAME” record.
  3. Edit the DNS record: Edit the DNS record to point to the new IP address of your VM instance in the new zone or region. You can find the IP address of your new instance in the GCP console under the “VM instances” section.
  4. Save the changes: Once you have edited the DNS record, save the changes. It may take some time for the changes to propagate across the internet, so be patient.

Step 5: Clean up the resources

To clean up the resources, you can follow these steps:

  1. Delete the original VM instance: You can do this by selecting the instance from the “VM instances” section of the GCP console and clicking the “Delete” button. This will delete the original VM instance, including its boot disk.
  2. Delete the snapshot or machine image: If you used the snapshot method to move the VM instance, you can delete the snapshot by selecting it from the “Snapshots” section of the GCP console and clicking the “Delete” button. If you used the machine image method, you can delete the image by selecting it from the “Machine images” section of the GCP console and clicking the “Delete” button.
  3. Delete the disk: If you used the snapshot method to move the VM instance, you can also delete the disk that was created from the snapshot by selecting it from the “Disks” section of the GCP console and clicking the “Delete” button.

By following these steps, you can ensure that you are only paying for the resources that you need and not incurring any unnecessary costs on your GCP account.

Moving a VM instance to a different zone or region on GCP can be done using either the snapshot or machine image method. Both methods are viable options, and you can choose the one that best suits your needs. With GCP’s flexibility and scalability, you can move your resources to the zones or regions that make the most sense for your business needs and clean up the resources that are no longer needed to ensure cost-effectiveness.

--

--

M. Ilham Margatama
M. Ilham Margatama

Written by M. Ilham Margatama

Software Engineer | Documenting my experiences

No responses yet