OpenStack Affinity Groups

What are Affinity Groups


Affinity Groups in OpenStack allow you to make sure that instances are on the same hypervisor node or to make sure that instances are never on the same hypervisor node. In specific cases it's usefull to have instances close to one another and in other cases you want them to be on different hypervisors.

If all instances in an affinity group should be spawned on the same hypervisor we call that an Affinity Group. If all instances in an affinity group should never be on a hypervisor with other instances from that group, we call that an Anti-Affinity group.

With affinity groups you can make sure that two loadbalancers are not on the same hypervsor. If one of the hypervisors has an issue, your changes of staying up are higher because the other loadbalancer is on another hypervisor. This is an Anti-Affinity group. The same case can be made for two MySQL servers that are master-master replidating to each other.

The other case can be for a webserver and a caching server, you might want those on the same hypervisor, which is an Affinity group.

An affinity group can only be set at first boot of the instance. When creating a new instance in OpenStack, the cluster decides where this instance should be placed. The scheduler takes a few parameters in account, like CPU, RAM, networking, storage etc. This is done via the message queue. The scheduler asks all hypervisors if they can place the requested instance specifications. They all reply, either positive or negative to that question. The scheduler then chooses a hypervisor from the positive hypervisor list to place the instance.

When an affinity group is added to the creation request, the scheduler takes this into account when asking the hypervisors if they can place the instance. It therefore could be that the instance cannot be created.

When an Anti-Affinity group is requested and there are only hypervisors available where an instance in that affinity-group already runs, the request fails with the error 'No valid host found'. This is because the scheduler cannot find a host which has the required specifications.

Affinity Groups via Skyline


In Skyline the option to create Affinity groups is not visible by default. To add this to the menu, open the 'Settings' menu via the top-right 'Cog' icon. Check the 'Enable anti-affinity settngs'.

In the left-menu there will be a new item under 'Advanced', named 'Affinity Groups'.

 

With the 'New Group' button a new affinity group can be created. This can be both an affinity as well as an anti-affinity group. In the dialog the different group types are explaind as well.

After creating groups the New Server dialog has a new option to set the specific affinity group:

 

It is only possible to add a server to an affinity group during the creation. Placing a server in a group later on is not possible.

When an affinity group is removed, the servers in that group are not removed automatically. Only the policy is removed, therefore it can be that new instances, or migrations, place instances on the same or different hypervisors. That is because the group is not honoured anymore since it's deleted.

Affinity Groups via the Command Line


The OpenStack command line clients need to be installed. See the following page:  http://docs.openstack.org/cli-reference/common/cli_install_openstack_command_line_clients.html

The command 'nova server-group-create' creates an affinity group:

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

'$group-name' is a name you choose, '$policy' is either 'affinity' or 'anti-affinity', the policy you want.

All the groups can be viewed with the command 'nova server-group-list':

$ nova server-group-list
+--------------------+--------+--------------------+------------+-----------+
| Id                          | Name   | Policies                 | Members  | Metadata |
+-------------------+--------+---------------------+------------+-----------+
| 415eea2[...]8fc8 | Anti      | [u'anti-affinity']     | []                | {}             |
+-------------------+--------+---------------------+------------+-----------+

A group can be removed with the command:

nova server-group-delete $group-uuid

At instance creation time an extra parameter can be given to set an affinity group (nova boot):

--hint group=$affinity-group-uuid

For example:

nova boot --image "CloudVPS 1 Ubuntu 14.04"  \
    --hint group=415eea22-4e37-44e0-a4c9-59c395688fc8 \
    --key-name $ssh_key \
    --flavor "Standard 1" \
    "Example instance 1"


Later on you can check if the affinity group is actually in effect. The 'nova show' command shows the 'hostID' value. In an Affinity group this should be the same for all servers in that group, in an Anti-Affinity group this should be different for all servers in that group.

It is only possible to add a server to an affinity group during the creation. Placing a server in a group later on is not possible.

When an affinity group is removed, the servers in that group are not removed automatically. Only the policy is removed, therefore it can be that new instances, or migrations, place instances on the same or different hypervisors. That is because the group is not honoured anymore since it's deleted.

Helpcenter

General FAQ

Show all FAQs

OpenStack FAQ

Show all FAQs

Knowledgebase

Show all FAQs