Configuring vSphere DRS VM-VM Affinity and Anti-Affinity Rules
Technical guide on implementing vSphere DRS VM-VM affinity and anti-affinity rules to optimize application latency and fault tolerance across ESXi hosts.
16 Feb 2026, 10:18 UTC

The Placement Problem
In a virtualized cluster, default Distributed Resource Scheduler (DRS) behavior prioritizes resource balance over application architecture. This can lead to two critical failures: redundant application nodes (like active/passive database pairs) landing on the same physical host, creating a single point of failure, or tightly coupled tiers (like a web server and its local cache) being split across hosts, increasing network latency.
The solution is to implement VM-VM affinity and anti-affinity rules to force or suggest specific placement patterns based on the application's fault tolerance and performance requirements.
Prerequisites
- vCenter Server: Version 7.0 Update 3 or 8.0.
- Licensing: VMware vSphere Enterprise Plus (required for DRS).
- Cluster State: DRS must be enabled and set to either Fully Automated or Partially Automated.
- Permissions: The user account requires
Host.Inventory.EditClusterandResource.AssignVMToPoolpermissions on the cluster object.
Rule Configuration Procedure
- Navigate to the vSphere Client, select the target cluster, and go to Configure → VM/Host Rules → Add.
- Assign a descriptive name (e.g.,
DB-Cluster-AntiAffinity). Ensure Enable rule is checked. - Select Virtual Machines to Virtual Machines as the rule type.
- Define the placement logic:
- Affinity (Should run on the same host): Use this for latency-sensitive workloads that communicate frequently.
- Anti-Affinity (Should run on different hosts): Use this for high-availability pairs to ensure a single host failure does not take down both nodes.
- Click Add to select the participating VMs. A minimum of two VMs is required.
- Click OK. DRS will evaluate the rule during its next cycle (default 5 minutes) or when you manually trigger Apply DRS Recommendations.
Verification and Diagnostics
Because DRS rules are "soft" (Should) rather than "hard" (Must), you must verify that the cluster has enough capacity to honor the rule without violating others.
Manual and UI Checks
- DRS Recommendations: Navigate to Cluster → Monitor → vSphere DRS → Recommendations. Check if DRS is suggesting migrations to satisfy the new rule.
- Alarm Monitoring: Ensure the DRS rule violation alarm is enabled under Alarms → Definitions → vSphere DRS.
PowerCLI Validation
Run the following command from a PowerCLI session connected to vCenter to audit all VM-VM rules and their current members:
Get-DrsRule -Cluster "<cluster-name>" | Where-Object {$_.Type -eq 'VmVmAffinity' -or $_.Type -eq 'VmVmAntiAffinity'} | Format-Table Name, Enabled, Type, @{N='VMs';E={($_.VMIds | ForEach {Get-VM -Id $_}).Name -join ','}} -AutoSize
Expected Result: A table listing the rule name, its enabled status, the type (Affinity/Anti-Affinity), and a comma-separated list of the VMs assigned to that rule.
Engineering Decisions: Affinity vs. Anti-Affinity
| Scenario | Recommended Rule | Engineering Justification |
|---|---|---|
| Active/Passive DB Pair | Anti-Affinity | Prevents a single hardware failure from causing a total service outage. |
| App Server & Local Cache | Affinity | Reduces inter-VM network hops to minimize latency. |
| License-Bound Workloads | VM-Host (Must) | VM-VM rules are insufficient; use VM-Host groups to lock VMs to specific licensed hardware. |
Recovery and Rollback
If a rule causes placement conflicts—such as during host maintenance where a VM has no compliant host to move to—DRS may violate the rule and trigger an alarm.
- To resolve a conflict: Uncheck Enable rule in the rule editor. This allows DRS to rebalance the cluster based on resource availability rather than placement constraints.
- Manual Correction: Use vMotion to manually move VMs to compliant hosts if the cluster is in Partially Automated mode.
- Full Rollback: Delete the rule entirely from the VM/Host Rules menu to return the cluster to default resource-based placement.
Critical Limitations
- HA Interaction: vSphere HA does not honor DRS VM-VM rules. If a host fails, HA may restart VMs on any available host, potentially violating your anti-affinity rules until the next DRS cycle.
- Scale Limits: Exceeding 50 VM-VM rules per cluster can increase the computational overhead for DRS. Use VM Groups (available in 7.0 U2+) to consolidate multiple VMs into a single rule.
- Maintenance Mode: If a VM in an anti-affinity rule is the last remaining VM on a host entering maintenance mode, DRS will violate the rule to evacuate the host.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.