How to migrate OpenStack instances from one compute host to another

You can move instances from one compute host to another in OpenStack. This is a common task when a compute node has a problem or must be maintained. The openstack server migration command is used to migrate OpenStack instances from one computing host to another.

The Nova scheduler will automatically select the target computing host based on its settings. The migration process does not assume that the instance has shared storage available on the target host. For users using SSH tunnels, make sure that SSH key authentication is configured for each node so that the Compute service can use SSH to move disks to other nodes.

You can do live or non-live migration. In a non-live migration, the instance is shut down, then moved to another hypervisor and restarted. The instance recognizes that it has restarted and the application running on the instance is destroyed.

With live migration, the instance will remain running during the entire migration process. They can be further categorized by the way they treat instance storage:

  • Live migration based on shared storage. The instance has a temporary disk
    On shared storage between source and target
    Host.
  • Prevent live migrationOr just prevent migration. The instance has
    Temporary disks not shared between source and destination
    Host. Block migration is not compatible with read-only devices, such as
    CD-ROM and configuration drive (config_drive).
  • Volume-supported live migration. Instances use volumes instead of volumes
    Temporary disk.

Step 1: Determine which VMs to migrate

Identify the VMs to be migrated. To list the VMs running on OpenStack, run:

$ openstack server list
+--------------------------------------+-------------+--------+----------------------+----------+----------+
| ID                                   | Name        | Status | Networks             | Image    | Flavor   |
+--------------------------------------+-------------+--------+----------------------+----------+----------+
| 97cb5110-4135-4b59-8049-d19a29f64184 | dbvm01      | ACTIVE | public=172.20.150.70 | rhel-7.6 | m1.small |
| 8ba74eb3-469e-4535-8f30-ed75df303680 | webvm01     | ACTIVE | public=172.20.150.71 | rhel-7.6 | m1.small |
+--------------------------------------+-------------+--------+----------------------+----------+----------+

List the available hypervisors:

$ openstack hypervisor list
+----+----------------------------------+-----------------+---------------+-------+
| ID | Hypervisor Hostname              | Hypervisor Type | Host IP       | State |
+----+----------------------------------+-----------------+---------------+-------+
|  1 | compute-01.osp.example.com       | QEMU            | 172.20.150.10 | up    |
|  4 | compute-02.osp.example.com       | QEMU            | 172.20.150.11 | up    |
+----+----------------------------------+-----------------+---------------+-------+

Get the hypervisor service name:

$ openstack hypervisor show compute-01.osp.example.com

To use OpenStack server migration Command to migrate instances.

$ openstack server migrate  

See the available command options by running:

$ openstack server migrate --help
usage: openstack server migrate [-h] [--live ]
                                [--shared-migration | --block-migration]
                                [--disk-overcommit | --no-disk-overcommit]
                                [--wait]
                                

Migrate server to different host

positional arguments:
                Server (name or ID)

optional arguments:
  -h, --help            show this help message and exit
  --live      Target hostname
  --shared-migration    Perform a shared live migration (default)
  --block-migration     Perform a block live migration
  --disk-overcommit     Allow disk over-commit on the destination host
  --no-disk-overcommit  Do not over-commit disk on the destination host
                        (default)
  --wait                Wait for migrate to complete

Migration example:

$ openstack server migrate dbvm01

To migrate instances and temporary block disks:

openstack server migrate --block-migration  --live compute-02.localdomain  dbvm01

where:

  • compute-02.localdomain Is the host name of the target host
  • dbvm01 Is the name of the instance to be migrated.

Check the instance migration status.

$ openstack server show  dbvm01
+-------------------------------------+----------------------------------------------------------+
| Field                               | Value                                                    |
+-------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                                                   |
| OS-EXT-AZ:availability_zone         | nova                                                     |
| OS-EXT-SRV-ATTR:host                | compute-01.localdomain                                   |
| OS-EXT-SRV-ATTR:hypervisor_hostname | compute-01.osp.example.com                               |
| OS-EXT-SRV-ATTR:instance_name       | instance-000000cf                                        |
| OS-EXT-STS:power_state              | Running                                                  |
| OS-EXT-STS:task_state               | None                                                     |
| OS-EXT-STS:vm_state                 | resized                                                  |
| OS-SRV-USG:launched_at              | 2019-09-18T08:59:09.000000                               |
| OS-SRV-USG:terminated_at            | None                                                     |
| accessIPv4                          |                                                          |
| accessIPv6                          |                                                          |
| addresses                           | public=172.20.150.70                                     |
| config_drive                        |                                                          |
| created                             | 2019-09-18T06:30:41Z                                     |
| flavor                              | m1.medium (2)                                            |
| hostId                              | 0535fdb75a2a49238da76c9b812629b3fc5522251ab791ef03287be9 |
| id                                  | 3a82cf1f-93d0-47c6-931f-9d14472d9e45                     |
| image                               | rhel-7.6 (3dcc3ae0-41ba-4371-afb2-c07c5c1725fb)          |
| key_name                            | None                                                     |
| name                                | dbvm01                                                   |
| progress                            | 0                                                        |
| project_id                          | f278b83dd81848399a66d704aeb507b4                         |
| properties                          |                                                          |
| security_groups                     | name='default'                                           |
| status                              | VERIFY_RESIZE                                            |
| updated                             | 2019-09-18T08:59:10Z                                     |
| user_id                             | 9d6cd9e9847640ffbb2570a39d98aa55                         |
| volumes_attached                    |                                                          |
+-------------------------------------+----------------------------------------------------------+

If the status is VERIFY_RESIZE. Confirm the resize manually.

$ openstack server resize --confirm dbvm01

Status should be set to active.

| status                              | ACTIVE                                                   |

More articles about OpenStack:

How to install OpenStack on CentOS 7 with Packstack

How to resize an OpenStack instance / virtual machine

Best book for learning OpenStack Cloud Platform 2019

How to install and configure OpenStack Client on Linux

How to configure NovaStack to automatically start after restarting NovaStack

How to create OpenStack Cinder volume on CLI and attach to VM instance / server

Sidebar