Create (anti-)affinity group

In the planning of VPC topology, an important step is to decide which servers are preferably located on the same hypervisor (compute) host to keep communication overhead to a minimum, and which servers should be on separate hosts for maximum availability.

The strategy of running servers on a single host or on separate hosts as far as possible is implemented as a server group policy, and the two scenarios are enforced by applying affinity rules and anti-affinity rules, respectively.

To apply such a policy, it is first necessary to create a server group with (anti-)affinity policy to which instances are assigned at the time they are created. It is not possible to assign a server to a server group after its creation.

It is, however, possible to create an image of an instance and boot a new server from that image in the new affinity group.

From OpenStack CLI, create a server group by the command

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

where <policy> is affinity or anti-affinity and <name> is the name of the server group. The command produces an output similar to the list shown in Figure 1.

Just like with other resources, a list of existing server groups is produced by

openstack server group list

and the details of a specific group by

openstack server group show <server-group>

where <server-group> is its name or UUID. It is deleted by

openstack server group delete <server-group>

To have servers running on the same hypervisor host, instances should be assigned to a group with an affinity policy. To have them on different hosts, they should be assigned to a group with an anti-affinity policy. The anti-affinity group ensures that no server in the group will be running on the same compute node as any other server in the group.

At the time of creation of an instance, it is assigned to an existing affinity group by using the additional argument --hint group=<server-group-id>. When inspecting the server group, the members are listed under members as shown in Figure 2.

The system limitations (quota) for the number of affinity groups per tenant and the the number of servers per affinity group are listed by

openstack quota show -c server-groups -c server-group-members

Currently, the default quotas are 10 server groups with 10 servers per group.