Skip to content

VM Anti-Affinity/Affinity

Multiple instances of the same service or application should be deployed in different availability zones to avoid service disruption in case of an infrastructure outage. When this isn't possible or isn't enough to guarantee your application availability you can use an anti-affinity schedule policy. An affinity policy is also available.

Create a server group

First you need to create a "server group". The server group will contain all the instances to which you want to apply an anti-affinity/affinity policy.

$ openstack server group create --policy <policy> <name>

with

policy : Add a policy (‘affinity’ or ‘anti-affinity’, defaults to ‘affinity’) name : New server group name

If you want all the instances to be hosted on different compute nodes, create a server group with an anti-affinity policy. Otherwise use an affinity policy.

Example:

taylor@laptop:~$ openstack server group create --policy anti-affinity my-policy
+----------+--------------------------------------+
| Field    | Value                                |
+----------+--------------------------------------+
| id       | 202cd313-30c0-4db3-8eab-62cb131fe6ec |
| members  |                                      |
| name     | my-policy                            |
| policies | anti-affinity                        |
+----------+--------------------------------------+

You can see your server groups with:

`$ openstack server group list [--long]

Example:

taylor@laptop:~$ openstack server group list
+--------------------------------------+------------------------+---------------+
| ID                                   | Name                   | Policies      |
+--------------------------------------+------------------------+---------------+
| 79bff002-2228-433c-974c-f5097cc3fa64 | taylor-564-group-nodes | anti-affinity |
| 7be47cd5-685d-47c6-9a47-c7a00d66e6cf | taylor-67-group-nodes  | anti-affinity |
| aebb58c0-caf2-43d2-b874-1c0281575425 | taylor-316-group-nodes | anti-affinity |
| 6f1303d6-e21f-4d8c-a16b-275de0913821 | taylor-883-group-nodes | anti-affinity |
| 202cd313-30c0-4db3-8eab-62cb131fe6ec | my-policy              | anti-affinity |
| 1f50d63c-8460-418d-b532-2e4a3fb43d4d | same-hypervisor        | affinity      |
+--------------------------------------+------------------------+---------------+

Create an instance and apply a schedule policy

To add an instance to a server group, use the following extra option when creating a new instance.

--hint group=<server_group_uuid>

Example:

$ openstack server create --image <image_uuid> --flavor <flavor_name> --hint group=<server_group_uuid> <new_instance_name>

NOTE:

You can only add an instance to a server group at instance creation time. Not afterwards! When using an affinity policy you are limited to the resources available in the compute node where the first instance was scheduled.

Display server group details

$ openstack server group show <uuid>

Delete a server group

$ openstack server group delete <uuid>

Back to top