将应用程序和服务作为 Azure 资源管理器资源进行管理Manage applications and services as Azure Resource Manager resources

可以通过 Azure 资源管理器,将应用程序和服务部署到 Service Fabric 群集。You can deploy applications and services onto your Service Fabric cluster via Azure Resource Manager. 也就是说,现在可以使用 JSON 表示应用程序和服务,并在群集使用的同一个资源管理器模板中部署它们,而不用被迫等待群集就绪,然后再通过 PowerShell 或 CLI 部署和管理应用程序。This means that instead of deploying and managing applications via PowerShell or CLI after having to wait for the cluster to be ready, you can now express applications and services in JSON and deploy them in the same Resource Manager template as your cluster. 只需执行一步操作,即可完成注册、预配和部署应用程序的整个过程。The process of application registration, provisioning, and deployment all happens in one step.

这是部署群集所需的任意安装应用程序、治理应用程序或群集管理应用程序的推荐方法。This is the recommended way for you to deploy any setup, governance, or cluster management applications that you require in your cluster. 其中包括修补业务流程应用程序、监视程序,或部署其他应用程序/服务前群集需要运行的任何应用程序。This includes the Patch Orchestration Application, Watchdogs, or any applications that need to be running in your cluster before other applications or services are deployed.

在适当情况下,将应用程序作为资源管理器资源进行管理可改进:When applicable, manage your applications as Resource Manager resources to improve:

  • 审核线索:资源管理器审核所有操作,并记录详细的活动日志 ,有助于跟踪对这些应用程序和群集做出的任何更改。Audit trail: Resource Manager audits every operation and keeps a detailed Activity Log that can help you trace any changes made to these applications and your cluster.
  • 基于角色的访问控制 (RBAC):可通过同一个资源管理器模板,管理对群集及其上部署的应用程序的访问。Role-based access control (RBAC): Managing access to clusters as well as applications deployed on the cluster can be done via the same Resource Manager template.
  • Azure 资源管理器(通过 Azure 门户)成为管理群集和关键应用程序部署的一站式平台。Azure Resource Manager (via Azure portal) becomes a one-stop-shop for managing your cluster and critical application deployments.

下面的代码片段展示了可以通过模板管理的各种资源:The following snippet shows the different kinds of resources that can be managed via a template:

{
    "apiVersion": "2019-03-01",
    "type": "Microsoft.ServiceFabric/clusters/applicationTypes",
    "name": "[concat(parameters('clusterName'), '/', parameters('applicationTypeName'))]",
    "location": "[variables('clusterLocation')]",
},
{
    "apiVersion": "2019-03-01",
    "type": "Microsoft.ServiceFabric/clusters/applicationTypes/versions",
    "name": "[concat(parameters('clusterName'), '/', parameters('applicationTypeName'), '/', parameters('applicationTypeVersion'))]",
    "location": "[variables('clusterLocation')]",
},
{
    "apiVersion": "2019-03-01",
    "type": "Microsoft.ServiceFabric/clusters/applications",
    "name": "[concat(parameters('clusterName'), '/', parameters('applicationName'))]",
    "location": "[variables('clusterLocation')]",
},
{
    "apiVersion": "2019-03-01",
    "type": "Microsoft.ServiceFabric/clusters/applications/services",
    "name": "[concat(parameters('clusterName'), '/', parameters('applicationName'), '/', parameters('serviceName'))]",
    "location": "[variables('clusterLocation')]"
}

将新应用程序添加到资源管理器模板Add a new application to your Resource Manager template

  1. 准备群集的资源管理器模板,以供部署时使用。Prepare your cluster's Resource Manager template for deployment. 若要详细了解如何执行此操作,请参阅使用 Azure 资源管理器创建 Service Fabric 群集See Create a Service Fabric cluster by using Azure Resource Manager for more information on this.

  2. 考虑一下,打算在群集中部署的一些应用程序。Think about some of the applications you plan on deploying in the cluster. 是否有始终要运行的被其他应用程序依赖的应用程序?Are there any that will always be running that other applications may take dependencies on? 是否计划部署任何群集治理应用程序或安装应用程序?Do you plan on deploying any cluster governance or setup applications? 如上所述,此类应用程序最好是通过资源管理器模板进行管理。These sorts of applications are best managed via a Resource Manager template, as discussed above.

  3. 确定要使用此方法部署的应用程序后,需要立即打包、压缩这些应用程序,并将它们上传到文件共享。Once you have figured out what applications you want to be deployed this way, the applications have to be packaged, zipped, and put on a file share. 此共享必须可通过 REST 终结点进行访问,这样 Azure 资源管理器才能在部署期间使用它。The share needs to be accessible through a REST endpoint for Azure Resource Manager to consume during deployment.

  4. 在资源管理器模板中的群集声明下,描述每个应用程序的属性。In your Resource Manager template, below your cluster declaration, describe each application's properties. 这些属性包括副本或实例计数,以及资源(其他应用程序或服务)之间的任何依赖链。These properties include replica or instance count and any dependency chains between resources (other applications or services). 有关完整属性列表,请参阅 REST API Swagger 规范。请注意,这不会取代应用程序或服务清单,只是在群集的资源管理器模板中描述了清单的部分内容。For a list of comprehensive properties, see the REST API Swagger Spec. Note that this does not replace the Application or Service manifests, but rather describes some of what is in them as part of the cluster's Resource Manager template. 下面展示了示例模板,包括在 Application1 中部署无状态服务 Service1 和有状态服务 Service2 :Here is a sample template that includes deploying a stateless service Service1 and a stateful service Service2 as part of Application1:

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "clusterName": {
        "type": "string",
        "defaultValue": "Cluster",
        "metadata": {
          "description": "Name of your cluster - Between 3 and 23 characters. Letters and numbers only."
        }
      },
      "applicationTypeName": {
        "type": "string",
        "defaultValue": "ApplicationType",
        "metadata": {
          "description": "The application type name."
        }
      },
      "applicationTypeVersion": {
        "type": "string",
        "defaultValue": "1",
        "metadata": {
          "description": "The application type version."
        }
      },
      "appPackageUrl": {
        "type": "string",
        "metadata": {
          "description": "The URL to the application package sfpkg file."
        }
      },
      "applicationName": {
        "type": "string",
        "defaultValue": "Application1",
        "metadata": {
          "description": "The name of the application resource."
        }
      },
      "serviceName": {
        "type": "string",
        "defaultValue": "Application1~Service1",
        "metadata": {
          "description": "The name of the service resource in the format of {applicationName}~{serviceName}."
        }
      },
      "serviceTypeName": {
        "type": "string",
        "defaultValue": "Service1Type",
        "metadata": {
          "description": "The name of the service type."
        }
      },
      "serviceName2": {
        "type": "string",
        "defaultValue": "Application1~Service2",
        "metadata": {
          "description": "The name of the service resource in the format of {applicationName}~{serviceName}."
        }
      },
      "serviceTypeName2": {
        "type": "string",
        "defaultValue": "Service2Type",
        "metadata": {
          "description": "The name of the service type."
        }
      }
    },
    "variables": {
      "clusterLocation": "[resourcegroup().location]"
    },
    "resources": [
      {
        "apiVersion": "2019-03-01",
        "type": "Microsoft.ServiceFabric/clusters/applicationTypes",
        "name": "[concat(parameters('clusterName'), '/', parameters('applicationTypeName'))]",
        "location": "[variables('clusterLocation')]",
        "dependsOn": [],
        "properties": {
          "provisioningState": "Default"
        }
      },
      {
        "apiVersion": "2019-03-01",
        "type": "Microsoft.ServiceFabric/clusters/applicationTypes/versions",
        "name": "[concat(parameters('clusterName'), '/', parameters('applicationTypeName'), '/', parameters('applicationTypeVersion'))]",
        "location": "[variables('clusterLocation')]",
        "dependsOn": [
          "[concat('Microsoft.ServiceFabric/clusters/', parameters('clusterName'), '/applicationTypes/', parameters('applicationTypeName'))]"
        ],
        "properties": {
          "provisioningState": "Default",
          "appPackageUrl": "[parameters('appPackageUrl')]"
        }
      },
      {
        "apiVersion": "2019-03-01",
        "type": "Microsoft.ServiceFabric/clusters/applications",
        "name": "[concat(parameters('clusterName'), '/', parameters('applicationName'))]",
        "location": "[variables('clusterLocation')]",
        "dependsOn": [
          "[concat('Microsoft.ServiceFabric/clusters/', parameters('clusterName'), '/applicationTypes/', parameters('applicationTypeName'), '/versions/', parameters('applicationTypeVersion'))]"
        ],
        "properties": {
          "provisioningState": "Default",
          "typeName": "[parameters('applicationTypeName')]",
          "typeVersion": "[parameters('applicationTypeVersion')]",
          "parameters": {},
          "upgradePolicy": {
            "upgradeReplicaSetCheckTimeout": "01:00:00.0",
            "forceRestart": "false",
            "rollingUpgradeMonitoringPolicy": {
              "healthCheckWaitDuration": "00:02:00.0",
              "healthCheckStableDuration": "00:05:00.0",
              "healthCheckRetryTimeout": "00:10:00.0",
              "upgradeTimeout": "01:00:00.0",
              "upgradeDomainTimeout": "00:20:00.0"
            },
            "applicationHealthPolicy": {
              "considerWarningAsError": "false",
              "maxPercentUnhealthyDeployedApplications": "50",
              "defaultServiceTypeHealthPolicy": {
                "maxPercentUnhealthyServices": "50",
                "maxPercentUnhealthyPartitionsPerService": "50",
                "maxPercentUnhealthyReplicasPerPartition": "50"
              }
            }
          }
        }
      },
      {
        "apiVersion": "2019-03-01",
        "type": "Microsoft.ServiceFabric/clusters/applications/services",
        "name": "[concat(parameters('clusterName'), '/', parameters('applicationName'), '/', parameters('serviceName'))]",
        "location": "[variables('clusterLocation')]",
        "dependsOn": [
          "[concat('Microsoft.ServiceFabric/clusters/', parameters('clusterName'), '/applications/', parameters('applicationName'))]"
        ],
        "properties": {
          "provisioningState": "Default",
          "serviceKind": "Stateless",
          "serviceTypeName": "[parameters('serviceTypeName')]",
          "instanceCount": "-1",
          "partitionDescription": {
            "partitionScheme": "Singleton"
          },
          "correlationScheme": [],
          "serviceLoadMetrics": [],
          "servicePlacementPolicies": []
        }
      },
      {
        "apiVersion": "2019-03-01",
        "type": "Microsoft.ServiceFabric/clusters/applications/services",
        "name": "[concat(parameters('clusterName'), '/', parameters('applicationName'), '/', parameters('serviceName2'))]",
        "location": "[variables('clusterLocation')]",
        "dependsOn": [
          "[concat('Microsoft.ServiceFabric/clusters/', parameters('clusterName'), '/applications/', parameters('applicationName'))]"
        ],
        "properties": {
          "provisioningState": "Default",
          "serviceKind": "Stateful",
          "serviceTypeName": "[parameters('serviceTypeName2')]",
          "targetReplicaSetSize": "3",
          "minReplicaSetSize": "2",
          "replicaRestartWaitDuration": "00:01:00.0",
          "quorumLossWaitDuration": "00:02:00.0",
          "standByReplicaKeepDuration": "00:00:30.0",
          "partitionDescription": {
            "partitionScheme": "UniformInt64Range",
            "count": "5",
            "lowKey": "1",
            "highKey": "5"
          },
          "hasPersistedState": "true",
          "correlationScheme": [],
          "serviceLoadMetrics": [],
          "servicePlacementPolicies": [],
          "defaultMoveCost": "Low"
        }
      }
    ]
    }
    

    备注

    必须将 apiVersion 设置为 "2019-03-01"The apiVersion must be set to "2019-03-01". 部署的此模板也可以与群集互不影响,只要群集已部署即可。This template can also be deployed independently of the cluster, as long as the cluster has already been deployed.

  5. 部署!Deploy!

删除 Service Fabric 资源提供程序应用程序资源Remove Service Fabric Resource Provider Application resource

以下命令将触发从群集取消预配应用程序包,这将清理已用的磁盘空间:The following will trigger the app package to be un-provisioned from the cluster, and this will clean up the disk space used:

Get-AzureRmResource -ResourceId /subscriptions/{sid}/resourceGroups/{rg}/providers/Microsoft.ServiceFabric/clusters/{cluster}/applicationTypes/{apptType}/versions/{version} -ApiVersion "2019-03-01" | Remove-AzureRmResource -Force -ApiVersion "2017-07-01-preview"

只是从 ARM 模板中删 Microsoft.ServiceFabric/clusters/application 就不会取消预配应用程序Simply removing Microsoft.ServiceFabric/clusters/application from your ARM template will not unprovision the Application

备注

删除完成后,你应该不会再在 SFX 或 ARM 中看到包版本。Once the removal is complete you should not see the package version in SFX or ARM anymore. 你不能删除应用程序运行所使用的应用程序类型版本资源;ARM/SFRP 将阻止此操作。You cannot delete the application type version resource that the application is running with; ARM/SFRP will prevent this. 如果你尝试取消预配正在运行的包,SF 运行时将阻止此操作。If you try to unprovision the running package, SF runtime will prevent it.

通过资源管理器管理现有应用程序Manage an existing application via Resource Manager

如果群集已部署,且其上已部署一些要作为资源管理器资源进行管理的应用程序,可以使用相同的 API,将这些应用程序确定为资源管理器资源,从而执行 PUT 调用,而不用删除并重新部署应用程序。If your cluster is already up and some applications that you would like to manage as Resource Manager resources are already deployed on it, instead of removing the applications and redeploying them, you can use a PUT call using the same APIs to have the applications get acknowledged as Resource Manager resources. 有关更多信息,请参阅什么是 Service Fabric 应用程序资源模型?For additional information, refer to What is the Service Fabric application resource model?

备注

若要允许群集升级忽略不正常的应用程序,可以在“upgradeDescription/healthPolicy”部分中指定“maxPercentUnhealthyApplications:100”,Service Fabrics REST API 群集升级策略文档中介绍了所有设置的详细说明。To allow a cluster upgrade to ignore unhealthy apps the customer can specify "maxPercentUnhealthyApplications: 100" in the "upgradeDescription/healthPolicy" section; detailed descriptions for all settings are in Service Fabrics REST API Cluster Upgrade Policy documentation.

后续步骤Next steps