Affinity & Anti-Affinity

Openstack itself, doesnot provide hypervisor high availability. But still, openstack administrator can create HA cluster for their applications. But for this, administrator should make sure that, the virtual machines he deployed must be in different hypervisor. Normally, nova-scheduler will choose the hypervisor based on the filter applied in the nova.conf file. So, how can an administrator can make sure that his Virtual Machines will be spinning up in different hypervisors ? The feature Affinity is here to help you.

Affinity is supported since Openstack IceHouse Release. You can only add an instance to an affinity group when you create the instance with nova-boot. You can not add existing instances to an affinity group. You can however create an image of an instance and boot a new server from that image, in the new affinity group. You can add the instance to affinity group via CLI only, currently this feature is not available via Horizon.

First of All enable Affinity Filter in the nova.conf (Controller)

scheduler_default_filters = ServerGroupAffinityFilter,ServerGroupAntiAffinityFilter

Create an Affinity Group

nova server-group-create $group-name $policy

nova server-group-create multihost anti-affinity

  • groupe-name is a human readable name for this group
  • policy is either affinity OR anti-affinity

If you want to spin up all your virtual machines in a same Hypervisor, create a group with an affinity policy.

If you want to spin up all your virtual machines in different hypervisor, create a group with an anti-affinity policy. Which means, if you are having 3 Virtual machines in this Group, all will be in different hypervisor nodes. Of course, you should have 3 Hypervisors on-board ūüôā

Check the newly created server group

nova server-group-list

>+————————————–+———–+——————–+———+———-+——–
| Id                                   | Name      | Policies           | Members | Metadata |
+————————————–+———–+——————–+———+———-+———-
| 581b1d6f-f3dd-48f6-8b08-d764b96eba90 | multihost | [u’anti-affinity’] | []¬†¬†¬†¬†¬† | {}¬†¬†¬†¬†¬†¬† |
+————————————–+———–+——————–+———+———-+———-

Adding Virtual Machines to this Group.

 You can add Virtual Machine to this Affinity group, ONLY at the time of booting. You CANNOT add a running Virtual Machine to Affinity Group. If you want to add a running Virtual Machine to affinity, take a snapshot of the Virtual Machine, boot a new instance from this snapshot and add to affinity. You have to pass the following parameter along with the nova-boot command to add to affinity group

–hint group=$affinity-group-uuid

Lets spinnup couple of Virtual Machine to this affinity group.

nova-boot –image m1.small –flavor cirros –nic net-id=73a73784-aa94-49ce-b9d0-e59486e52d02 –hint group=581b1d6f-f3dd-48f6-8b08-d764b96eba90 affinity-test-1
nova-boot –image m1.small –flavor cirros –nic net-id=73a73784-aa94-49ce-b9d0-e59486e52d02 –hint group=581b1d6f-f3dd-48f6-8b08-d764b96eba90 affinity-test-2

by using nova show <instance-id>  you can see that both virtual machines are in different hypervisors.

stacker has written 18 articles

Leave a Reply

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

Humans Only. * Time limit is exhausted. Please reload the CAPTCHA.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>