将应用程序部署到 Service Fabric 群集

此示例 Service Fabric SDK PowerShell 脚本将应用程序包复制到群集映像存储,在群集中注册应用程序类型,删除不必要的应用程序包,并从应用程序类型创建应用程序实例。 如果目标应用程序类型的应用程序清单中定义了任何默认服务,则此时还会创建那些服务。 根据需要自定义参数。

必要时,使用 Service Fabric SDK 安装 Service Fabric PowerShell 模块。

示例脚本

# Variables
$endpoint = 'mysftestcluster.chinaeast.cloudapp.chinacloudapi.cn:19000'
$thumbprint = '2779F0BB9A969FB88E04915FFE7955D0389DA7AF'
$packagepath="C:\Users\sfuser\Documents\Visual Studio 2017\Projects\MyApplication\MyApplication\pkg\Release"

# Connect to the cluster using a client certificate.
Connect-ServiceFabricCluster -ConnectionEndpoint $endpoint `
          -KeepAliveIntervalInSec 10 `
          -X509Credential -ServerCertThumbprint $thumbprint `
          -FindType FindByThumbprint -FindValue $thumbprint `
          -StoreLocation CurrentUser -StoreName My

# Copy the application package to the cluster image store.
Copy-ServiceFabricApplicationPackage $packagepath -ImageStoreConnectionString fabric:ImageStore -ApplicationPackagePathInImageStore MyApplication

# Register the application type.
Register-ServiceFabricApplicationType -ApplicationPathInImageStore MyApplication

# Remove the application package to free system resources.
Remove-ServiceFabricApplicationPackage -ImageStoreConnectionString fabric:ImageStore -ApplicationPackagePathInImageStore MyApplication

# Create the application instance.
New-ServiceFabricApplication -ApplicationName fabric:/MyApplication -ApplicationTypeName MyApplicationType -ApplicationTypeVersion 1.0.0

整理部署

运行脚本示例后,可以使用删除应用程序中的脚本删除应用程序实例,取消注册应用程序类型,并从映像存储中删除应用程序包。

脚本说明

此脚本使用以下命令。 表中的每条命令均链接到特定于命令的文档。

Command 注释
Connect-ServiceFabricCluster 与 Service Fabric 群集建立连接。
Copy-ServiceFabricApplicationPackage 将应用程序包复制到群集映像存储。
Register-ServiceFabricApplicationType 在群集上注册应用程序类型和版本。
New-ServiceFabricApplication 从注册的应用程序类型创建应用程序。
Remove-ServiceFabricApplicationPackage 从映像存储区中删除 Service Fabric 应用程序包。

后续步骤

有关 Service Fabric SDK PowerShell 模块的详细信息,请参阅 SDK PowerShell 文档

有关 Service Fabric Azure PowerShell 模块的详细信息,请参阅 Azure PowerShell 文档

可以在 PowerShell 示例中找到 Service Fabric 的其他 PowerShell 示例