it:ad:azure:iaas:howto:load_balancer:home

IT:AD:Azure:IaaS:Load Balancer

Creating Load Balancers is currently done only by script (no IT:AD:Azure:Portal experience). Once created, can be managed via IT:AD:Azure:Portal).

Login.ps1
# Login to your Azure Account:
Login-AzureRmAccount
DefineAResourceGroupNameVariable.ps1
# $rgName = "[...]"
$rgName = “OpsVmRmRg”
ListTheNetworkInterfacesNames.ps1
Get-AzureRmNetworkInterface -ResourceGroupName $rgName | select name
configuration.ps1
# Non deployment specific
#$rgName  = "OpsVMRmRG" 
 
# Deployment specific
$publicIpName = "opsstaticip";
$uniqueDns = "[unique DNS name]"
$vmNic1    = "[ nic 1 place holder ]"
$vmNic2    = "webVMNIC2"
$location  = "[azure region name]"
OpsTraining.json
...
configure-azure-load-balancer.ps1
$ErrorActionPreference = 'Stop'
Select-AzureRmProfile -Path "$PSScriptRoot\OpsTraining.json"
 
 
 
# Create a new public static IP address 
$pip = New-AzureRmPublicIpAddress -Name $publicIpName `
                                  -ResourceGroupName $rgName `
                                  -AllocationMethod Static `
                                  -DomainNameLabel $uniqueDns `
                                  -Location $location 
 
 
# Create the front end configuration for the load balancer
# Associated with the public IP just created
$frontEndIP = New-AzureRmLoadBalancerFrontendIpConfig -Name "LBFE" `
                                                      -PublicIpAddress $pip    
 
# Create the backend configuration object
$beAddressPool = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name "LBBE"
 
# Create RDP rules for each VM
$inboundNATRule1= New-AzureRmLoadBalancerInboundNatRuleConfig -Name "RDP1" `
                                            -FrontendIpConfiguration $frontendIP `
                                            -Protocol TCP `
                                            -FrontendPort 3441 `
                                            -BackendPort 3389
 
$inboundNATRule2= New-AzureRmLoadBalancerInboundNatRuleConfig -Name "RDP2" `
                                            -FrontendIpConfiguration $frontendIP `
                                            -Protocol TCP `
                                            -FrontendPort 3442 `
                                            -BackendPort 3389 
 
# Create a HTTP health probe for port 80
$healthProbe = New-AzureRmLoadBalancerProbeConfig -Name "HealthProbe" `
                                                -RequestPath "/" `
                                                -Protocol http `
                                                -Port 80 `
                                                -IntervalInSeconds 15 `
                                                -ProbeCount 2 
 
# Create a load balanced rule for port 80 
$lbrule = New-AzureRmLoadBalancerRuleConfig -Name "HTTP" `
                                          -FrontendIpConfiguration $frontendIP `
                                          -BackendAddressPool $beAddressPool `
                                          -Probe $healthProbe `
                                          -Protocol Tcp `
                                          -FrontendPort 80 `
                                          -BackendPort 80 
 
 
# Create the load balancer 
$NRPLB = New-AzureRmLoadBalancer -ResourceGroupName $rgName `
                               -Name "OPSLB" `
                               -Location $location `
                               -FrontendIpConfiguration $frontendIP `
                               -InboundNatRule $inboundNATRule1,$inboundNatRule2 `
                               -LoadBalancingRule $lbrule `
                               -BackendAddressPool $beAddressPool `
                               -Probe $healthProbe  
 
 
# Associate the network interfaces with the load balancer 
$nic1 = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $vmNic1
$nic2 = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $vmNic2
 
$nic1.IpConfigurations[0].LoadBalancerBackendAddressPools = $NRPLB.BackendAddressPools[0]
$nic1.IpConfigurations[0].LoadBalancerInboundNatRules     = $NRPLB.InboundNatRules[0]
$nic2.IpConfigurations[0].LoadBalancerBackendAddressPools = $NRPLB.BackendAddressPools[0]
$nic2.IpConfigurations[0].LoadBalancerInboundNatRules     = $NRPLB.InboundNatRules[1]
 
# Update the network interface configuration
Set-AzureRmNetworkInterface -NetworkInterface $nic1
Set-AzureRmNetworkInterface -NetworkInterface $nic2
  • /home/skysigal/public_html/data/pages/it/ad/azure/iaas/howto/load_balancer/home.txt
  • Last modified: 2023/11/04 02:44
  • by 127.0.0.1