HDInsight: Scale Horizontally

HDInsight: Scale Horizontally with Scale-HDInsightClusterNodes.ps1 a PowerShell workflow that will help you automate the process of scaling your cluster.

The script receives 4 parameters:

  • ResourceGroupName: The name of the resource group where the cluster resides
  • ClusterName: The name of your HDInsight cluster
  • Nodes: The number of nodes you want for the cluster
  • ConnectionName: The name of your automation connection account

and requires the following powershell modules: AzureRM.Profile, AzureRM.HDInsight

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
    .SYNOPSIS
        Scale-HDInsightClusterNodes is a simple PowerShell workflow runbook that will help you automate the process of scaling in or out your HDInsight clusters depending on your needs.
 
    .DESCRIPTION
        Scale-HDInsightClusterNodes is a simple PowerShell workflow runbook that will help you automate the process of scaling in or out your HDInsight clusters depending on your needs.
 
    .PARAMETER ResourceGroupName
        The name of the resource group where the cluster resides
 
    .PARAMETER ClusterName
        The name of your HDInsight cluster
 
    .PARAMETER Nodes
        The number of nodes you want for the cluster
 
    .PARAMETER ConnectionName
        The name of your automation connection account
 
    .NOTES 
        AUTHOR: Carlos Mendible 
        LASTEDIT: June 13, 2017 
#>
Workflow Scale-HDInsightClusterNodes {
    Param
    (   
        [Parameter(Mandatory = $true)]
        [String]$ResourceGroupName,
 
        [Parameter(Mandatory = $true)]
        [String]$ClusterName,
 
        [Parameter(Mandatory = $true)]
        [Int]$Nodes,
 
        [Parameter(Mandatory = $false)]
        [String]$ConnectionName
    )
 
    # This Workflow requieres the following powershell modules: AzureRM.Profile, AzureRM.HDInsight
 
    $automationConnectionName = $ConnectionName
    if (!$ConnectionName) {
        $automationConnectionName = "AzureRunAsConnection"
    }
 
    # Get the connection by name (i.e. AzureRunAsConnection)
    $servicePrincipalConnection = Get-AutomationConnection -Name $automationConnectionName         
 
    Write-Output "Logging in to Azure..."
 
    Add-AzureRmAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
 
    Write-Output "Scaling cluster $ClusterName to $Nodes nodes..."
    Set-AzureRmHDInsightClusterSize `
        -ResourceGroupName $ResourceGroupName `
        -ClusterName $ClusterName `
        -TargetInstanceCount $Nodes
}

You can download the script from the Technet Script Gallery, import it as a runbook for your automation account in the Azure portal or simply copy the code from this post.

Hope it helps!

Leave a Reply

Your email address will not be published. Required fields are marked *