[Service Fabric] Auto-scaling your VMSS

Like most people, whenever I need to build an ARM template to do something with Service Fabric, I'm browsing around Github or where ever else I can find the bits and pieces of JSON that I need.

I was recently working on a project where they needed 3 things:

  1. They wanted their Service Fabric cluster to use managed disks instead of Azure Storage accounts.
  2. They wanted to have auto-scaling setup for their virtual machine scale set (VMSS). In this case, we were using a CPU rule
  3. They had a stateless service where they wanted to register their service event source to output logging information in to the WADETWEventTable.

This template includes those 3 implementations. You can find a link to the files here https://github.com/larrywa/blogpostings/tree/master/VMSSScaleTemplate.

A little more detail…

Using managed disks

You need to find the location in your JSON file, in the Microsoft.Compute/virtualMachineScaleSets resource provider and make the following modifications.


Another important setting you need to make sure you have is the overProvision = false setting (here placed in a variable)


This variable is actually used in the Microsoft.Compute/virtualMachineScaleSets resource provider properties:


More information about overprovisioning can be found here https://docs.microsoft.com/en-us/rest/api/compute/virtualmachinescalesets/create-or-update-a-set, but if this setting is missing or set to true, you may see more than the requested number of machines and nodes created at deployment and then the ones that are not in use are turned off. This will cause errors to appear in the Service Fabric Explorer. Service Fabric will eventually go behind and clean up itself but when you first see the errors, you'll think you did something wrong.

Setting Up Auto-scale on your VMSS

At first my idea was to go to my existing cluster, turn on auto-scaling inside of the VMSS settings and then export the template from the Azure portal. I then discovered that my subscription did not have permission to use the microsoft.insights resource provider. Not sure you'll run in to this, but if you do you can either enable it in the portal under Subscriptions -> your subscription -> Resource providers -> Microsoft.Insights.

The 'microsoft.insights/autoscalesettings' resource provider is placed at the same level in the JSON file as the other major resource providers like the cluster, virtual machine scale set etc, so, this scaleset, although it is found as a setting for the scaleset, is not a sub-section of the resource provider for the VMSS.

In the Json outline editor, the auto-scale resource will look like this:


There is a rule with conditions for scaling up and scaling down based on CPU metrics. Before deployments, go in and set your own desired levels in the capacity area, line 823.

Registering your Event Source provider

To register an event source provider, you need to add your event source provider to the Microsoft.Compute/virtualMachineScaleSets resource provider in the Microsoft.Azure.Diagnostics section.


You will of course need to make sure that the 'provider' listed above matches the EventSource name in your ServiceEventSource.cs file of your service.


For deployment, there is a deploy.ps1 PowerShell script included but you can really deploy the ARM template with whatever script you normally would use for your other ARM templates.

Hope this helps you in your Service Fabric cluster deployments!

Comments (0)

Skip to main content