Reader small image

You're reading from  Learning PowerCLI - Second Edition

Product typeBook
Published inFeb 2017
Publisher
ISBN-139781786468017
Edition2nd Edition
Right arrow
Author (1)
Robert van den Nieuwendijk
Robert van den Nieuwendijk
author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk

Right arrow

Chapter 8. Managing High Availability and Clustering

The availability of the applications running in your environment is an important advantage of virtualization. In the case of a host's or operating system's failure, VMware vSphere High Availability (HA) will restart the affected virtual machines. This ensures that your servers are available as much as possible.

VMware vSphere Distributed Resources Scheduler (DRS) provides initial placement of a virtual machine on an appropriate host during power on, automated load balancing to maximize performance and distribution of virtual machines across hosts to comply with affinity and anti-affinity rules.

To save power and money, Distributed Power Management (DPM) will consolidate your virtual machines on fewer hosts in your cluster and power down the unused hosts when not all of the resources are needed.

To use DRS or DPM, you need a VMware vSphere Enterprise Plus or vSphere with Operations Management Enterprise Plus license.

The topics that will be...

Creating vSphere HA and DRS clusters


In Chapter 4, Managing vSphere Hosts with PowerCLI, you already saw how to create a vSphere cluster with the default settings using the New-Cluster cmdlet. In the default settings, HA and DRS are disabled. You will now see how to create a cluster with HA and DRS enabled. First, the syntax of the New-Cluster cmdlet will be repeated, so you don't have to look back to Chapter 4, Managing vSphere Hosts with PowerCLI :

New-Cluster [-HARestartPriority <HARestartPriority>]
    [-HAIsolationResponse <HAIsolationResponse>] [-VMSwapfilePolicy
    <VMSwapfilePolicy>] [-Name] <String> -Location <VIContainer>
    [-HAEnabled] [-HAAdmissionControlEnabled] [-HAFailoverLevel
    <Int32>] [-DrsEnabled] [-DrsMode <DrsMode>] [-DrsAutomationLevel 
    <DrsAutomationLevel>] [-VsanDiskClaimMode <VsanDiskClaimMode>]
    [-VsanEnabled] [-EVCMode <String>] [-Server <VIServer[]>...

Retrieving clusters


To retrieve one or more of the clusters available on your vCenter Server system, you can use the Get-Cluster cmdlet. The syntax of the Get-Cluster cmdlet is as follows. The first parameter set is for retrieving clusters in a specific location such as a data center or a folder:

Get-Cluster [[-Name] <String[]>] [-Location <VIContainer[]>]
    [-NoRecursion] [-Tag <Tag[]>] [-Server <VIServer[]>]
    [<CommonParameters>]

The second parameter set is for retrieving clusters by a related object.

Get-Cluster [-RelatedObject] <ClusterRelatedObjectBase[]>
    [<CommonParameters>]

The third parameter set is to retrieve clusters containing specific virtual machines or ESXi hosts:

Get-Cluster [[-Name] <String[]>] [-VM <VirtualMachine[]>]
    [-VMHost <VMHost[]>] [-Tag <Tag[]>] [-Server <VIServer[]>]
    [<CommonParameters>]

The fourth parameter set is to retrieve clusters by ID:

...

Modifying the cluster settings


To modify the settings of a cluster, you can use the Set-Cluster cmdlet. This cmdlet has basically the same parameters as the New-Cluster cmdlet, with the addition of the -Profile parameter that enables you to associate a host profile with a cluster. The syntax of the Set-Cluster cmdlet is as follows:

Set-Cluster [-HARestartPriority <HARestartPriority>]
    [-HAIsolationResponse <HAIsolationResponse>] [-VMSwapfilePolicy
    <VMSwapfilePolicy>] [-Cluster] <Cluster[]> [[-Name] <String>]
    [-HAEnabled [<Boolean>]] [-HAAdmissionControlEnabled [<Boolean>]]
    [-HAFailoverLevel <Int32>] [-DrsEnabled [<Boolean>]] [-DrsMode 
    <DrsMode>] [-DrsAutomationLevel <DrsAutomationLevel>] [-VsanEnabled
    [<Boolean>]] [-VsanDiskClaimMode <VsanDiskClaimMode>] [-Profile
    <VMHostProfile>] [-EVCMode <String>] [-Server <VIServer[]>]
  ...

Moving hosts to clusters


You can use the Move-VMHost cmdlet to move a host to a cluster. The host has to already be added to your vSphere inventory. If it isn't, you can use the Add-VMHost cmdlet to add the host to your inventory, as shown in Chapter 4, Managing vSphere Hosts with PowerCLI . The host also has to be in a maintenance mode or you will get the error message: The operation is not allowed in the current state.

The syntax of the Move-VMHost cmdlet is as follows:

Move-VMHost [-VMHost] <VMHost[]> [-Destination] <VIContainer>
    [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm]
    [<CommonParameters>]

The -VMHost and -Destination parameters are required.

You can also use the Move-VMhost cmdlet to move a host to another VIContainer such as a data center or a folder.

In the following example, you will first put host 192.168.0.134 in a maintenance mode, move the host to Cluster02, and finally exit a maintenance mode:

PowerCLI C:\> $VMHost =...

Moving clusters


You can use the Move-Cluster cmdlet to move a cluster to a folder. The folder must be in the same data center as the cluster. The syntax of the Move-Cluster cmdlet is as follows:

Move-Cluster [-Cluster] <Cluster[]> [-Destination] <VIContainer>
    [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm]
    [<CommonParameters>]

The -Cluster and -Destination parameters are required.

Besides a folder, you can specify the data center to which the cluster belongs as the value of the -Destination parameter. In this case, the cluster is moved to the host system folder of the data center. It is not possible to move a cluster to another data center.

In the following example, Cluster01 is moved to the Accounting folder:

PowerCLI C:\> Move-Cluster -Cluster Cluster01 -Destination Accounting


    Name              HAEnabled  HAFailover DrsEnabled DrsAutomationLevel
                             Level
----              ---------  ----------...

Using DRS rules


To control the placement of virtual machines on hosts in a cluster, you can use DRS affinity rules or anti-affinity rules. There are two types of affinity rules:

  • VM-VM affinity rules: These rules specify affinity or anti-affinity between virtual machines. An affinity rule specifies that DRS should or must keep a group of virtual machines together on the same host. A use case of the affinity rules can be performance because virtual machines on the same hosts have the fastest network connection possible. An anti-affinity rule specifies that DRS should or must keep a group of virtual machines on separate hosts. This prevents you from losing all of the virtual machines in the group if a host crashes.

  • VM-Host affinity rules: These rules specify affinity or anti-affinity between a group of virtual machines and a group of hosts. An affinity rule specifies that the group of virtual machines should or must run on the group of hosts. An anti-affinity rule specifies that the group of...

Using DRS recommendations


To retrieve the available DRS recommendations from the provided clusters, you can use the Get-DrsRecommendation cmdlet. This is useful if you configure the DrsAutomationLevel on your cluster as Manual or PartiallyAutomated. The syntax of the Get-DrsRecommendation cmdlet is as follows:

Get-DrsRecommendation [[-Cluster] <Cluster[]>] [-Refresh]
    [-Priority <Int32[]>] [-Server <VIServer[]>] [<CommonParameters>]

The Get-DrsRecommendation cmdlet has no required parameters.

In the following example, you will retrieve all the DRS recommendations for all the clusters:

PowerCLI C:\ > Get-DrsRecommendation


    Priority Recommendation                Reason
-------- --------------                ------
2        Migrate VM 'VM1' from host... Fix soft VM/host affinity r...

To apply a DRS recommendation, you can use the Invoke-DrsRecommendation cmdlet. This cmdlet has the following syntax:

Invoke-DrsRecommendation [-DrsRecommendation...

Using resource pools


The virtual machines in a vSphere cluster share the resources of the ESXi hosts in the cluster. Resource pools are a way to divide the resources of the cluster into different pools. Virtual machines in a resource pool share the resources of their resource pool. This can be useful to always give a group of virtual machines the resources they need or to limit the number of resources for a group of virtual machines.

Each cluster has a root resource pool named Resources. The resource pools you create are children of the Resources root resource pool or other resource pools in the cluster.

Resource pools and virtual machines have settings that will be explained in the following table:

Using Distributed Power Management


The load of your virtual machines is probably not always the same. Sometimes, they need more resources, and sometimes, they need fewer resources. Distributed Power Management (DPM) will use DRS to consolidate virtual machines on fewer ESXi hosts during periods of low resource utilization. The unused ESXi hosts will be powered off. If more resources are needed, DPM will power on ESXi hosts, and DRS will move virtual machines to these hosts. DPM will save you or your company money in power and cooling costs.

Enabling DPM

DPM has two modes: manual and automatic. In manual mode, DPM will give recommendations to evacuate virtual machines from hosts and power off or power on the hosts. You will have to apply the recommendations manually. In automatic mode, DPM will automatically apply DPM recommendations above a certain threshold.

In the following screenshot of the vSphere Web Client, you will see the DPM settings of a cluster with Automation Level set to Manual...

Removing clusters


The Remove-Cluster cmdlet will remove a cluster from your vSphere inventory. The Remove-Cluster cmdlet has the following syntax:

Remove-Cluster [-Cluster] <Cluster[]> [-Server <VIServer[]>]
    [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

The -Cluster parameter is required.

The following example will remove Cluster02 that was created at the beginning of this chapter:

PowerCLI C:\> Remove-Cluster -Cluster Cluster02
    -Confirm:$false

The preceding command does not return any output.

Tip

Be careful. Removing a cluster will also remove all the hosts and virtual machines in the cluster!

Summary


In this chapter, you learned all about managing vSphere HA and DRS clusters. We looked at retrieving HA master or primary hosts, retrieving cluster configuration issues, and disabling HA, to perform network maintenance that may cause network isolation. You learned about disabling or enabling host monitoring, associating a host profile with a cluster, enabling VM and Application Monitoring, configuring the heartbeat datastore selection policy, moving hosts to clusters, and moving clusters.

Using DRS rules and DRS groups, we discussed how to control the placement of virtual machines on hosts in a cluster. You learned to use resource pools and to divide the resources of the cluster into different pools. We looked at configuring resource allocation between virtual machines, with shares, limits, and reservations.

Finally, you read how to use Distributed Power Management, to save money in power and cooling costs during the periods of low resource utilization.

The following chapter will be...

lock icon
The rest of the chapter is locked

Unlock this book and the full library FREE for 7 days

Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
You have been reading a chapter from
Learning PowerCLI - Second Edition
Published in: Feb 2017Publisher: ISBN-13: 9781786468017
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime

Author (1)

author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at&nbsp;http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk

Setting

Description

Shares

A relative importance against sibling resource pools or virtual machines. Shares can have a level (Custom, High, Low, or Normal) or an amount.

Limit

The maximum allowed resources.

Reservation

The minimum available resources.

Expandable reservation (resource...