Manage service versions

更新时间:
复制 MD 格式

In Cloud-native Gateway, service versions are primarily used for tag-based routing. Configure appropriate routing policies to enable use cases such as canary releases, tag-based routing, and high-availability deployments.

Note

Service version management is not supported for Fixed Address or DNS Domain Name services.

Background

In a microservices architecture, a service is a functional unit of an application that typically has an independent business domain, such as an order service or a user service. Physically, a service runs on containers, virtual machines, or physical machines that have network addresses. Logically, a service consists of a group of network instances that provide the same functionality.

A service version is a subset of a service's instances, grouped based on their metadata. Common use cases for service versions include canary release, tag-based routing, and high-availability deployment.

  • Canary release: To safely roll out new service versions, you can use a canary release. This strategy directs a small amount of traffic to a new version for verification. After verifying the new version works as expected, gradually migrate all traffic from the old version to the new one.

  • Tag-based routing: A service may have multiple versions with different functionalities, each intended for specific requests. For example, for the same API, requests with a specific header value are routed to a particular service version. You can also use service versions to route requests to the correct development environment, such as test, staging, or production, based on request attributes.

  • High-availability deployment: To ensure service availability, you can deploy a service across multiple Kubernetes (K8s) clusters. By treating the instances in each cluster as a separate service version, you can adjust the traffic weight routed to each cluster. If one cluster fails, you can redirect traffic by setting its weight to 0.

Service version management relies on the metadata associated with service instances.

  • For Container Service for Kubernetes (ACK), the metadata on service instances is derived from the Labels attribute of Pods. For example, if you use a Spring Cloud application associated with a Kubernetes Service, you can add a tag key and tag value under spec.template.metadata.labels in the Kubernetes Deployment YAML file.

  • For a Nacos registry, the metadata on service instances is based on the metadata that the application provides during instance registration. For example, if you use a Spring Cloud application with a Nacos registry, you can set the instance metadata by using the spring.cloud.nacos.discovery.metadata field.

Add service version

  1. Log on to the MSE console. In the top navigation bar, select a region.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.

  3. In the left-side navigation pane, click Routes. Then, click the Services tab.

  4. Click the name of the service to modify. In the Service Version section, click Add Version.

  5. In the new row that appears in the service version list, configure the parameters, and then click the 完成 icon in the Actions column.

    Parameter

    Description

    Version Name

    Enter a service version name. Use a readable, descriptive name.

    Tag Name

    The metadata keys available across all service instances. Select a key to group instances for the new version.

    Tag Value

    The values available for the selected tag key. Select a value to define the instance group for the new version.

    Number of Instances/Proportion

    • Number of instances: The number of instances that match the specified tag key and value.

    • Proportion: The percentage of the service's total instances that belong to this version.

    Note

    Tag Name and Tag Value together determine the instance set for the current version.

  6. In the confirmation dialog box, click OK.

    The new service version appears in the Service Version section.

Edit service version

  1. Log on to the MSE console. In the top navigation bar, select a region.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.

  3. In the left-side navigation pane, click Routes. Then, click the Services tab.

  4. Click the name of the service to modify. In the Service Version section, click the 编辑 icon in the Actions column.

  5. Select a new Tag Name and Tag Value, and then click the 完成 icon in the Actions column.

  6. In the confirmation dialog box, click OK.

Delete service version

  1. Log on to the MSE console. In the top navigation bar, select a region.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.

  3. In the left-side navigation pane, click Routes. Then, click the Services tab.

  4. Click the name of the service to modify. In the Service Version list, click the 删除 icon in the Actions column.

  5. In the confirmation dialog box, click OK.