Service Fabric 应用程序升级Service Fabric application upgrade

Azure Service Fabric 应用程序是多个服务的集合。An Azure Service Fabric application is a collection of services. 在升级期间,Service Fabric 将新的应用程序清单与以前的版本进行比较,并确定应用程序中的哪些服务需要升级。During an upgrade, Service Fabric compares the new application manifest with the previous version and determines which services in the application require updates. Service Fabric 会将服务清单中的版本号与前一版中的版本号进行比较。Service Fabric compares the version numbers in the service manifests with the version numbers in the previous version. 如果服务未更改,则不升级服务。If a service has not changed, that service is not upgraded.

滚动升级概述Rolling upgrades overview

在应用程序滚动升级过程中,分阶段进行升级。In a rolling application upgrade, the upgrade is performed in stages. 在每个阶段,对群集中的部分节点进行升级,这一部分节点称为更新域。At each stage, the upgrade is applied to a subset of nodes in the cluster, called an update domain. 因此,应用程序在整个升级过程中保持可用。As a result, the application remains available throughout the upgrade. 升级期间,群集中可能混合了新旧版本。During the upgrade, the cluster may contain a mix of the old and new versions.

因此,两个版本均必须可向前和向后兼容。For that reason, the two versions must be forward and backward compatible. 如果它们不兼容,则由应用程序管理员负责分阶段进行多阶段升级,以保持可用性。If they are not compatible, the application administrator is responsible for staging a multiple-phase upgrade to maintain availability. 在多阶段升级中,第一个步骤是升级到与以前版本兼容的应用程序中间版本。In a multiple-phase upgrade, the first step is upgrading to an intermediate version of the application that is compatible with the previous version. 第二个步骤是升级与更新前的版本不兼容、但与中间版本兼容的最终版本。The second step is to upgrade the final version that breaks compatibility with the pre-update version, but is compatible with the intermediate version.

在配置群集时在群集清单中指定更新域。Update domains are specified in the cluster manifest when you configure the cluster. 更新域不按特定的顺序接收更新。Update domains do not receive updates in a particular order. 更新域是应用程序部署的逻辑单元。An update domain is a logical unit of deployment for an application. 更新域可让服务在升级过程中保持高可用性。Update domains allow the services to remain at high availability during an upgrade.

如果对群集中的所有节点应用升级,即应用程序只有一个更新域,将不可能进行任何滚动升级。Non-rolling upgrades are possible if the upgrade is applied to all nodes in the cluster, which is the case when the application has only one update domain. 由于服务会关闭,并且在升级时不可用,因此不建议此方法。This approach is not recommended, since the service goes down and isn't available at the time of upgrade. 此外,当仅为群集设置了一个更新域时,Azure 不提供任何保证。Additionally, Azure doesn't provide any guarantees when a cluster is set up with only one update domain.

升级完成后,所有的服务和副本(实例)将会保持相同版本,也就是说,如果升级成功,它们会更新到新版本;如果升级失败并回滚,它们会降回到旧版本。After the upgrade completes, all the services and replicas(instances) would stay in the same version-i.e., if the upgrade succeeds, they will be updated to the new version; if the upgrade fails and is rolled back, they would be rolled back to the old version.

升级过程中的运行状况检查Health checks during upgrades

必须对升级设置运行状况策略(或者可使用默认值)。For an upgrade, health policies have to be set (or default values may be used). 当所有更新域均在指定的超时内进行了升级,并且所有更新域均被认为运行正常时,即可称升级为成功升级。An upgrade is termed successful when all update domains are upgraded within the specified time-outs, and when all update domains are deemed healthy. 运行正常的更新域是指该更新域通过了运行状况策略中指定的所有运行状况检查。A healthy update domain means that the update domain passed all the health checks specified in the health policy. 例如,运行状况策略可能要求应用程序实例中的所有服务都必须运行正常,因为运行状况是由 Service Fabric 定义的。For example, a health policy may mandate that all services within an application instance must be healthy, as health is defined by Service Fabric.

升级期间 Service Fabric 执行的运行状况策略和检查与服务和应用程序无关。Health policies and checks during upgrade by Service Fabric are service and application agnostic. 也就是说,不会执行任何特定于服务的测试。That is, no service-specific tests are done. 例如,服务可能有吞吐量方面的要求,但 Service Fabric 并不提供用于检查吞吐量的信息。For example, your service might have a throughput requirement, but Service Fabric does not have the information to check throughput. 有关要执行的检查,请参阅运行状况文章Refer to the health articles for the checks that are performed. 在升级期间执行的检查包括是否已正确复制应用程序包、是否已启动实例,等等。The checks that happen during an upgrade include tests for whether the application package was copied correctly, whether the instance was started, and so on.

应用程序运行状况是应用程序子实体的聚合。The application health is an aggregation of the child entities of the application. 简单地说,Service Fabric 通过应用程序报告的运行状况来评估应用程序的运行状况。In short, Service Fabric evaluates the health of the application through the health that is reported on the application. 它还以这种方式评估应用程序的所有服务的运行状况。It also evaluates the health of all the services for the application this way. Service Fabric 通过聚合子实体(如服务副本)的运行状况进一步评估应用程序服务的运行状况。Service Fabric further evaluates the health of the application services by aggregating the health of their children, such as the service replica. 一旦符合应用程序运行状况策略,便可继续升级。Once the application health policy is satisfied, the upgrade can proceed. 如果违反运行状况策略,则应用程序升级会失败。If the health policy is violated, the application upgrade fails.

升级模式Upgrade modes

建议的应用程序升级模式为受监视模式,这是最常用的模式。The mode that we recommend for application upgrade is the monitored mode, which is the commonly used mode. 受监视模式对一个更新域执行升级,如果所有运行状况检查均通过(按指定的策略),则自动移动到下一个更新域。Monitored mode performs the upgrade on one update domain, and if all health checks pass (per the policy specified), moves on to the next update domain automatically. 如果运行状况检查失败和/或达到超时,则更新域的升级会回滚,或者模式更改为不受监视的手动模式。If health checks fail and/or time-outs are reached, the upgrade is either rolled back for the update domain, or the mode is changed to unmonitored manual. 可以将升级配置为在升级失败时选择这两种模式之一。You can configure the upgrade to choose one of those two modes for failed upgrades.

不受监视的手动模式在每次对更新域升级之后都需要人工干预,以开始进行下一个更新域的升级。Unmonitored manual mode needs manual intervention after every upgrade on an update domain, to kick off the upgrade on the next update domain. 系统不会执行任何 Service Fabric 运行状况检查。No Service Fabric health checks are performed. 管理员开始在下一个更新域中升级之前,需执行状况或状态检查。The administrator performs the health or status checks before starting the upgrade in the next update domain.

升级默认服务Upgrade default services

在应用程序升级过程中,还可以升级在应用程序清单中定义的某些默认服务参数。Some default service parameters defined in the application manifest can also be upgraded as part of an application upgrade. 在升级过程中,只能更改支持通过 Update-ServiceFabricService 进行更改的服务参数。Only the service parameters that support being changed through Update-ServiceFabricService can be changed as part of an upgrade. 在应用程序升级过程中更改默认服务的行为如下所述:The behavior of changing default services during application upgrade is as follows:

  1. 创建新的应用程序清单中在群集中尚不存在的默认服务。Default services in the new application manifest that do not already exist in the cluster are created.
  2. 更新在以前的和新的应用程序清单中都存在的默认服务。Default services that exist in both the previous and new application manifests are updated. 新的应用程序清单中默认服务的参数将覆盖现有服务的参数。The parameters of the default service in the new application manifest overwrite the parameters of the existing service. 如果更新某个默认服务失败,则会自动回滚应用程序升级。The application upgrade will rollback automatically if updating a default service fails.
  3. 新的应用程序清单中不存在的默认服务将被删除(如果它们存在于群集中)。Default services that do not exist in the new application manifest are deleted if they exist in the cluster. 请注意,删除某个默认服务将导致删除该服务的所有状态,并且无法撤消。Note that deleting a default service will result in deleting all that service's state and cannot be undone.

当回滚应用程序升级时,会将默认服务参数恢复为开始升级之前的旧值,但是无法使用已删除服务的旧状态重新创建这些服务。When an application upgrade is rolled back, default service parameters are reverted back to their old values before the upgrade started but deleted services cannot be re-created with their old state.


EnableDefaultServicesUpgrade 群集配置设置必须为 true 才能启用上面的规则 2) 和 3)(默认服务更新和删除)。The EnableDefaultServicesUpgrade cluster config setting must be true to enable rules 2) and 3) above (default service update and deletion). 从 Service Fabric 版本 5.5 开始,将支持此功能。This feature is supported starting in Service Fabric version 5.5.

使用 HTTPS 终结点升级多个应用程序Upgrading multiple applications with HTTPS endpoints

请注意,使用 HTTPS 时,不要将相同端口用于同一应用程序的不同实例。You need to be careful not to use the same port for different instances of the same application when using HTTPS. 原因是,Service Fabric 无法升级应用程序实例之一的证书。The reason is that Service Fabric won't be able to upgrade the cert for one of the application instances. 例如,如果应用程序 1 或应用程序 2 都要将证书 1 升级为证书 2。For example, if application 1 or application 2 both want to upgrade their cert 1 to cert 2. 升级时,Service Fabric 可能已使用 http.sys 清除了证书 1 注册,即使其他应用程序仍在使用它,也不例外。When the upgrade happens, Service Fabric might have cleaned up the cert 1 registration with http.sys even though the other application is still using it. 为了防止发生这种情况,Service Fabric 检测到另一个应用程序实例已在带证书的端口上注册(由于 http.sys),导致操作失败。To prevent this, Service Fabric detects that there is already another application instance registered on the port with the certificate (due to http.sys) and fails the operation.

因此,Service Fabric 不支持通过以下方法升级两个不同的服务:在不同的应用程序实例中使用同一端口 。Hence Service Fabric does not support upgrading two different services using the same port in different application instances. 也就是说,不能对同一端口上的不同服务使用同一证书。In other words, you cannot use the same certificate on different services on the same port. 如果需要在同一端口上使用共享证书,请务必将服务放置在具有放置约束的不同计算机上。If you need to have a shared certificate on the same port, you need to ensure that the services are placed on different machines with placement constraints. 或者,如果可以,考虑将 Service Fabric 动态端口用于每个应用程序实例中的各个服务。Or consider using Service Fabric dynamic ports if possible for each service in each application instance.

如果 https 升级失败,则会看到内容为“Windows HTTP Server API 不支持对共享端口的应用程序使用多个证书”的错误警告。If you see an upgrade fail with https, an error warning saying "The Windows HTTP Server API does not support multiple certificates for applications that share a port."

应用程序升级流程图Application upgrade flowchart

本段落后面的流程图可帮助理解 Service Fabric 应用程序的升级过程。The flowchart following this paragraph can help you understand the upgrade process of a Service Fabric application. 具体而言,该流程描述当一个更新域的升级被认为成功或失败时,超时(包括 HealthCheckStableDurationHealthCheckRetryTimeoutUpgradeHealthCheckInterval)如何为控制提供帮助。In particular, the flow describes how the time-outs, including HealthCheckStableDuration, HealthCheckRetryTimeout, and UpgradeHealthCheckInterval, help control when the upgrade in one update domain is considered a success or a failure.

Service Fabric 应用程序的升级过程

后续步骤Next steps

使用 Visual Studio 升级应用程序逐步讲解了如何使用 Visual Studio 进行应用程序升级。Upgrading your Application Using Visual Studio walks you through an application upgrade using Visual Studio.

使用 PowerShell 升级应用程序逐步讲解了如何使用 PowerShell 进行应用程序升级。Upgrading your Application Using PowerShell walks you through an application upgrade using PowerShell.

使用升级参数来控制应用程序的升级方式。Control how your application upgrades by using Upgrade Parameters.

了解如何使用数据序列化,使应用程序在升级后保持兼容。Make your application upgrades compatible by learning how to use Data Serialization.

参考高级主题,了解如何在升级应用程序时使用高级功能。Learn how to use advanced functionality while upgrading your application by referring to Advanced Topics.

参考对应用程序升级进行故障排除中的步骤来解决应用程序升级时的常见问题。Fix common problems in application upgrades by referring to the steps in Troubleshooting Application Upgrades.