Using DRS in vSphere is a great thing for load balancing your cluster, but what if you need to keep one VM from vMotioning to another host?  Everyone mention’s host affinity when searching, but digging through the DRS settings doesn’t really show much.

The closest thing to ‘Host Affinity’ is this KB article from VMware.

It’s not really that easy, but it’s not complicated by any means. So VMware’s KB article basically says this: create dummy vm1, 2, 3, 4, 5, 6, 7, 8, etc, based on number of hosts in a drs cluster, then register each VM to the corresponding host. By dummy VM, I mean an empty VM that’s not running, just registered. Once that’s done set drs rules as follows (based on 8 hosts):

vm1 cannot run with 2, 3, 4, 5, 6, 7, 8
vm2 cannot run with 3, 4, 5, 6, 7, 8
vm3 cannot run with 4, 5, 6, 7, 8
vm4 cannot run with 5, 6, 7, 8
vm5 cannot run with 6, 7, 8
vm6 cannot run with 7, 8
vm7 cannot run with 8

So now if you wanted to keep one of your VMs on a specific host, say host 1, you can just set another DRS rule to keep your VM and VM1 together. If dummy VM1 isn’t running, it’ll NEVER leave host 1, which keeps your VM there also. HA won’t power VM1 up on another host because it’s not running in the first place. Anyone see an issue with that? Generally, HA may ignore DRS rules, but are you willing to try it out? I’m not. I know this would be useful for licensing certain apps where you pay by the socket and don’t want to license all 16 (or 32) sockets in an 8-node cluster. You could set those DRS rules, then set the advanced DRS option ForceAffinePoweron to 1 and it will strictly enforce all DRS rules. Of course, this would probably keep your desired VM on the same host with the dummy VM, even in a failure (again, untested by me).

Recently, we had an app say it can be virtual, as long as it doesn’t live migrate anywhere (vMotion). Personally, I think this is lame, but any network hiccup caused the app to drop it’s connection and you have to bounce the entire server. So basically I don’t care which host the VM runs on, as long as it doesn’t vMotion to another host.

This can be accomplished by using DRS automation level for specific VMs. There are a couple different options here:
Default – from cluster DRS settings
Fully Auto – vMotions as DRS needs
Partially Auto – Moves on power up, makes recommendations, but does not vMotion
Manual – Makes recommendations, but does not vMotion
Disabled – Pretty much disables DRS (or blocks for this VM)

I used Partially Automated for one of my production VMs that should never vMotion. If I power the VM off, then power it back on, DRS will move it to the host to load balance the cluster as best as possible, but will not vMotion that VM later, only show up as a recommendation.

Basically, you could also set the automation level for a VM to Disabled and it shouldn’t migrate either. It should stay on the original host it was registered to. I haven’t tested that, but I did test Partially Automated on a VM that migrated often, sometimes 3-4 times a day, and it hasn’t migrated in weeks.

This only applies to ESX/i & vCenter prior to 4.1. In 4.1, you can create DRS Groups, which I’ll cover later.