Seven deployment strategies for Service Fabric

I've finished two hackfests with our partners as a DevOps evangelist. During the hackfest, I find some typical patterns that they want to know. I'd like to share these. I hope you like this.

1. Simple Deployment Pipeline

People want to know the typical CI/CD pipeline for Service Fabric. When you try Service Fabric,
I strongly recommend VSTS (Visual Studio Team Services). It is the SaaS version of the TFS.

It supports Service Fabric tasks. Since Service Fabric is brand new product, it keeps on developing.
You might not want to catch up these changes. The VSTS help you to catch up these change to supports
through Service Fabric tasks. Also it has template of CI/CD pipeline for Service Fabric. It is deadly
easy.

slide2

The Concept of the basic CI / CD pipeline for the Service Fabric is simple. Build and Release.
I recommend to separate a build and release. Generally speaking, you don't want to deploy it every time,
when you commit your code into Git. Build is in charge of Build/Test the artifact. You can create it
using the Service Fabric Template. The artifact that you built is sent to the shared place. We often
call it 'drop' folder. The artifact is uploaded into the folder.

slide1

Then, you go Release. Using the artifact, you deploy the artifact using Service Fabric deployment tasks. You can create several releases for the same artifact. You might want to deploy Dev / QA / Staging / Production environment. Or you might have several Live sites. You can create several release depend on your needs.

For the detail, you can refer https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-set-up-continuous-integration Also, you might have a problem of writing a unit test. You can refer

https://azure.microsoft.com/en-us/resources/samples/service-fabric-dotnet-web-reference-app/

This is bit old however, you may understand the overview by my blog.

https://blogs.technet.microsoft.com/livedevopsinjapan/2016/09/02/unit-testing-for-microsoft-azure-service-fabric/

You can cover a lot of use cases only for this simple pipeline strategy.

2. Multi-Tenant Deployment

Some people want to have the multi-tenant depoyment. If you develop a SaaS application, you may
need this strategy. Let me explain how to get multi-tenant environment using Service Fabric.

When you deploy Service Fabric Application via Visual Studio, you can deploy it via publish command.
It fires a powershell for deployment. We can decompose the deployment process.

1. Connect to a Service Fabric Cluster
2. Copy your Application Package into the Cluster
3. Register your Application Type
4. Create the Application instance

On the step 4. You can create several application instances from your Application Type. Which means
you can create an application instance for one tenant. If you create several applications, it means
multi-tenant. Service Fabric allow you to have several application type version. So you can manage
multi-tenant environment very easily.

Let's take a look for multi-tenant application deployment step via PowerShell command.

 PS> Connect-ServiceFabricCluster -ConnectionEndpoint 'idealcluster.westus.cloudapp.azure.com:19000' -FindType FindByThumbprint -FindValue "{Cert Thumbprint here}" -X509Credential -StoreLocation CurrentUser -StoreName MY -ServerCertThumbprint "{CertThumbprint here}"<br>PS> Copy-ServiceFabricApplicationPackage -ApplicationPackagePath . -ImageStoreConnectionString "fabric:ImageStore" -ApplicationPackagePathInImageStore ActorTicTacToeApplicationType<br>PS> Register-ServiceFabricApplicationType -ApplicationPathInImageStore ActorTicTacToeApplicationType

registerapps

Then instantiate your applications for tenants.

 PS> New-ServiceFabricApplication fabric:/tenant1 ActorTicTacToeApplicationType "1.0.2" 

multitenant

If you want to remove the application

 PS> Remove-ServiceFabricApplication 'fabric:/tenant1' 

You can get the Tic-Tac-Toe application via this git hub.

https://github.com/TsuyoshiUshio/AzureServiceFabricSample

In this case, you need to manage database connection by your self. Because you can't change
property files for an instance.

3. OnPremise deployment

If you want to go an OnPremise Service Fabric cluster, you can use VSTS build agent.
You can use it on your OnPremise environment. If you want to deploy a Service Fabric application into yor
cluster, the client should be reachable to the cluster endpoint. Then you can use the same strategy as the
simple deployment pipeline.

slide3

Also, if you want to know how to upgrade your Service Fabric cluster. We don't have any grace shout down for
whole cluster. However, you can upgrade cluster node one by one. You can use this power shell for this reason.
Then you can achieve zero-downtime upgrade.

4. Provisioning the Secure Service Fabric cluster

You can use several measure to deploy a Service Fabric cluster. I recommend to go Azure portal.
Wait! Do I foreget about Infrastructure as Code? No worries. You can generate ARM template before
you deploying it. The cluster is managed. It is automatically upgraded by default.

armsave

You just save it. The next time, you can provision it using PowerShell or Azure CLI.

directory

However, currently, If you want a secure Service Fabric cluster, you need to deploye Resource Group and KeyVault
first. Also, you need to store certificate on it. It is annoying process. So I wrote a powershell that you can
easily understand what it looks like.

Secure Cluster Script for Service Fabric

5. Provisioning the Secure Service Fabric Cluster via VSTS deployment pipeline

Also, you can use VSTS to deployment as a release pipeline. I recommend you to include the ARM template
on your repository. Then you can deploy it via VSTS relase management.

rm

6. Blue Green Deployment

You might want to Blue Green Deployment. Since Service Fabric has Stateful Service and Reliable Acotor, ususal
Blue Green Deployment strategy doesn't work. You can refer this article.

Blue/Green Deployments in Service Fabric Blue/Green Deployments with Azure ServiceFabric

7. Feature Flags

You might want to do a continuous deployment to the environment, I recommend the Feature Flags. I recommend to use Launch Darkly. It is integrated with VSTS. You can also use it for A/B testing, beta testing and Canary testing.
You might also try Trunk Based Development. It will accelerate your lead time.

deploymentstrategy Enabling Trunk Based Development with Deployment Pipelines Launch Darkly

LaunchDarkly Integration (VSTS)

Conclusion

The Service Fabric is brand new product. However, you can pick several strategy for deployment. The Service Fabric
already implement Fault Injection via PowerShell Command let and Rolling Update feature. You can easily to deploy
your Microservices. I hope you enjoy this technology.