PageRenderTime 38ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/articles/service-fabric/service-fabric-get-started-with-a-local-cluster.md

https://gitlab.com/yeah568/azure-content
Markdown | 219 lines | 140 code | 79 blank | 0 comment | 0 complexity | 2df3d163ea9bd5417caabe5f55b86ba3 MD5 | raw file
  1. <properties
  2. pageTitle="Get started with deploying and upgrading apps on your local cluster | Microsoft Azure"
  3. description="Set up a local Service Fabric cluster, deploy an existing application to it, and then upgrade that application."
  4. services="service-fabric"
  5. documentationCenter=".net"
  6. authors="rwike77"
  7. manager="timlt"
  8. editor=""/>
  9. <tags
  10. ms.service="service-fabric"
  11. ms.devlang="dotNet"
  12. ms.topic="get-started-article"
  13. ms.tgt_pltfrm="NA"
  14. ms.workload="NA"
  15. ms.date="06/09/2016"
  16. ms.author="ryanwi"/>
  17. # Get started with deploying and upgrading applications on your local cluster
  18. The Azure Service Fabric SDK includes a full local development environment that you can use to quickly get started with deploying and managing applications on a local cluster. In this article, you will create a local cluster, deploy an existing application to it, and then upgrade that application to a new version, all from Windows PowerShell.
  19. > [AZURE.NOTE] This article assumes that you already [set up your development environment](service-fabric-get-started.md).
  20. ## Create a local cluster
  21. A Service Fabric cluster represents a set of hardware resources that you can deploy applications to. Typically, a cluster is made up of anywhere from five to many thousands of machines. However, the Service Fabric SDK includes a cluster configuration that can run on a single machine.
  22. It is important to understand that the Service Fabric local cluster is not an emulator or simulator. It runs the same platform code that is found on multi-machine clusters. The only difference is that it runs the platform processes that are normally spread across five machines on one machine.
  23. The SDK provides two ways to set up a local cluster: a Windows PowerShell script and the Local Cluster Manager system tray app. In this tutorial, we will use the PowerShell script.
  24. > [AZURE.NOTE] If you have already created a local cluster by deploying an application from Visual Studio, you can skip this section.
  25. 1. Launch a new PowerShell window as an administrator.
  26. 2. Run the cluster setup script from the SDK folder:
  27. ```powershell
  28. & "$ENV:ProgramFiles\Microsoft SDKs\Service Fabric\ClusterSetup\DevClusterSetup.ps1"
  29. ```
  30. Cluster setup will take a few moments. After setup is finished, you should see output that looks something like this:
  31. ![Cluster setup output][cluster-setup-success]
  32. You are now ready to try deploying an application to your cluster.
  33. ## Deploy an application
  34. The Service Fabric SDK includes a rich set of frameworks and developer tooling for creating applications. If you are interested in learning how to create applications in Visual Studio, see [Create your first Service Fabric application in Visual Studio](service-fabric-create-your-first-application-in-visual-studio.md).
  35. In this tutorial, we will use an existing sample application (called WordCount) so that we can focus on the management aspects of the platform--including deployment, monitoring, and upgrade.
  36. 1. Launch a new PowerShell window as an administrator.
  37. 2. Import the Service Fabric SDK PowerShell module.
  38. ```powershell
  39. Import-Module "$ENV:ProgramFiles\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1"
  40. ```
  41. 3. Create a directory to store the application that you will download and deploy, such as C:\ServiceFabric.
  42. ```powershell
  43. mkdir c:\ServiceFabric\
  44. cd c:\ServiceFabric\
  45. ```
  46. 4. [Download the WordCount application](http://aka.ms/servicefabric-wordcountapp) to the location you created. Note: the Microsoft Edge browser will save the file with a *.zip* extension. You will need to change the file extension to *.sfpkg*.
  47. 5. Connect to the local cluster:
  48. ```powershell
  49. Connect-ServiceFabricCluster localhost:19000
  50. ```
  51. 6. Invoke the SDK's deployment command to create a new application by providing a name and a path to the application package.
  52. ```powershell
  53. Publish-NewServiceFabricApplication -ApplicationPackagePath c:\ServiceFabric\WordCountV1.sfpkg -ApplicationName "fabric:/WordCount"
  54. ```
  55. If all goes well, you should see output like the following:
  56. ![Deploy an application to the local cluster][deploy-app-to-local-cluster]
  57. 7. To see the application in action, launch the browser and navigate to [http://localhost:8081/wordcount/index.html](http://localhost:8081/wordcount/index.html). You should see something like this:
  58. ![Deployed application UI][deployed-app-ui]
  59. The WordCount application is very simple. It includes client-side JavaScript code to generate random five-character "words", which are then relayed to the application via ASP.NET Web API. A stateful service keeps track of the number of words counted. They are partitioned based on the first character of the word. You can find the source code for the WordCount app in the [getting started samples](https://azure.microsoft.com/documentation/samples/service-fabric-dotnet-getting-started/).
  60. The application that we deployed contains four partitions. So words beginning with A through G are stored in the first partition, words beginning with H through N are stored in the second partition, and so on.
  61. ## View application details and status
  62. Now that we have deployed the application, let's look at some of the app details in PowerShell.
  63. 1. Query all deployed applications on the cluster:
  64. ```powershell
  65. Get-ServiceFabricApplication
  66. ```
  67. Assuming that you have only deployed the WordCount app, you will see something like this:
  68. ![Query all deployed applications in PowerShell][ps-getsfapp]
  69. 2. Go to the next level by querying the set of services that are included in the WordCount application.
  70. ```powershell
  71. Get-ServiceFabricService -ApplicationName 'fabric:/WordCount'
  72. ```
  73. ![List services for the application in PowerShell][ps-getsfsvc]
  74. Note that the application is made up of two services--the web front end and the stateful service that manages the words.
  75. 3. Finally, take a look at the list of partitions for WordCountService:
  76. ```powershell
  77. Get-ServiceFabricPartition 'fabric:/WordCount/WordCountService'
  78. ```
  79. ![View the service partitions in PowerShell][ps-getsfpartitions]
  80. The set of commands that you just used, like all Service Fabric PowerShell commands, are available for any cluster that you might connect to, local or remote.
  81. For a more visual way to interact with the cluster, you can use the web-based Service Fabric Explorer tool by navigating to [http://localhost:19080/Explorer](http://localhost:19080/Explorer) in the browser.
  82. ![View application details in Service Fabric Explorer][sfx-service-overview]
  83. > [AZURE.NOTE] To learn more about Service Fabric Explorer, see [Visualizing your cluster with Service Fabric Explorer](service-fabric-visualizing-your-cluster.md).
  84. ## Upgrade an application
  85. Service Fabric provides no-downtime upgrades by monitoring the health of the application as it rolls out across the cluster. Let's perform a simple upgrade of the WordCount application.
  86. The new version of the application will now count only words that begin with a vowel. As the upgrade rolls out, we will see two changes in the application's behavior. First, the rate at which the count grows should slow, since fewer words are being counted. Second, since the first partition has two vowels (A and E) and all other partitions contain only one each, its count should eventually start to outpace the others.
  87. 1. [Download the WordCount v2 package](http://aka.ms/servicefabric-wordcountappv2) to the same location where you downloaded the v1 package.
  88. 2. Return to your PowerShell window and use the SDK's upgrade command to register the new version in the cluster. Then begin upgrading the fabric:/WordCount application.
  89. ```powershell
  90. Publish-UpgradedServiceFabricApplication -ApplicationPackagePath C:\ServiceFabric\WordCountV2.sfpkg -ApplicationName "fabric:/WordCount" -UpgradeParameters @{"FailureAction"="Rollback"; "UpgradeReplicaSetCheckTimeout"=1; "Monitored"=$true; "Force"=$true}
  91. ```
  92. You should see output in PowerShell that looks something like this as the upgrade begins.
  93. ![Upgrade progress in PowerShell][ps-appupgradeprogress]
  94. 3. While the upgrade is proceeding, you may find it easier to monitor its status from Service Fabric Explorer. Launch a browser window and navigate to [http://localhost:19080/Explorer](http://localhost:19080/Explorer). Expand **Applications** in the tree on the left, then choose **WordCount**, and finally **fabric:/WordCount**. In the essentials tab, you will see the status of the upgrade as it proceeds through the cluster's upgrade domains.
  95. ![Upgrade progress in Service Fabric Explorer][sfx-upgradeprogress]
  96. As the upgrade proceeds through each domain, health checks are performed to ensure that the application is behaving properly.
  97. 4. If you rerun the earlier query for the set of services that are included in the fabric:/WordCount application, you will notice that while the version of WordCountService changed, the version of WordCountWebService did not:
  98. ```powershell
  99. Get-ServiceFabricService -ApplicationName 'fabric:/WordCount'
  100. ```
  101. ![Query application services after upgrade][ps-getsfsvc-postupgrade]
  102. This highlights how Service Fabric manages application upgrades. It touches only the set of services (or code/configuration packages within those services) that have changed, which makes the process of upgrading faster and more reliable.
  103. 5. Finally, return to the browser to observe the behavior of the new application version. As expected, the count progresses more slowly, and the first partition ends up with slightly more of the volume.
  104. ![View the new version of the application in the browser][deployed-app-ui-v2]
  105. ## Cleaning up
  106. Before wrapping up, it's important to remember that the local cluster is very real. Applications will continue to run in the background until you remove them. Depending on the nature of your apps, a running app can take up significant resources on your machine. You have several options to manage this:
  107. 1. To remove an individual application and all of its data, run the following:
  108. ```powershell
  109. Unpublish-ServiceFabricApplication -ApplicationName "fabric:/WordCount"
  110. ```
  111. Or, use the **Delete application** action in Service Fabric Explorer either with the **ACTIONS** menu or the context menu in the application list view in the left hand pane.
  112. ![Delete an application is Service Fabric Explorer][sfe-delete-application]
  113. 2. After deleting the application from the cluster you can then unregister versions 1.0.0 and 2.0.0 of the WordCount application type. This removes the application packages, including the code and configuration, from the cluster's image store.
  114. ```powershell
  115. Remove-ServiceFabricApplicationType -ApplicationTypeName WordCount -ApplicationTypeVersion 2.0.0
  116. Remove-ServiceFabricApplicationType -ApplicationTypeName WordCount -ApplicationTypeVersion 1.0.0
  117. ```
  118. Or, in Service Fabric Explorer, choose **Unprovision Type** for the application.
  119. 3. To shut down the cluster but keep the application data and traces, click **Stop Local Cluster** in the system tray app.
  120. 4. To delete the cluster entirely, click **Remove Local Cluster** in the system tray app. Note that this option will result in another slow deployment the next time you press F5 in Visual Studio. Use this only if you don't intend to use the local cluster for some time or if you need to reclaim resources.
  121. ## Next steps
  122. - Now that you have deployed and upgraded some pre-built applications, you can [try building your own in Visual Studio](service-fabric-create-your-first-application-in-visual-studio.md).
  123. - All of the actions performed on the local cluster in this article can be performed on an [Azure cluster](service-fabric-cluster-creation-via-portal.md) as well.
  124. - The upgrade that we performed in this article was very basic. See the [upgrade documentation](service-fabric-application-upgrade.md) to learn more about the power and flexibility of Service Fabric upgrades.
  125. <!-- Images -->
  126. [cluster-setup-success]: ./media/service-fabric-get-started-with-a-local-cluster/LocalClusterSetup.png
  127. [extracted-app-package]: ./media/service-fabric-get-started-with-a-local-cluster/ExtractedAppPackage.png
  128. [deploy-app-to-local-cluster]: ./media/service-fabric-get-started-with-a-local-cluster/DeployAppToLocalCluster.png
  129. [deployed-app-ui]: ./media/service-fabric-get-started-with-a-local-cluster/DeployedAppUI-v1.png
  130. [deployed-app-ui-v2]: ./media/service-fabric-get-started-with-a-local-cluster/DeployedAppUI-PostUpgrade.png
  131. [sfx-app-instance]: ./media/service-fabric-get-started-with-a-local-cluster/SfxAppInstance.png
  132. [sfx-two-app-instances-different-partitions]: ./media/service-fabric-get-started-with-a-local-cluster/SfxTwoAppInstances-DifferentPartitionCount.png
  133. [ps-getsfapp]: ./media/service-fabric-get-started-with-a-local-cluster/PS-GetSFApp.png
  134. [ps-getsfsvc]: ./media/service-fabric-get-started-with-a-local-cluster/PS-GetSFSvc.png
  135. [ps-getsfpartitions]: ./media/service-fabric-get-started-with-a-local-cluster/PS-GetSFPartitions.png
  136. [ps-appupgradeprogress]: ./media/service-fabric-get-started-with-a-local-cluster/PS-AppUpgradeProgress.png
  137. [ps-getsfsvc-postupgrade]: ./media/service-fabric-get-started-with-a-local-cluster/PS-GetSFSvc-PostUpgrade.png
  138. [sfx-upgradeprogress]: ./media/service-fabric-get-started-with-a-local-cluster/SfxUpgradeOverview.png
  139. [sfx-service-overview]: ./media/service-fabric-get-started-with-a-local-cluster/sfx-service-overview.png
  140. [sfe-delete-application]: ./media/service-fabric-get-started-with-a-local-cluster/sfe-delete-application.png