VMware ESXi and vSphere Cluster Management
How to Create a VMware vSphere DRS VM Affinity Rule
Learn how to create and verify a VMware vSphere DRS VM-VM affinity rule that keeps selected virtual machines together on the same ESXi host.
A VMware vSphere VM-VM affinity rule tells Distributed Resource Scheduler (DRS) to keep selected virtual machines on the same ESXi host. This can help tightly coupled application components communicate with lower network latency, but it also reduces the number of hosts available for placement.
This lesson covers creating the rule in the vSphere Client, choosing mandatory or preferential behavior when available, verifying DRS activity, and troubleshooting capacity or migration problems. For a related configuration, see Create a DRS affinity rule.
What vSphere DRS affinity does
vSphere DRS is a cluster feature that evaluates resource usage and helps place or migrate virtual machines across ESXi hosts. It can produce a DRS recommendation, which is a suggested placement or migration action intended to balance resources or satisfy a rule.
A VM-VM affinity rule directs DRS to place the listed virtual machines together on one ESXi host. If the VMs are running on different hosts, DRS can recommend moving one of them with vMotion, which is the live migration of a running VM from one ESXi host to another.
Example: tightly coupled application components
Suppose an application VM frequently communicates with a supporting service VM. You can place both VMs in one VM-VM affinity rule so DRS attempts to run them on the same host. This may reduce communication latency, but the destination host must have enough capacity for both VMs.
Prerequisites
- Use a vCenter Server-managed cluster. DRS rules are configured at the cluster level through vCenter Server.
- The cluster must contain multiple ESXi hosts and the virtual machines that you want to group.
- DRS must be enabled for the cluster. DRS must be operating before it can evaluate and act on placement rules.
- Your account needs permission to modify cluster DRS rules.
- The selected VMs must be eligible for migration and must not have incompatible host, datastore, network, CPU, or other placement requirements.
- Understand basic vSphere Client navigation, vMotion, cluster administration, and DRS automation modes.
Affinity rule types
Do not confuse VM-VM affinity with VM-host affinity. VM-VM rules relate selected VMs to one another. VM-host rules relate VMs to particular ESXi hosts.
Mandatory and preferential behavior
Depending on the vSphere version and rule interface, an affinity rule can expose choices such as must run together and should run together.
- Must run together: a mandatory policy. DRS treats co-location as a strict requirement. If no host can accommodate the VM group, migrations or other operations may be blocked.
- Should run together: a preferential policy. DRS attempts to co-locate the VMs when cluster conditions allow, but it has more flexibility when resources or compatibility constraints prevent the preferred placement.
This lesson focuses on VM-VM affinity. An anti-affinity rule has the opposite goal: it directs selected VMs to run on separate hosts.
Create the DRS VM affinity rule
- Select the target cluster in the vSphere inventory.
- Open the cluster's Manage or Configure area.
- Locate DRS Rules under the cluster settings.
- Choose Add or the control used to create a new rule.
- Enter a descriptive rule name. Include the application or VM group in the name, such as
App01-and-Service01-SameHost. - Select the VM-VM affinity option. In releases that show separate behavior choices, select either the mandatory or preferential option according to the application requirement.
- Use the VM selection control to add every virtual machine that must be placed together.
- Review the rule name, rule type, behavior, and selected VMs.
- Save the rule with OK, Finish, or the equivalent action.
Configuration path
vSphere Client inventory
Select cluster
Manage or Configure
DRS Rules
Add
Set name and VM-VM affinity type
Add virtual machines
SaveUse a name that remains understandable after the application changes. Avoid generic names such as Rule1, especially in clusters containing many placement policies.
Verify the rule and DRS behavior
- Return to the cluster's DRS Rules list.
- Confirm that the new rule is enabled.
- Confirm that every intended VM appears in the rule and that no unintended VM was added.
- Check the current ESXi host for each selected VM.
- Select the cluster and open Monitor > vSphere DRS.
- Review recommendations, migration actions, and rule-related placement outcomes.
If the selected VMs initially run on different hosts, DRS may recommend moving one VM to the other's host. Whether that recommendation is executed automatically depends on the cluster's DRS automation mode. Manual mode presents recommendations for an administrator to apply. Partially automated or fully automated configurations can execute eligible placement actions according to their settings.
A recommendation might not appear immediately. DRS considers current placement, resource demand, available capacity, migration compatibility, and other cluster policies. If the VMs are already on the same host, there may be no migration to recommend.
Operational considerations
Affinity reduces DRS placement flexibility. A host must provide sufficient CPU, memory, and compatible storage, networking, and CPU features for the complete VM group. A hard affinity policy can prevent migrations or make host evacuation difficult when no eligible host can accommodate every VM.
Review rules when VM resource requirements, cluster capacity, maintenance procedures, or application architecture changes. Avoid unnecessary rules: excessive constraints can prevent DRS from balancing workloads effectively.
Troubleshooting
No migration recommendation appears
Possible causes include:
- DRS is disabled or is not operating for the cluster.
- The selected VMs are already running on the same host.
- DRS is in manual mode and the recommendation has not been reviewed.
- No viable migration path exists because of capacity, compatibility, or placement restrictions.
Check the cluster-level DRS setting, compare the current host placement of the VMs, and review Monitor > vSphere DRS. Also validate destination-host CPU and memory capacity, datastore access, network availability, vMotion compatibility, and any host-specific requirements.
DRS cannot keep the VMs on one host
First, review the combined resource demand of all VMs in the rule. No host may have enough available memory or CPU for the complete group. Other DRS rules, VM-host rules, incompatible CPU requirements, unavailable datastores or networks, migration restrictions, maintenance mode, or an unavailable host can also prevent placement.
Inspect all cluster rules for contradictions and verify that the VMs can migrate to a common destination. If the requirement is still valid, add capacity or reduce demand. If the application can tolerate separation, consider changing a mandatory policy to a preferential one or revising the VM grouping.
The rule blocks maintenance or evacuation
A mandatory affinity rule can prevent DRS from separating the VMs temporarily. Confirm that another host can accommodate the entire group, and plan maintenance with sufficient spare capacity. Temporarily adjust or disable the rule only when the operational risk is understood and the change is approved.
Practical validation example
Two resource-intensive VMs, App01 and Service01, are running on different ESXi hosts. After creating a VM-VM affinity rule, the administrator confirms both VM names in the DRS Rules list and checks the vSphere DRS monitoring page. DRS may recommend migrating one VM to the host running the other. In automatic mode, the migration may be executed if all requirements are met; in manual mode, the administrator must review and apply it.
If no host has enough available memory for both VMs, DRS cannot fully satisfy the affinity policy. The administrator must add capacity, reduce VM demand, wait for resource conditions to change, or revise the policy if co-location is no longer essential.
Exam-relevant notes
- VM-VM affinity means selected VMs run together on one ESXi host.
- VM-VM anti-affinity means selected VMs run separately.
- VM-host affinity is a different rule category that controls VM placement relative to specific hosts.
- DRS recommendations and automated migrations depend on the cluster's DRS automation mode.
- A mandatory affinity rule can reduce availability during maintenance or failure if no single host can hold the VM group.
- Rules do not create additional CPU, memory, storage, or network capacity; the destination host must still satisfy all requirements.