Open ports for a Service Fabric cluster

The load balancer deployed with your Azure Service Fabric cluster directs traffic to your app running on a node. If you change your app to use a different port, you must expose that port (or route a different port) in the Azure Load Balancer.

When you deployed your Service Fabric cluster to Azure, a load balancer was automatically created for you. If you do not have a load balancer, see Configure an Internet-facing load balancer.

Note

This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.

Configure service fabric

Your Service Fabric application ServiceManifest.xml config file defines the endpoints your application expects to use. After the config file has been updated to define an endpoint, the load balancer must be updated to expose that (or a different) port. For more information on how to create the service fabric endpoint, see Setup an Endpoint.

Create a load balancer rule

A Load Balancer rule opens up an internet-facing port and forwards traffic to the internal node's port used by your application. If you do not have a load balancer, see Configure an Internet-facing load balancer.

To create a Load Balancer rule, you need to collect the following information:

  • Load balancer name.
  • Resource group of the load balancer and service fabric cluster.
  • External port.
  • Internal port.

Azure CLI

It only takes a single command to create a load balancer rule with the Azure CLI. You just need to know both the name of the load balancer and resource group to create a new rule.

Note

If you need to determine the name of the load balancer, use this command to quickly get a list of all load balancers and the associated resource groups.

az network lb list --query "[].{ResourceGroup: resourceGroup, Name: name}"

az network lb rule create --backend-port 40000 --frontend-port 39999 --protocol Tcp --lb-name LB-svcfab3 -g svcfab_cli -n my-app-rule

The Azure CLI command has a few parameters that are described in the following table:

Parameter Description
--backend-port The port the Service Fabric application is listening to.
--frontend-port The port the load balancer exposes for external connections.
-lb-name The name of the load balancer to change.
-g The resource group that has both the load balancer and Service Fabric cluster.
-n The desired name of the rule.

Note

For more information on how to create a load balancer with the Azure CLI, see Create a load balancer with the Azure CLI.

PowerShell

PowerShell is a little more complicated than the Azure CLI. Follow these conceptual steps to create a rule:

  1. Get the load balancer from Azure.
  2. Create a rule.
  3. Add the rule to the load balancer.
  4. Update the load balancer.

Note

If you need to determine the name of the load balancer, use this command to quickly get a list of all load balancers and associated resource groups.

Get-AzLoadBalancer | Select Name, ResourceGroupName

# Get the load balancer
$lb = Get-AzLoadBalancer -Name LB-svcfab3 -ResourceGroupName svcfab_cli

# Create the rule based on information from the load balancer.
$lbrule = New-AzLoadBalancerRuleConfig -Name my-app-rule7 -Protocol Tcp -FrontendPort 39990 -BackendPort 40009 `
                                            -FrontendIpConfiguration $lb.FrontendIpConfigurations[0] `
                                            -BackendAddressPool  $lb.BackendAddressPools[0] `
                                            -Probe $lb.Probes[0]

# Add the rule to the load balancer
$lb.LoadBalancingRules.Add($lbrule)

# Update the load balancer on Azure
$lb | Set-AzLoadBalancer

Regarding the New-AzLoadBalancerRuleConfig command, the -FrontendPort represents the port the load balancer exposes for external connections, and the -BackendPort represents the port the service fabric app is listening to.

Note

For more information on how to create a load balancer with PowerShell, see Create a load balancer with PowerShell.

Next steps

Learn more about networking in Service Fabric.