OpenStack block migration
Block migration, the best compromise possible?
I. Principles
I.1. Live migration
KVM live migration describes a process during which the guest operation system will move to an another hypervisor. What is performed under the hood? Well, the state of the guest operationg system will be migrate more precisely the content of the memory pages and the diverse emulated devices. In the theory it’s simple as that. During the live migration process the guest is not supposed to be affected by the operation, and the client can continue to perform operation while the migration is running. Note that the live migration also exists in offline mode. This operation may require a little downtime for migration the CPU (processes and threads) and the RAM content. It depends on multiple factors like the size of the VM and his load.
With the live migration comes mandatory requirements:
- Distributed filesystem for the VMs storage like NFS or GlusterFS
- Libvirt must have the listen flag enable
- Obsviouly each compute node (hypervisor) must be located in the same network/subnet
- The authenfication must be configured as
none
or via ssh with ssh keys - The mount point used by the DFS must be the same on each location
I.2. Block migration
Block migration has a similar functionnement as above with the live migration dispite of the fact that the disk needs to be migrate which makes the operation longer. But a distributed filesystem is optionnal. The block migration migrate the disk via TCP. This can be summarized as follow:
I don’t have a distributed filesystem at my disposal, and I don’t want one for some understandable reasons like the network latency but I want to be able to perform maintenance operations.
II. State
II.1. Does it work?!
First of all, configure your system for the migration by editing /etc/default/libvirt-bin
and replace libvirtd_opts="-d"
by libvirtd_opts="-d -l"
.
Then edit /etc/libvirt/libvirtd.conf
and change:
listen_tls = 0
listen_tcp = 1
auth_tcp = "none"
As I said above, you don’t need a DFS, simply configure libvirt properly. I experimented the KVM block migration and I detected some problems. Basically you can’t successfully migrate a instance with this kind of flavor:
$ nova flavor-list |
Both “Disk” and “Ephemeral” make the migration fail, the issue has been reported on the Openstack launchpad and the commit for Folsom which is perfectly functionnal. You need to edit the line 2168 of /usr/lib/python2.7/dist-packages/nova/virt/libvirt/connection.py
If you don’t want to modify the Python code and wait for Folsom here’s the workaround.
You need to create a special flavor like so:
$ sudo nova-manage instance_type create --name medium --memory 4096 --cpu 4 --root_gb 0 --ephemeral_gb 0 --swap 0 --flavor 13 |
You will have something like:
$ nova flavor-list |
If you use the ubuntu cloud repository, you will have a virtual size of 2G by default for your disk image, which will represent the size of the root filesystem while your instance will be running. The virtual size can be easily showed via:
$ sudo qemu-img info precise-server-cloudimg-amd64.img |
Inside the VM:
ubuntu@med:~$ df -h | grep /dev/ |
The virtual size can be easily increase like so:
$ sudo qemu-img resize precise-server-cloudimg-amd64.img 15G |
The result is immediate:
$ sudo qemu-img info precise-server-cloudimg-amd64.img |
Inside the VM:
ubuntu@med:~$ df -h | grep /dev/ |
This operation can be performed while the instance is running, simply reboot it and you will see that the local fs has grow. :)
II.2. Example of block migration
Pick up an instance:
$ nova show med |
Run the block migration:
$ nova live-migration --block_migrate med server-01 |
Check the state:
$ nova list | grep med |
Initiates connections:
tcp 0 0 172.17.1.3:49152 172.17.1.2:57822 ESTABLISHED 30184/kvm
tcp 0 0 172.17.1.3:16509 172.17.1.2:48448 ESTABLISHED 32365/libvirtd
During the block migration I noticed a CPU hit between 10% and 15% on each compute node. CPUs are Intel(R) Xeon(R) CPU L5335 @ 2.00GHz respectively on both compute nodes.
III. Tips
Before performing the block_migration, nova checks both free_ram_mb
and disk_available_least
values in the nova database.
free_ram_mb
is the amont of RAM available on the destination compute nodedisk_available_least
is a value calculated from thelocal_gb
and the virtual size of the image.
Example of a compute node record:
*************************** 2. row *************************** |
If you want to bypass the virtual size which is not erroned but simply not useful for everyone you can use the --disk_over_commit
which will use the real disk_size
of the image.
You can enable options via the flag in nova.conf:
block_migration_flag=VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_NON_SHARED_INC
At the end, the block migration seems a pretty good option instead of using the classic live migration even if it’s longer. But only using the network to migrate your VMs can be priceless and if it’s only for maintenance purpose this is not so often. You don’t always want a to use a DFS because it requires a lot of bandwith and store virtual instance via dedicated disks on each compute node is faster. In an order hand, you also want to perform maintenace on compute node like kernel or security upgrades and VMs downtime is not acceptable. In this case the block migrate looks like the ideal solution! Just keep in mind that you will need a fast private network between all your compute node (hypervisors) in order to make the block migration as fast as possible, who says 10G?
Comments