Publish Service Fabric Application to All Nodes in a Cluster

In my previous article, we discussed how to create Service Fabric Asp.Net Core web application and how to publish to the local 5-Node cluster. Today also we use the same example and will discuss how to publish the application to all nodes. Create service fabric Asp.Net Core MVC web application and publish to the 5-Node local cluster.

As you see here, the application published to Node_2 (it may differ on your machine) and all other nodes “Health State” set to Warning

 

To publish the application into all available nodes, edit Local.5Node.xml file. Open Local.5Node.xml  file check the SimpleWeb_InstanceCount value. By default it is set “1”, that means deploy application to single node only. To deploy the application into all available nodes, set SimpleWeb_InstanceCount value to -1.

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/ServiceFabricAspNetCoreWeb" xmlns="http://schemas.microsoft.com/2011/01/fabric">
  <Parameters>
    <Parameter Name="SimpleWeb_ASPNETCORE_ENVIRONMENT" Value="Development" />
    <Parameter Name="SimpleWeb_InstanceCount" Value="-1" />
  </Parameters>
</Application>

Publish the application to local cluster and check whether application is deployed to all nodes or not in local cluster.

Notice that, still application deployed to single port Node_2 and all other nodes “Health State” showing as Warning. It is because all application instances are trying to bind same port 9010 (it may differ in your case). We are getting this issue because we are running multiple nodes on a single machine and only one port 9010 is available. In a real-time multi-host cluster, it may not happen.

To resolve this issue, open ServiceManifest.xml and remove Port element for Endpoint tag as shown below. When we don’t mention any port number, service fabric allows random port numbers for each node.

<Resources>
    <Endpoints>
      <Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input"/>
    </Endpoints>
  </Resources>

Let’s publish the application and check whether the application published to all nodes or not.

As shown above, our application deployed to all nodes on different ports, and all nodes are active. You can browse your application on all these ports.