Muokkaa

Jaa


Open an application port in the Azure load balancer

A Service Fabric application running in Azure sits behind the Azure load balancer. This sample script opens a port in an Azure load balancer so that a Service Fabric application can communicate with external clients. Customize the parameters as needed. If your cluster is in a network security group, also add an inbound network security group rule to allow inbound traffic.

Note

We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

If needed, install the Service Fabric PowerShell module with the Service Fabric SDK.

Sample script

# Variables
$probename = "AppPortProbe6"
$rulename="AppPortLBRule6"
$RGname="mysftestclustergroup"
$port=8303
$subscriptionID = 'subscription ID'

# Login and select your subscription
Connect-AzAccount
Get-AzSubscription -SubscriptionId $subscriptionID | Select-AzSubscription 

# Get the load balancer resource
$resource = Get-AzResource | Where {$_.ResourceGroupName –eq $RGname -and $_.ResourceType -eq "Microsoft.Network/loadBalancers"} 
$slb = Get-AzLoadBalancer -Name $resource.Name -ResourceGroupName $RGname

# Add a new probe configuration to the load balancer
$slb | Add-AzLoadBalancerProbeConfig -Name $probename -Protocol Tcp -Port $port -IntervalInSeconds 15 -ProbeCount 2

# Add rule configuration to the load balancer
$probe = Get-AzLoadBalancerProbeConfig -Name $probename -LoadBalancer $slb
$slb | Add-AzLoadBalancerRuleConfig -Name $rulename -BackendAddressPool $slb.BackendAddressPools[0] -FrontendIpConfiguration $slb.FrontendIpConfigurations[0] -Probe $probe -Protocol Tcp -FrontendPort $port -BackendPort $port

# Set the goal state for the load balancer
$slb | Set-AzLoadBalancer

Script explanation

This script uses the following commands. Each command in the table links to command-specific documentation.

Command Notes
Get-AzResource Gets an Azure resource.
Get-AzLoadBalancer Gets the Azure load balancer.
Add-AzLoadBalancerProbeConfig Adds a probe configuration to a load balancer.
Get-AzLoadBalancerProbeConfig Gets a probe configuration for a load balancer.
Add-AzLoadBalancerRuleConfig Adds a rule configuration to a load balancer.
Set-AzLoadBalancer Sets the goal state for a load balancer.

Next steps

For more information on the Azure PowerShell module, see Azure PowerShell documentation.

Additional PowerShell samples for Azure Service Fabric can be found in the Azure PowerShell samples.