Learn how to configure and validate Affinity and Anti-Affinity policies in Nutanix AHV—plus tips from eGroup on simplifying policy management at scale.
This article originally appeared on Mike Dent’s blog. It has been republished with the author’s credit and consent.
Overview
Following up on Part 1 where I covered the benefits (and some pitfalls) of Affinity and Anti-Affinity policies with AHV, this post will cover the configuration and validation of these policies.
Affinity and Anti-Affinity policies are crucial for ensuring application availability, performance, and compliance by controlling the placement of virtual machines on specific hosts, or preventing them from residing on the same host.
Lab Environment
My lab environment consists of a 4-node cluster, with just a handful of workloads. I have two Domain Controllers (MainDC01
and MainDC02
), as well as two SQL Server nodes in an AAG (MAINSQL01
and MAINSQL02
).
Creating VM-Host Affinity and VM-VM Anti-Affinity Rules
Let’s dive into creating both VM-Host Affinity Policies and VM-VM Anti-Affinity Policies. In a larger environment, you might have more policies based on the workloads, but we’ll keep this post simple to give a good foundation and focus on the following scenarios:
- Affinity: Ensuring a SQL Server only runs on two of the four hosts within the cluster
- Anti-Affinity: Ensuring that Domain Controllers remain on separate hosts
Configuring VM-Host Affinity Policies in Nutanix AHV
Quick Recap
VM-Host Affinity Policies control the relationship between specific VMs and physical hosts. Configuring these policies can be done through one of three methods:
- ACLI
- Prism Element
- Prism Central
A few things to consider:
- VMs with VM-Host affinity policies can only be migrated to the hosts specified in the policy.
- A VM cannot be powered on or migrated to a host that does not conform to the affinity requirements– this policy is enforced mandatorily.
- VMs configured with host affinity settings retain these settings if the VM is migrated to a new cluster.
- The VM-host anti-affinity policy is not supported. You can’t omit a host from where a VM may run.
Setting VM-Host Affinity Policies via ACLI (Command Line)
Using ACLI to set the VM-Host affinity allows flexibility for mass application, though validation is limited via this method.
In my case, I am binding my two SQL servers to hosts 3 and 4:
# Enable VM-Host affinity
acli vm.affinity_set MAINSQL01,MAINSQL02 host_list=172.20.120.23,172.20.120.24
# Unset VM-Host affinity
acli vm.affinity_unset <vm_name> (or can use \* to unset all VMs)
To validate the affinity is set for the VM, you can do this in Prism Element. Here we can see that nodes 3 and 4 were applied.
Configuring VM-Host Affinity in Prism Element (GUI)
So, having gone through the ACLI method, since we have to validate through Prism ElementWithin Prism Element, an administrator can define the VM-Host affinity policies during the VM create or update operation. This is done a per-VM basis.
- Select the VM to enable VM-Host affinity, and click Update.
- Scroll down to the VM Host Affinity section.
- Click the Set Affinity button, and select the desired hosts. In my scenario, I have selected hosts cl2-node3 and cl2-node4 as my desired hosts.
Scaling VM-Host Affinity with Prism Central (GUI)
VM-Host Affinity policies, when created within Prism Central, use a category-based assignment, rather than a per-VM assignment. The image below provides a quick view of the workflow for creating these policies via PC.
- Create a category (or categories) to associate to a VM. In my case, outside of the usual categories that I use, I will create a Category:Value pair of HostWorkloads:SQL, to which I will assign those hosts I want to host SQL workloads.
- After creating my Hosts category, I apply the category value to the hosts by using the Managing Categories function on the Hosts page, applying the specific category to each host.
- Before fully applying the policy, I ensure that my 2 SQL instances have the Microsoft_SQL value applied, which in my case is using the AppType system category.
- Finally, we create a new VM-Host Affinity policy, and indicate that I want any VMs with the Category:Value pair of AppType:Microsoft_SQL to run only on hosts with the Category:Value pair of HostWorkloads:SQL.
Now that the VM and Hosts are associated to this VM-Host Affinity policy, we can validate compliance with the policy, and in my case, we show compliant.
We can also validate the specifics of our worklaods to the hosts they are running on, which in my case was only cl2-node3 and cl2-node4.
Understanding VM-VM Anti-Affinity Policies in Nutanix AHV
Quick Recap: VM-VM Anti-Affinity Policies define the relationship between two or more virtual machines by either keeping them apart. These policies are commonly used to optimize availability, performance isolation, or clustered workload behavior.
Nutanix AHV supports VM-VM Anti-Affinity policies through both the legacy CLI-based approach and the GUI-based method in Prism Central. VM-VM Anti-Affinity polices are not possible through Prism Element.
Prior to the AOS 7.0 and pc.2024.3 releases, VM-VM anti-affinity policies could only be managed via the Acropolis CLI (aCLI
). With more recent releases, administrators can create category-based VM-VM anti-affinity policies from Prism Central, rather than the CLI method. The CLI method is still useful in environments where Prism Central isn’t deployed or where automation scripts are preferred.
Creating VM-VM Anti-Affinity Policies via ACLI (Command Line)
# Create a VM Group
acli vm_group.create Domain_Controllers
# Add VMs to the group
acli vm_group.add_vms Domain_Controllers vm_list=MAINDC01,MAINDC02
# Apply an Anti-Affinity rule to the group
acli vm_group.set_rule Domain_Controllers anti_affinity=True
Now it’s great that we can programatically set Anti-Affinity policies via ACLI, however, notice the output that we receive when doing so, telling us this will be deprecated. Good to know!
"Deprecation Warning: VM group operations through ACLI will be removed in future releases. Use Prism Central based anti-affinity policies instead."
Domain_Controllers: pending
Domain_Controllers: complete
Now that these are set up, we can validate the results with the following commands. You can find additional information in the commands reference guide:
# Lists all VM groups
acli vm_group.list
# Retrieves information about a VM group
acli vm_group.get Domain_Controllers
# Lists VMs configured to the VmGroup
acli vm_group.list_vms Domain_Controllers
Configuring VM-VM Anti-Affinity in Prism Central (GUI)
As we saw from the warning when creating Anti-Affinity polices using ACLI, these are being deprecated, and recommended using Prism Central. With Prism Central, Nutanix has provides a visual interface to create and manage VM-VM affinity and anti-affinity rules.
As the image above highlights, it’s a 3-part process to creating Anti-Affinity Policies.
First, we want to create categories to define the VMs we want to apply to. In my case, I’m using the built-in SharedService category of AD, and have applied that to both of my domain controllers.
Second, we create the policy and define the category or categories to be compliant with this policy.
Once the policy is applied, the current state of compliance will be validated, and the active compliance can be quickly seen.
Final Thoughts
Affinity and anti-affinity policies are powerful tools in the Nutanix AHV arsenal that enable administrators to optimize workload placement for availability, performance, and compliance.
The evolution from CLI-only to category-based management in Prism Central represents a major step forward in scalability, governance, and ease of use.
Key takeaways:
- Use VM-Host Affinity for targeted placement and licensing
- Use VM-VM Anti-Affinity for availability and fault domain separation
- CLI methods still offer automation value—but Prism Central is the future
At eGroup, we guide clients through this transition by aligning Nutanix configuration with DR strategies, app priorities, and security controls—ensuring that Affinity policies actually deliver on their promise.
Smart policy. Smarter placement. Stronger outcomes.
Take Control of Your Nutanix VM Strategy
Looking to simplify your Nutanix environment and build smarter placement policies at scale?