使用PowerShell将应用程序部署到服务结构

时间:2019-04-10 01:56:10

标签: powershell azure-service-fabric

我在Azure中启动并运行了服务结构。另外,我还有带有两个项目的Visual Studio解决方案:Service Fabric和Web Service。 我想以天蓝色将服务部署到服务结构。 当我右键单击我的服务结构项目并单击“发布”时,该服务将顺利部署到云结构。我想对PowerShell进行同样的操作。

似乎我需要运行此脚本:

# 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 $packagename

# Register the application type.
Register-ServiceFabricApplicationType -ApplicationPathInImageStore $packagename

# Create the service instance.
$appName = <name that I see in fabric explorer under 'typeName' in azure>
New-ServiceFabricService -ApplicationName fabric:/$appName -ServiceName fabric:/$appName/MyApp -ServiceTypeName $serviceTypeName -Stateless -PartitionSchemeSingleton -InstanceCount -1

在运行脚本之前,我右键单击我的Fabric应用程序,然后选择“包”。

我脚本的最后一个命令失败,并显示“找不到应用程序”

可能缺少什么?

2 个答案:

答案 0 :(得分:3)

构建并准备好软件包后,可以尝试使用以下命令来使用PowerShell脚本部署pkg。

如果您尚未尝试以下选项,请尝试以下方法,看看是否可行。

要运行脚本,需要满足一些先决条件:

  • 您已启动集群并正在运行。

  • 集群已部署了所有必需的证书(例如用于SSL的证书) 端点(如果有))

  • 您已经准备好ARM模板和参数文件。

  • 您具有部署新资源的必要权限, 即贡献者角色(在订阅或资源级别上 组)

  • 您已经创建了目标资源组

检查以上内容后,执行以下命令:

Copy-ServiceFabricApplicationPackage

Register-ServiceFabricApplicationType

New-ServiceFabricApplication

如果这对您不起作用,请浏览以下站点以查看是否有帮助。

Deploy applications using PowerShell

Deploy resources with Resource Manager templates and Azure PowerShell

答案 1 :(得分:0)

问题是我在命令ApplicationName中使用了错误的ServiceNameNew-ServiceFabricService

为了找出正确的值,我运行了Get-ServiceFabricApplicationGet-ServiceFabricService

这些页面对于构建脚本疑难解答非常有用:

相关问题