PowerCLI Cookbook
上QQ阅读APP看书,第一时间看更新

Creating a cluster and adding ESXi hosts

Clusters are the basis for everything that is great within vSphere. Clusters are the level where individual resources become pooled and shared for virtual machines. Clusters allow all higher-level functionalities within vSphere, such as an automatic restart after a hardware failure and dynamic balancing of workloads. Individual ESXi hosts and clusters can exist at the same level under a datacenter object in vSphere.

In this recipe, you will walk through the steps necessary to set up your first cluster of servers in vCenter. You will be reusing the same four ESXi hosts that you configured in the Creating a configuration script to set all properties uniformly recipe from Chapter 1, Configuring the Basic Settings of an ESXi Host with PowerCLI.

Getting ready

This chapter assumes that your vCenter has the datacenter object defined and that you have individual ESXi hosts connected or managed by vCenter. In this example, you will call the Primary datacenter, like you defined in the previous recipe. You will need to open a PowerCLI prompt and connect to your vCenter instance.

vSphere clusters have several advanced features, and when creating the cluster, you will want to enable these features in most cases. In this example, you will enable High Availability (HA) and Dynamic Resource Scheduling. You will also set the DRS mode to FullyAutomated. In the next recipe, you will look at configuring these cluster settings.

How to do it…

In order to set up your first cluster of servers in vCenter by reusing the same four ESXi hosts that you have configured earlier, perform the following steps:

  1. The New-Cluster cmdlet is very simple. If you perform a Get-Help cmdlet on this cmdlet, you will see a number of additional parameters that you can define, but in its simplest form, New-Cluster only requires two parameters: a location and a name:
    New-Cluster -Location (Get-Datacenter -Name "Primary") -Name BigCluster -HAEnabled -DRSEnabled -DRSAutomationLevel FullyAutomated
    
  2. A confirmation output will follow and you can confirm whether the new cluster was created using the Get-Cluster cmdlet.
  3. The next step is to add a host to a cluster. For this, you will use the familiar Get-VMHost cmdlet to find our existing host and then use the Move-VMHost cmdlet to move it into the cluster, passing the cluster object as the location:
    Get-VMHost esxsrv1.domain.local | Move-VMHost -Destination (Get-Cluster -Name "BigCluster")
    
  4. If you had not previously added the host to vCenter, you could simply use the Add-VMHost cmdlet that you used in the Joining an ESXi host to vCenter recipe in Chapter 1, Configuring the Basic Settings of an ESXi Host with PowerCLI, and specify -Location to be our newly created cluster. In vCenter Server 6, you also need to add the -Force:$true parameter. vCenter Server 6 checks the SSL thumbprint of the host and if it's not trusted, the Add-Host cmdlet will fail. The -Force parameter will make this host add, even with an untrusted certificate.
    Add-VMHost -Name esxsrv1.domain.local -Location (Get-Cluster "BigCluster") -Force:$true
    

How it works…

Creating a cluster on vSphere is pretty simple. A cluster can exist without any hosts in it, but there's no reason to set up empty clusters. Adding hosts to the cluster begins to build a functional pool of resources for your virtual machines to share.

Creating a cluster only needs a location and a name. Everything beyond these parameters is optional, but you can get much more detailed information if you like by enabling and configuring advanced features, such as DRS and HA, from the same cmdlet.

There's more…

In the previous chapter, we covered how to add an individual host to vCenter and configure multiple hosts with the same configuration. This recipe takes a step further and allows you to create clusters using individual ESXi hosts with similar configurations.

Admitting the first host into a cluster is simple from PowerCLI, but it certainly has implications for the new cluster. The first host of the cluster defines some things about the cluster and determines what can be added in the future. Hosts should contain compatible processors or should have other settings configured to make disliked processors from the same vendor more compatible with each other. These settings are EVC settings and we will cover these in the next recipe.

See also

  • The Joining an ESXi host to vCenter and Creating a configuration script to set all properties uniformly recipes in Chapter 1, Configuring the Basic Settings of an ESXi Host with PowerCLI