You can give the cluster name and VM credentials.
You can choose the Node type now. There are 3 types of node type counts. We chose node type count as 1. Also, give the node type name. Currently, node type name is restricted to 9 characters.
We can choose the VM size now. Currently, there are 9 types of VM available. I chose the basic type. I will get 2 cores per node and 8GB per VM.
We can choose a number of VMs. I chose the default 5. It will create 5 nodes in the Fabric cluster.
After choosing the VM count, you can click the OK button to proceed.
We can create a Key vault for security purpose. This key vault and Certificate will be used later.
We can give a name to the key vault and click “Create” button to proceed.
After creating the key vault you must edit the access policies.
We can select the first two access policies and click the “Save” button to proceed. Azure Disk Encryption is not needed currently.
We can give a certificate name and click the “OK” button to proceed.
It will take some time to create our certificate and we can download this certificate for future usage. This certificate will be used later with our cluster. Please click the provided link to download the certificate.
The link to download certificate will be opened in a separate tab and you can download the certificate by clicking the “Download as a certificate” button.
After downloading the certificate please come to the previous page and click the “Create” button to create our Service Fabric Cluster.
It will take some time to complete the deployment of our Cluster.
Meantime, we can install the certificate to our windows machine. Double click the certificate file which we already downloaded from Azure Portal.
Choose store location as “Current User” and click “Next” button to proceed.
Keep password as empty and click “Next” button to proceed.
Click “Next” button to proceed and in the next page press “Finish” button to complete the certificate import.
Cluster deployment will be finished soon. You can see all the resources listed in the Azure. Please note for one cluster, there are a total of 8 resources created in Azure. 1 Public IP Address, 1 Load balancer, 1 Virtual machine scale set, 1 Key vault, 2 Storage accounts, 1 Virtual network along with our cluster.
You can see there are 5 active nodes available in the cluster.
We can copy URL of the Service Fabric Explorer and open the cluster dashboard in a browser. While opening the Service Fabric Explorer, it will ask your certificate. Please choose the existing certificate we already installed to our system.
Please note that 5 nodes are active and no application is hosted yet in this cluster.
We can open Visual Studio 2017 in Administrator mode (It is very important, we need administrator rights later for PowerShell commands) and open our existing .NET core application. (We already created a sample .NET Core application and I explained in my previous C# Corner article). We can publish the application by right-clicking the microservice project and choosing “Publish”.
You can choose the Azure profile and we can see the recently created Service Fabric Cluster available there. Please choose the Cluster and click “Publish” button to proceed.
It will take some time to finish the deployment.
If you go to service fabric explorer, you can see that the new application is listed there now.
We can open the MVC project (SarathMicroService) in the solution and under PackageRoot folder and Config folder there isServiceManifest.xml file available. Please open that configuration file.
Inside that file Input, Port is mentioned automatically by the system. It varies from project to project. Please note down this Port number. We will use this Port number in Load balancer rule.
ServiceManifest.xml
- <?xml version="1.0" encoding="utf-8"?>
- <ServiceManifest Name="SarathMicroServicePkg" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <ServiceTypes>
- <!-- This is the name of your ServiceType.
- This name must match the string used in RegisterServiceType call in Program.cs. -->
- <StatelessServiceType ServiceTypeName="SarathMicroServiceType" />
- </ServiceTypes>
- <!-- Code package is your service executable. -->
- <CodePackage Name="Code" Version="1.0.0">
- <EntryPoint>
- <ExeHost>
- <Program>SarathMicroService.exe</Program>
- <WorkingFolder>CodePackage</WorkingFolder>
- </ExeHost>
- </EntryPoint>
- <EnvironmentVariables>
- <EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="" />
- </EnvironmentVariables>
- </CodePackage>
- <!-- Config package is the contents of the Config directoy under PackageRoot that contains an
- independently-updateable and versioned set of custom configuration settings for your service. -->
- <ConfigPackage Name="Config" Version="1.0.0" />
- <Resources>
- <Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to listen- . Please note that if your service is partitioned, this port is shared with replicas of different partitions that are placed in your code. -->
- <Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input" Port="8281" />
- </Endpoints>
- </Resources>
- </ServiceManifest>
We can go to Azure Portal again and choose Load balancer from resource list. Please open it by double clicking and again click “Load balancing rules” tab.
It will open existing rules inside the load balancer. Currently, there are two rules available for this load balancer. You can open the first rule.
We can modify the Port number with “80” and Backend port with “8281” (We already noted this Port number from our ASP.NET Core application)
You can click the “Save” Button to apply these new port numbers to load balancer.
You can check the running application by opening in a browser. (Without https) Our application is running fine.
In this article, we saw how to create a Service Fabric Cluster in the Azure portal and we created the Cluster with 5 nodes. We also saw how to create Azure Keyvault and Certificate with Cluster. Later we opened our existing ASP.NET Core application in Visual Studio 2017 and published to Azure Service Fabric Cluster. We configured the Load balancer rule with our application’s Input Port and we successfully executed our application in Service Fabric Cluster.