Graceful rolling deployment in Kubernetes divides a complete release process into multiple batches. One batch is released each time. After all batches are released, the graceful rolling deployment is complete. Microservices Engine (MSE) provides graceful start capabilities that allow applications to be registered with MSE instances and prefetched before the readiness probe. This ensures that available instances of an application are running during a graceful rolling deployment. This topic describes how to implement graceful rolling deployment.
Prerequisites
Microservices Governance is activated. For more information, see Activate Microservices Governance.
Microservices Governance is enabled for microservice applications in a Container Service for Kubernetes (ACK) cluster. For more information, see Enable Microservices Governance for microservice applications in an ACK cluster.
Precautions
The low-traffic service prefetching feature is designed for scenarios where microservice applications are run. To allow the system to complete service prefetching before the readiness probe, take note of the following points:
- You can enable the service prefetching feature for only Dubbo 2.7 applications. Dubbo 2.6 or 3.0 applications do not support the service prefetching feature.
- You can enable the service prefetching feature for only the Spring Cloud applications that are registered with Nacos or ZooKeeper instances.
- The service prefetching feature is implemented on Spring Cloud applications based on the default load balancer class ZoneAwareLoadBalancer of the Spring Cloud framework. If you change this class for your Spring Cloud application, the service prefetching feature becomes ineffective for your Spring Cloud application.
- In most cases, gateways are not called by using registries but called by exposing APIs. Therefore, the low-traffic prefetching feature provided by MSE is ineffective for gateways. The service prefetching feature is not mandatory for gateways because gateways have no major changes or complex business logic.
Complete service registration before the readiness probe
Kubernetes cannot detect the time when a microservice application instance is ready. In most cases, an application instance is considered ready if a port can be connected to the application instance. However, the application instances of the new version may not be registered with a registry before the application instances of the old version are shut down. As a result, the consumer may fail to call the provider of the new version. To address this issue, Kubernetes provides the readiness probe mechanism that allows you to perform a health check on an application instance. If the health check is successful, the application instance is considered ready.
MSE provides a feature that aligns the microservice lifecycle with Kubernetes readiness probe. If you enable this feature, MSE provides a port by using agents. The port is used to detect whether an application instance is registered with a registry. This way, no code changes are required. If MSE detects that the application instance is registered, the status code 200 is returned. If MSE detects that the application instance is not registered, the status code 500 is returned, indicating that the application instance is not ready.
Log on to the MSE console, and select a region in the top navigation bar.
In the left-side navigation pane, choose . On the page that appears, click the resource card of the application that you want to manage.
On the application details page, click Traffic management in the left-side navigation pane, and click the Lossless up and down line tab.
In the Graceful Start section, configure Preheating duration (seconds) and Delayed registration time (seconds). Then, click Advanced Settings and turn on the switch on the right side of Complete service registration before passing the readiness check.
Turn on the switch on the right side of Graceful Start.
After the application is restarted, the system can complete service registration before the readiness probe.
Log on to the ACK console, configure the readiness probe for the destination application, and then update the configuration.
Select Enable on the right side of Readiness and configure the following parameters:
Path: Enter /health in the field.
Port: Enter 55199 in the field.
Retain default values for other parameters.
For more information about the parameters, see Deploy a stateless application from an image.
After the application is restarted, the system can complete service registration before the readiness probe.
Complete service prefetching before the readiness probe
In addition to the separate use of the low-traffic service prefetching and delayed service registration features, you can associate the features with the Kubernetes readiness probe mechanism in complex online scenarios. The Kubernetes readiness probe succeeds if service prefetching is complete. This ensures that the application becomes ready after service prefetching is complete.
Log on to the MSE console, and select a region in the top navigation bar.
In the left-side navigation pane, choose . On the page that appears, click the resource card of the application that you want to manage.
On the application details page, click Traffic management in the left-side navigation pane, and click the Lossless up and down line tab.
In the Graceful Start section, configure Preheating duration (seconds) and Delayed registration time (seconds). Then, click Advanced Settings and turn on the switch on the right side of Complete service warm-up before passing the readiness check.
Turn on the switch on the right side of Graceful Start.
Log on to the ACK console, configure the readiness probe for the destination application, and then update the configuration.
Select Enable on the right side of Readiness and configure the following parameters:
Path: Enter /health in the field.
Port: Enter 55199 in the field.
Retain default values for other parameters.
For more information about the parameters, see Deploy a stateless application from an image.
After the application is restarted, the system can complete service prefetching before the readiness probe.