Red Hat Training

A Red Hat training course is available for Red Hat Virtualization

6.11. Affinity Groups

Virtual machine affinity allows you to define sets of rules that specify whether certain virtual machines run together on the same host or on hosts in a group, or run separately on different hosts. This allows you to create advanced workload scenarios for addressing challenges such as strict licensing requirements and workloads demanding high availability, and failover and failback for disaster recovery.

Virtual machine affinity is applied to virtual machines by adding virtual machines to one or more affinity groups. An affinity group is a group of two or more virtual machines for which a set of identical parameters and conditions apply. These parameters include positive (run together) affinity that ensures the virtual machines in an affinity group run on the same host or hosts in a group, and negative (run independently) affinity that ensures the virtual machines in an affinity group run on different hosts.

Important

In order for affinity groups to take effect, a scheduling policy must be applied to the clusters in which the affinity groups are applied. This scheduling policy must have the VmAffinityGroups and VmToHostsAffinityGroups filter or weight modules enabled for affinity groups. For affinity labels, the scheduling policy must have the Label filter module enabled.

See Scheduling Policies in the Red Hat Virtualization Administration Guide for details.

A further set of conditions can then be applied to these parameters in the associated scheduling policy.

  • Hard enforcement - ensures that virtual machines in the affinity group run on a specified host or hosts in a group regardless of external conditions. The filter modules in the scheduling policy implement hard enforcement.
  • Soft enforcement - indicates a preference for virtual machines in an affinity group to run on the specified host or hosts in a group when possible. The the weights modules in the scheduling policy implement soft enforcement.

The combination of an affinity group, its parameters, and its conditions is known as an affinity policy. Affinity policies are applied to running virtual machines immediately, without having to restart.

Note

Affinity groups are applied to virtual machines on the cluster level. When a virtual machine is moved from one cluster to another, that virtual machine is removed from all affinity groups in the source cluster.

6.11.1. Creating an Affinity Group

You can create new affinity groups in the Administration Portal.

Creating Affinity Groups

  1. Click ComputeVirtual Machines and select a virtual machine.
  2. Click the virtual machine’s name to go to the details view.
  3. Click the Affinity Groups tab.
  4. Click New.
  5. Enter a Name and Description for the affinity group.
  6. From the VM Affinity Rule drop-down, select Positive to apply positive affinity or Negative to apply negative affinity. Select Disable to disable the affinity rule.
  7. Select the Enforcing check box to apply hard enforcement, or ensure this check box is cleared to apply soft enforcement.
  8. Use the drop-down list to select the virtual machines to be added to the affinity group. Use the + and - buttons to add or remove additional virtual machines.
  9. Click OK.

6.11.2. Editing an Affinity Group

Editing Affinity Groups

  1. Click ComputeVirtual Machines and select a virtual machine.
  2. Click the virtual machine’s name to go to the details view.
  3. Click the Affinity Groups tab.
  4. Click Edit.
  5. Change the VM Affinity Rule drop-down and Enforcing check box to the preferred values and use the + and - buttons to add or remove virtual machines to or from the affinity group.
  6. Click OK.

6.11.3. Removing an Affinity Group

Removing Affinity Groups

  1. Click ComputeVirtual Machines and select a virtual machine.
  2. Click the virtual machine’s name to go to the details view.
  3. Click the Affinity Groups tab.
  4. Click Remove.
  5. Click OK.

The affinity policy that applied to the virtual machines that were members of that affinity group no longer applies.