VK Cloud logo

Migrating a VM to another availability zone

All virtual machines that use the availability zone GZ1 must be migrated to another availability zone (for example, PA2), since GZ1 is being decommissioned.

This guide will help you migrate your virtual machines to a new availability zone. You will perform the following steps:

  1. Create disk snapshots of the virtual machine you want to migrate.
  2. Create disks from the snapshots in the new availability zone.
  3. Create a virtual machine from the disk in the new availability zone.
  4. Start the VM and attach additional disks to it, if any.
  5. (Optional) Synchronize the Terraform State with the actual infrastructure.

Preparatory steps

  1. Determine which virtual machine needs to be migrated to the new availability zone.
  2. Stop this virtual machine to ensure data integrity in its disk snapshots.
  3. If a Floating IP address is attached to the virtual machine, detach it.

1. Create VM disk snapshots

  1. Create snapshots of the VM boot disk.
  2. (Optional) Create snapshots of the additional VM disks, if any.

2. Create new disks from snapshots

  1. From the VM boot disk snapshot, create a boot disk in the new availability zone.
  2. (Optional) From the additional VM disk snapshots, create disks in the new availability zone.

3. Create a VM from the new disk

  1. Go to the Cloud ComputingDisks section.

  2. In the list of disks, click  for the new boot disk and select the Create VM instance option.

  3. Set the VM parameters in the Configuration block:

    • Virtual machine category: select a category of predefined VM configurations.

    • Virtual machine type: select a predefined VM configuration.

    • Availability zone: the value corresponds to the availability zone of the disk from which the VM is created.

  4. Fill in the General information block:

    • Virtual machine name: use only Latin letters, numbers, or special characters -, _, and ..

    • Tags: if necessary, specify a tag for the VM or create a new one.

    • Configure scripts on VM launch: enable the option to add a bash script or a cloud-config script that will be executed on the first VM launch.

  5. Configure the network settings in the Network and firewall settings block.

    • Network: select an existing network or create a new one. When creating a new network, additional fields will appear:

      • SDN: select the virtual network management system. For new accounts, the option is unavailable and Sprut is used by default.

      • Subnet address: specify the CIDR in the format XXX.XXX.XXX.XXX/XX, for example, 10.0.0.0/24.

    • Use configuration drive: enable the option if you need to configure the network on the virtual machine when there is no DHCP server in the network. The option is enabled automatically if an external network or a network with disabled DHCP is selected.

    • DNS name: specify the domain name for private DNS. It can be used to access instances within the internal network.

    • Virtual machine key: select a key for SSH connection or create a new one.

      When you select Create new key, after the VM is created, the private key file *.pem will be automatically downloaded. Save it, it will be needed later for SSH connection to the server.

      The public part of the key will be automatically added to the server.

    • Firewall settings: select the required security groups.

      To connect via SSH, add the ssh or ssh+www group. For more information about configuring network access rules, see the Security groups section.

    • (Optional) Assign external IP: enable the option to assign a new or existing Floating IP address to the VM. The option is available if internet access is enabled for the network.

    • (Optional) Bind domain to external IP: enable the option and specify a domain to bind the FQDN to the external IP address. An A record for the selected IP address will be added to the DNS zone. The option is available if the Assign external IP option is enabled.

    • Enable monitoring: enable to install an agent for sending metrics to the monitoring service.

  6. Specify the required parameters in the Backup block.

    By default, backup is enabled with recommended settings, but you can change them:

    • Plan name: specify an arbitrary name for the backup plan.

    • Enable full backup retention strategy (GFS): enable to automatically delete backups after the retention period expires.

      • Keep weekly full backups: specify how many weeks to keep the backup.
      • Keep monthly full backups: specify how many months to keep the backup.
      • Keep yearly full backups: specify how many years to keep the backup.
    • Enable incremental backups: enable the option to create a full backup once a week. On all other days of the week, incremental backups will be created.

    • Backup schedule: select the days of the week and the backup start time. The time is specified in the GMT+03:00 time zone.

    • Enable immutable backups: enable the option to protect backups from deletion using object lock. Two types of lock are available:

      • Temporary protection: protects copies from deletion and overwriting for a specified number of days. Has two modes:

        • Compliance: strict lock. Cannot be removed or changed during the specified retention period.
        • Governance: flexible lock that can be removed by the project administrator.
      • Indefinite protection: protects the copy from deletion until the lock is removed.

  7. Click the Create button.

  8. Wait for the VM to be created. This process may take some time. When the creation is completed, the page with the VM characteristics and connection instructions will open.

4. Start the VM and attach additional disks

  1. Start the new virtual machine.
  2. (Optional) Attach additional disks to the virtual machine.

5. (Optional) Synchronize Terraform State

If you manage VK Cloud resources via Terraform, after migrating the VM, synchronize the Terraform State with the actual infrastructure:

  1. Bind the new VM to the vkcs_compute_instance resource:

    terraform import vkcs_compute_instance.<RESOURCE_NAME> <VM_ID>
  2. Bind the new disks to the vkcs_blockstorage_volume resource:

    terraform import vkcs_blockstorage_volume.<RESOURCE_NAME> <DISK_ID>
  3. Bind the Floating IP address to the vkcs_networking_floatingip resource:

    terraform import vkcs_networking_floatingip.<RESOURCE_NAME> <FLOATING-IP_ID>
  4. Bind the disk attachment to the vkcs_compute_volume_attach resource:

    terraform import vkcs_compute_volume_attach.<RESOURCE_NAME> <VM_ID>/<DISK_ID>
  5. Bind the Floating IP address association to the vkcs_networking_floatingip_associate resource:

    terraform import vkcs_networking_floatingip_associate.<RESOURCE_NAME> <FLOATING-IP_ID>
  6. View the parameters of the new resources:

    terraform state show <RESOURCE>.<RESOURCE_NAME>
  7. Add the obtained fields to the Terraform configuration file.

  8. Generate a changes file and make sure it is empty:

    terraform plan

Delete unused resources

A running virtual machine, its disks, and their snapshots are billed. If you no longer need the source VM, delete it. Its disks and their snapshots will be deleted along with it.