A VM-Host affinity policy describes a relationship between a category of VMs and a category of hosts.

VM-Host affinity policies can be useful when host-based licensing requires VMs that are running certain applications to be placed on hosts that are licensed to run those applications. They can also be useful when virtual machines with workload-specific configurations require placement on hosts that have certain characteristics.

A VM-Host affinity policy establishes an affinity relationship between a category of virtual machines and a category of hosts. After the policy is created, the placement engine in your SDDC deploys VMs in the category covered by the policy on hosts in the category covered by the policy.

To prevent a VM-Host affinity policy from blocking the upgrade of a host or cluster, VM-Host affinity policies are constrained in several ways.
  • A policy cannot prevent a host from entering maintenance mode. If the host needs to be put into maintenance mode, VMs with an affinity for the host are automatically migrated to another host in the cluster, then migrated back when the maintenance completes and the host becomes available.
  • A policy cannot prevent a host configured for HA from executing a failover. VMs with an affinity for the failed host can be migrated to any available host in the cluster.
  • A policy cannot prevent a VM from powering-on. If a VM subject to a host affinity policy specifies a resource reservation that no host can meet, it is powered on on any available host.
These constraints are lifted as soon as a compliant host becomes available.

Prerequisites

This operation is restricted to users who have the CloudAdmin role.

Procedure

  1. Create a category and tag for VMs that you want to include in a VM-Host affinity policy.

    Pick a category name that describes common characteristics, such as license requirements, of VMs you plan to tag as members of that category.

  2. Create a category and tag for hosts that you want to include in a VM-Host affinity policy.

    You can use existing tags and categories or create new ones specific to your needs. See vSphere Tags and Attributes for more about creating and using tags.

  3. Tag the VMs and hosts that you want to include in a VM-Host affinity policy.
  4. Create a VM-Host affinity policy.
    1. In your SDDC, open vCenter Server.
    2. From the vSphere Client Home, click Policies and Profiles > Compute Policies.
    3. Click Add to open the New Compute Policy Wizard.
    4. Fill in the policy Name and choose VM-Host affinity from the Policy type drop-down control.
      The policy Name must be unique within your SDDC.
    5. Provide a Description of the policy, then use the VM tag and Host Tag drop-down controls to choose a Category and Tag to which the policy applies.

      Unless you have multiple VM tags associated with a category, the wizard fills in the VM tag after you select the tag Category.

      Note:

      In a stretched cluster, each host is automatically tagged with an Availability zones tag. All hosts in an availability zone (AZ) are assigned the same tag, so you can use these tags to establish an affinity between a VM and any host in the cluster that has a specific availability zone tag.

      Compute policy does not affect the location of VM storage, so be sure that VM storage policies locate a copy of VM storage in the AZ where VM is deployed. Compute policy does not affect network paths to and from the VM, which might transit a different AZ than the one where the VM is deployed.

    6. Click Create to create the policy.
  5. (Optional) To delete a compute policy, open the vSphere Client, click Policies and Profiles > Compute Policies to show each policy as a card. Click DELETE to delete a policy.