1

I'm trying to setup anti affinity with a cluster Hyper-V setup but am struggling to get any VMs to stay apart. It seems to be that the anti affinity is simply not honored.

Setup:

  • 3 x Hyper-V servers (server1, server2, server3)
  • 3 x VMs (web_test_1, web_test_2, web_test3)

Attempt 1: I ran the below script on server1:

$WEBAntiAffinity = New-Object System.Collections.Specialized.StringCollection

$WEBAntiAffinity.Add("WEB Servers")

(Get-ClusterGroup –Name WEB_TEST_1).AntiAffinityClassNames = $WEBAntiAffinity
(Get-ClusterGroup –Name WEB_TEST_2).AntiAffinityClassNames = $WEBAntiAffinity
(Get-ClusterGroup –Name WEB_TEST_3).AntiAffinityClassNames = $WEBAntiAffinity

Get-ClusterGroup |Select-Object -Property name,AntiAffinityClassNames

All three VMs were powered off before I ran the above and all created on server1.

When powering them on, they all powered on and stayed on server1.

Attempt 2: I ran the same script above, on the additional servers (server2 and server3).

I powered off the VMs and powered them back on again, they again all remained on server1.

Attempt 3: After having ran the script on all the servers, I restarted the servers one by one. The VMs moved between nodes as normal during the reboots but when all were rebooted I stopped all the VMs, moved them to server1 and then started them again.

My assumption was that 2 would move before powering on but that didn't happen, they all started on server1.

Anyone know what I'm doing wrong here? Am I missing some pre-reqs? There's not a great amount of examples online that I've been able to find.

Saf
  • 92
  • 2
  • 9
  • I have run in to exactly the same problem, with almost exactly the same configuration as you: 3 host, 3 guests, all in the same anti-affinity group, and the same attempts as you. A blog post mentioned pausing the nodes and then resuming to trigger a rebalance, but that didn't work for me either. Have you had any further success? – longneck Mar 16 '22 at 03:08

1 Answers1

1

This is not called out specifically in Microsoft's documentation, but to make anti-affinity rules work in Hyper-V you also need System Center Virtual Machine Manager (SCVMM). SCVMM reads the anti-affinity rules (and other rules such as affinity, priority, etc.) and performs the migrations to apply those rules.

This is equivalent to the vmware stack, where ESXi is the hypervisor, the VM configuration contains the rules, and Director or vSphere actually apply the rules.

longneck
  • 11,938
  • 2
  • 36
  • 44
  • Thank you for the update. I did not know this. And in answer to your previous comment. We setup the anti-affinity rules but as there didn't seem to be any way to test it and all tests didn't really show what I expected we just left it configured and 'hoped' it would work. I'm not sure we'll be getting SCVVM so it's unlikely it will work for us then. – Saf Mar 17 '22 at 07:55