How to deploy a Hyper-V cluster with Powershell

Case



You have two or more physical Hyper-V hosts on which you need to configure a Hyper-V cluster to be able to host virtual machines. This article provides step-by-step guidance on how to deploy a Hyper-V cluster with Powershell.



Solution



Pre-requisites

First off, you should have configured the core/distribution switching infrastructure and the storage infrastructure for supporting your Hyper-V cluster. Designing the proper networking and storage environment for any Windows Failover Cluster (WFC) is outside the scope of this article. You can find out more about design considerations and best practices in my Windows Failover Clustering Design Handbook.



Each Hyper-V host which will join the WFC Hyper-V cluster will need to have sufficient RAM memory, sufficient storage IOPS in its local disks and sufficient number of physical Network Interface Cards (NICs). You will need to ensure redundancy for the shared storage cabling paths with LACP configured at the switch ports side.



Ensure that all your Hyper-V hosts have the latest Windows updates and the latest hardware vendor (for example pNICs and hard disks) drivers and firmware installed.



Remember that when setting up a single (standalone) Hyper-V server, most of the High Availability features of a WFC is not applicable, such as Live Migration, Quick Migration and Storage Multipathing.



Ensure that you have the latest Powershell version installed on all Hyper-V hosts. Powershell Desktop can be run on Windows only while Powershell Core can be run on any supported operating system, including MacOSX and Linux. Powershell Desktop latest version is 5.1 and no new versions will be coming out.





Powershell must have the Hyper-V module imported. The module should already be installed by now as part of the Hyper-V management tools.





Important note



The below Powershell cmdlets must be executed in an elevated Powershell terminal on each Hyper-V physical host. Please use these cmdlets at your own risk as they have been created by taking into account a certain environment/configuration. There may need to be changes in your own environment. First test in a lab environment before applying to production. Obviously all variables and environment-specific elements must be changed to reflect your own environment.



Install server roles and features

Run the following Powershell cmdlets to install the required server roles and features on the Hyper-V host.



Import-Module ServerManager

#Assuming multipath will be enabled in your storage, for example FCoE, FC or iSCSI

Add-WindowsFeature Multipath-IO

Install-WindowsFeature -Name Failover-Clustering –IncludeManagementTools

Install-WindowsFeature Hyper-V

Powershell configuration cmdlets

Run the following cmdlets for configuring IP addressing of the Hyper-V hosts physical NICs.



#The below two commands must be run manually in the HyperV host for configuring an example storage vendor iSCSI storage

#mpiocpl.exe -> add support for ISCSI devices

#mpclaim –s –d

#Install storage vendor iSCSI driver on the Hyper-V host



# Adjust subnetting as per your requirements, the below is only a example.

# The below example assumes four (4) NICs per physical host to be dedicated to shared storage traffic and other four (4) NICs per physical host to be dedicated to cluster traffic.

#NIC1, NIC3, NIC5, NIC7 are used for shared storage traffic

#NIC2, NIC4, NIC6, NIC8 are used for WFC cluster traffic



New-NetIPAddress -InterfaceAlias "NIC1" -IPAddress 192.168.10.11 -PrefixLength 24

New-NetIPAddress -InterfaceAlias "NIC3" -IPAddress 192.168.11.11 -PrefixLength 24

New-NetIPAddress -InterfaceAlias "NIC5" -IPAddress 192.168.12.11 -PrefixLength 24

New-NetIPAddress -InterfaceAlias "NIC7" -IPAddress 192.168.13.11 -PrefixLength 24



#Configure the iSCSI initiator

New-IscsiTargetPortal –TargetPortalAddress

New-IscsiTargetPortal –TargetPortalAddress

New-IscsiTargetPortal –TargetPortalAddress

New-IscsiTargetPortal –TargetPortalAddress



$targets = Get-IscsiDiscoveredTarget

Connect-IscsiDiscoveredTarget –NodeAddress $targets.NodeAddress

Connect-IscsiDiscoveredTarget –NodeAddress $targets.NodeAddress

Connect-IscsiDiscoveredTarget –NodeAddress $targets.NodeAddress

Connect-IscsiDiscoveredTarget –NodeAddress $targets.NodeAddress

#If the Connect-IscsiDiscoveredTarget does not work, then use

#Register-IscsiPersistentTarget –TargetName $targets.NodeAddress, etc.

Get-IscsiPersistentTarget



#Configure MPIO using the Windows Server configuration tool

#Create a NIC team for the NICs to host the WFC cluster and client



New-NetLbfoTeam -Name "HyperVTeam01" -TeamMembers "NIC2", "NIC4", "NIC6", "NIC8" -TeamingMode LACP -LoadBalancingAlgorithm TransportPorts



#Create a Hyper-V vSwitch object and bind it to the NIC team



New-VMSwitch -Name "HyperVSwitch01" -AllowManagementOS 0 -MinimumBandwidthMode Weight -NetAdapterName "HyperVTeam01"



#Or if you prefer to use SET as a SDN alternative to traditional NIC teaming, you can run below cmdlet.



New-VMSwitch -Name "SETTeam01" -NetAdapterName "NIC2", "NIC4", "NIC6", "NIC8" -EnableEmbeddedTeaming $true



#Configure Jumbo frames, check pNIC manufacturer for Jumbo frame optimals and other possible optimized configuration values

Get-NetAdapterAdvancedProperty -Name "NIC*" -DisplayName "Jumbo Frame" | Set-NetAdapterAdvancedProperty -RegistryValue "9216"

Get-NetAdapterAdvancedProperty -Name "NIC*" -DisplayName "Jumbo Mtu" | Set-NetAdapterAdvancedProperty -RegistryValue "9000"

Get-NetAdapterAdvancedProperty -Name "NIC*"



#Configure vNICs, Three virtual networks should be created at minimum, namely Management, Cluster and LiveMigration

Add-VMNetworkAdapter –ManagementOS –Name "Management" –SwitchName "HyperVSwitch01"

Add-VMNetworkAdapter -ManagementOS -Name "Cluster" -SwitchName "HyperVSwitch01"

Add-VMNetworkAdapter -ManagementOS -Name "LiveMigration" -SwitchName "HyperVSwitch01"



#Configure VLANs in the vNICs, example values provided for VLAN IDs

Set-VMNetworkAdapterVlan –ManagementOS –VMNetWorkAdapterName "Management" -Access –VlanId 20

Set-VMNetworkAdapterVlan –ManagementOS –VMNetWorkAdapterName "Cluster" -Access –VlanId 21

Set-VMNetworkAdapterVlan –ManagementOS –VMNetWorkAdapterName "LiveMigration" -Access –VlanId 22

#Enable VMQ on the network adapters of the Hyper-V hosts, check with your hardware vendor to ensure that activating VMQ is supported and will not be causing any performance or operational issues.

Get-NetAdapterVMQ -IncludeHidden

Enable-NetAdapterVmq -Name



#Configure Jumbo frames in the vNICs

Get-NetAdapterAdvancedProperty -Name "vEthernet (LiveMigration)", "vEthernet (Management)", "vEthernet (Cluster)" -DisplayName "Jumbo Packet" | Set-NetAdapterAdvancedProperty -RegistryValue "9014"



#Configure bandwidth allocation settings for the virtual network adapters

Set-VMNetworkAdapter –ManagementOS –Name "Management" –MinimumBandwidthWeight 10

Set-VMNetworkAdapter -ManagementOS -Name "Cluster" -MinimumBandwidthWeight 30

Set-VMNetworkAdapter -ManagementOS -Name "LiveMigration" -MinimumBandwidthWeight 60



#Configure IP addressing of the vNICs and set DNS servers, set as per your network subnetting design, the below are only samples

New-NetIPAddress -InterfaceAlias "vEthernet (Management)" -IPAddress 10.0.1.21 -DefaultGateway 10.0.0.1 -PrefixLength 24

Set-DnsClientServerAddress -InterfaceAlias "vEthernet (Management)" -ServerAddresses 10.0.0.2, 10.0.0.3

New-NetIPAddress -InterfaceAlias "vEthernet (Cluster)" -IPAddress 10.0.2.21 -PrefixLength 24

New-NetIPAddress -InterfaceAlias "vEthernet (LiveMigration)" -IPAddress 10.0.3.21 -PrefixLength 24

#Other tasks to be performed are the following.

#JOIN HYPER-V SERVER TO AN AD DOMAIN

#ACTIVATE WINDOWS SERVER LICENSING

#RUN WSFC CLUSTER VALIDATION WIZARD FULL TESTS

Test-Cluster –Node $ListOfServers –Include "Inventory", "Network", "System Configuration"



#Create the Hyper-V cluster by either using the Failover Cluster Manager mmc console or Powershell





# After all configuration steps are complete, run the following validation tasks

# Check cluster logs and Windows event logs

# Create a test VM and test live migration for networking and storage failover operations
https://stefanos.cloud/kb/how-to-deploy-a-hyper-v-cluster-with-powershell/

Comments

Popular posts from this blog

Acronis Cyber Protect 15 virtual machine backup not working when using shared mode virtual disks vhds

How to perform hardware health checks in Windows

How to resolve Group Policy error codes 8007071a and 800706ba