VMware ESXi and vSphere Cluster Management
Create a VMware vSphere DRS VM-VM Affinity Rule
Learn how to create, verify, manage, and troubleshoot a VMware vSphere DRS VM-VM affinity rule that keeps selected VMs on the same ESXi host.
A VMware vSphere Distributed Resource Scheduler (DRS) VM-VM affinity rule tells DRS to keep selected virtual machines on the same physical ESXi host. This placement is called colocation. It can reduce network latency between tightly coupled application components, such as an application VM and a supporting service VM.
This rule operates inside a single DRS-enabled vSphere cluster. It does not place virtual machines together across unrelated standalone ESXi hosts or across separate clusters.
How VM-VM affinity works
vSphere DRS is the cluster service that evaluates virtual machine placement and host load. When DRS evaluates initial placement, workload balancing, or a migration event, it considers configured placement rules along with capacity, compatibility, availability, and other constraints.
A VM-VM affinity rule expresses the objective that its member VMs should run on the same ESXi host. For example, a two-tier application might have these members:
- An application virtual machine
- A supporting service virtual machine
If both VMs can run on one compatible host and sufficient capacity is available, DRS can keep them colocated or recommend a migration that makes them colocated.
Prerequisites and planning
Before creating the rule, confirm that the placement objective is technically and operationally reasonable. The following checklist helps prevent a rule that cannot be satisfied.
Check cluster membership and DRS
The target ESXi hosts must belong to the same vSphere cluster, and DRS must be enabled for that cluster. If the VMs are in different clusters, move or otherwise reorganize them before attempting to use a VM-VM rule.
If you need background on inventory structure, see adding an ESXi host to vCenter Server inventory and communication between vCenter Server and ESXi.
Confirm vMotion and capacity readiness
DRS can use vMotion, the live migration of a running VM between compatible ESXi hosts, to change placement. Verify that each selected VM can run on the same eligible hosts and that their combined requirements fit on at least one host.
- Check CPU and memory capacity, including reservations and overhead.
- Check datastore and storage accessibility.
- Check virtual networking and port-group availability.
- Check CPU and other host compatibility requirements.
- Check that the target host is not unavailable or in a state that prevents placement.
Consider what should happen during host maintenance, a host failure, admission-control decisions, licensing restrictions, or temporary resource shortages. A rule is a placement objective; it cannot create capacity or override every condition required to keep VMs running.
Navigate to DRS rule management
- Select the target cluster in the vSphere inventory.
- Open Manage.
- Open Settings.
- Locate DRS Rules.
- Choose Add to start a new rule.
Select cluster > Manage > Settings > DRS Rules > AddThe exact labels can vary slightly between vSphere versions, but the rule is created from the selected cluster's DRS settings rather than from an individual standalone host.
Create a VM-VM affinity rule
- In the rule creation dialog, enter a meaningful name. For example, use a name such as
App01-and-Service01-Colocationthat identifies the relationship. - Choose the VM-VM affinity type, commonly displayed as Keep virtual machines together.
- Add the virtual machines that must be colocated.
- Review the member list carefully. Two VMs are the simplest example, but additional VMs can be included when the application design requires them.
- Confirm the rule's enabled state.
- Save the rule.
The essential configuration consists of the rule name, the keep-together VM-VM rule type, and the selected VM members.
Preferential versus strict behavior
Depending on the vSphere version and rule interface, a rule may expose a distinction between a preferred or preferential placement and a strict requirement. A preferential rule tells DRS to favor colocation when possible. A strict option, where available, expresses a stronger must-run-together requirement.
Use the option that matches the operational requirement. A strict requirement can make placement, maintenance, and recovery more difficult when no host can satisfy all constraints. Even a preferred rule may not be immediately satisfied when capacity, compatibility, availability, or another policy takes precedence.
DRS enforcement and automation
DRS considers the affinity requirement during initial VM placement and later workload balancing. If members start on different hosts, DRS can identify a migration that would place them together.
The DRS automation level determines how eligible actions are handled:
- In a recommendation-based configuration, DRS presents a proposed migration for an administrator to review and apply.
- In a more automated configuration, DRS can execute eligible vMotion migrations automatically.
A DRS recommendation is a proposed placement or migration action generated to improve balance or comply with configured rules. DRS does not guarantee an immediate migration merely because a rule is enabled. It must also find an eligible host and satisfy resource, compatibility, maintenance, availability, and policy constraints.
Verify the affinity rule
- Return to the cluster's DRS Rules list.
- Confirm that the new rule appears and is enabled.
- Inspect the current ESXi host for each rule member.
- Select the cluster and open Monitor.
- Open vSphere DRS to review DRS status, recommendations, and migrations.
Select cluster > Monitor > vSphere DRSFor a useful test, begin with two selected VMs running on different hosts in the same DRS cluster. DRS may show a recommendation to migrate one VM so both become colocated, or it may perform the migration automatically according to the cluster automation level.
After a recommendation is applied or an automated migration completes, check the host assigned to each VM. Both members should show the same ESXi host when the affinity objective is currently satisfiable.
Affinity versus anti-affinity
Choose affinity only when colocation is desired. If two redundant application nodes must remain on separate physical hosts, use a VM-VM anti-affinity rule instead.
Manage an existing rule
Edit a rule
Open the cluster's DRS Rules list, select the existing rule, and choose the available edit action. Depending on the vSphere version and permissions, you can rename the rule, change its enabled state, or add and remove VM members.
Review the resulting member list before saving. Adding a VM increases the amount of capacity and compatibility that must be available on one host. Removing a VM changes the placement relationship for that VM but does not necessarily cause an immediate migration.
Disable a rule temporarily
Disable the rule when you need to suspend its placement objective without deleting its definition. This preserves the rule and its members for later use. Disabling a rule does not necessarily move any VM immediately; DRS behavior depends on automation and current cluster conditions.
Remove a rule
Delete the rule when the colocation requirement no longer applies. Removing the configuration does not necessarily trigger an immediate migration or redistribute the VMs. DRS may later make recommendations based on load balancing and other active policies.
Troubleshooting
The Add option or DRS Rules section is unavailable
- The selected inventory object may not be a cluster.
- DRS may not be enabled for the cluster.
- Your vCenter permissions may not include the required cluster configuration privileges.
Select the correct cluster, enable DRS where appropriate, and verify the assigned role. See assigning permissions for help reviewing access.
DRS does not move the VMs onto the same host
- DRS may be configured to provide manual or partially automated recommendations.
- No eligible host may have enough combined CPU or memory capacity.
- vMotion compatibility or networking requirements may not be met.
- A host may be in maintenance mode or otherwise unavailable.
- A VM-host rule, anti-affinity rule, or another conflicting policy may block placement.
Review the vSphere DRS monitoring view, inspect recommendations and reasons, confirm vMotion readiness, check cluster capacity, and review conflicting rules. If DRS provides a recommendation rather than applying it, an administrator may need to apply it manually.
The rule is enabled but the VMs remain separated during maintenance or failure
The cluster may be unable to satisfy colocation while also preserving availability, capacity, and compatibility. A preferred affinity objective is normally less important than conditions required to keep workloads running. Review available hosts, admission-control behavior, capacity, and conflicting policies. If colocation is essential, determine whether the cluster needs additional resources or a stricter placement design.
For related planning, review admission control and admission-control policies.
A VM cannot be added to the rule
- The VM may not belong to the target cluster.
- The VM may already be subject to an incompatible placement rule.
- The selected object may not be an eligible virtual machine.
Confirm the VM's cluster membership and inspect existing DRS rules before changing membership.
Exam-relevant notes
- A VM-VM affinity rule keeps specified VMs on the same ESXi host.
- A VM-VM anti-affinity rule keeps specified VMs on different ESXi hosts.
- Both rule types are managed at the DRS cluster level.
- vMotion compatibility and sufficient capacity are necessary for DRS to migrate VMs.
- DRS automation controls whether eligible migration actions are recommended or executed.
- An enabled rule does not override host failure, maintenance, capacity, compatibility, admission-control, or conflicting-policy constraints.
Summary
To create a VM-VM affinity rule, select a DRS-enabled cluster, open Manage > Settings > DRS Rules, add a clearly named keep-together rule, select its VM members, and save it. Verify the enabled rule in the DRS Rules list, then inspect VM host locations and the Monitor > vSphere DRS view for recommendations or migrations. Keep in mind that DRS can colocate the VMs only when cluster capacity, vMotion compatibility, availability, and other placement constraints permit it.