How to create VM/Host Rules is an article that will explain how creating DRS VM/Host Rules to satisfy some environmental requirements such as “pin” a specific Virtual Machine only to run on a specific ESXi host, avoid both Virtual Machines running on the same ESXi host or something like that.
This rule depends on the DRS service. So, it is a requirement to enable and configure the DRS service before using VM/Host rules.
We have an article that explains how to enable the DRS service. Click HERE to see this article.
VM/Host Rules Overview
To access the VM/Host Rules, select the Cluster Name –> Configure –> VM/Host Rules:
After clicking on “Add” to add a new VM/Host Rules, it is possible to choose the type of the rule.
There are some types of rules, described below:
Keep Virtual Machines Together: Keep the virtual machines together on the same ESXi host inside this cluster.
Separate Virtual Machines Together: Separate the virtual machines. So, both virtual machines never will run on the same ESXi host, for example.
Virtual Machines to Hosts: Enforce the specific virtual machines to run on specific ESXi hosts.
Virtual Machines to Virtual Machines: Virtual machines in the Cluster VM Group “X” must have the dependency restart condition met before vSphere HA proceeds with restarting the VMs in group “Y”, for example.
Creating a VM/Host Group
Before creating a VM/Host Rule, is necessary to create a VM/Host Groups to match the VM/Host rules requirements.
For doing it, under the Configure tab, click on “VM/Host Groups” and click on “ADD”:
The first group is “VM_Group-A” and it is a group of the Virtual Machines “VM-01”, “VM-02”, and “VM-03”:
Select the Virtual Machines and click on OK:
Click on OK to confirm the VM/Host Group creation:
The next group is “VM_Group-B” and it is a group of the Virtual Machines “VM-04”, “VM-05”, and “VM-06”.
Repeat the same steps and click on OK to confirm the group creation:
Now, we are creating both VM/Host Groups.
The first host group is “Host_Group-A” and contains the ESXi hosts “01” and “02”:
Select both ESXi hosts and click on OK to continue:
Click on OK to confirm the host group creation:
The next host group is “Host_Group-B” and only contains the ESXi host “03”:
After that, it is possible to see all VM Groups and all Host Groups:
Creating a VM/Host Rule
Virtual Machines to Hosts
In this lab, we will create a VM/Host rule to enforce that the Virtual Machines in Group A only will run on the Hosts in Group A, and the Virtual Machines in Group B only run on the Hosts in Group B.
To acquire it, follow the instructions below. Creating the first rule for the Virtual Machines in Group A:
Creating the second rule for the Virtual Machines in Group B:
After a few minutes, if necessary, the DRS service will migrate the Virtual Machines to enforce the DRS Rules.
In this example, we can see some migration tasks. The DRS migrated these Virtual Machines to enforce the DRS rules that we created:
Important note about the “Virtual Machines to Host” type DRS rule:
- Must run on hosts in group. Virtual machines in VM Group A must run on hosts in Host Group A.
- Should run on hosts in group. Virtual machines in VM Group A should, but are not required, run on hosts in Host Group A (There is a possibility of the Virtual Machines in Group A to run in Hosts in Group B, for example).
Separete Virtual Machines
Another important example of the VM/Host Rules is the Separate Virtual Machines. In this type of rule, both or more Virtual Machines will not run on the same ESXi host.
For example:
If you would like to avoid Virtual Machine “VM-01” running on the same ESXi host that the Virtual Machine “VM-03”, the rule for it is:
To see more details about this subject, the link below can be read (4sysops is a very interesting site that I follow 🙂 ):
https://4sysops.com/archives/configuration-of-vsphere-7-drs-affinity-and-anti-affinity-rules/