You can connect Spring Cloud applications to Alibaba Cloud Service Mesh (ASM) so that you can use cloud-native service governance capabilities to manage Spring Cloud services without modifying business code. This topic describes how to use ASM to manage Spring Cloud services.
Prerequisites
- An ASM instance of Enterprise Edition or Ultimate Edition is created. For more information, see Create an ASM instance.
- A Container Service for Kubernetes (ACK) cluster is created. For more information, see Create an ACK managed cluster.
- The ACK cluster is added to the ASM instance. For more information, see Add a cluster to an ASM instance.
Background information
Spring Cloud is a standard with different implementations, such as Spring Cloud Netflix,
Spring Cloud Alibaba, and Spring Cloud Consul. For ASM, the core difference among
different Spring Cloud implementations is that they use different registries. The
following table describes whether ASM supports migration between registries for different
Spring Cloud versions.
Spring Cloud version | Registry | Whether migration is supported without code modification |
---|---|---|
Spring Cloud Alibaba | Microservice Engine (MSE) Nacos (an Alibaba Cloud service) | Supported |
Spring Cloud Alibaba | Self-managed Nacos | Supported |
Spring Cloud Netflix | Eureka | Not supported. We recommend that you use Nacos as the registry. |
Spring Cloud Consul | Consul | Not supported. We recommend that you use Nacos as the registry. |
Spring Cloud Zookeeper | Zookeeper | Not supported. We recommend that you use Nacos as the registry. |
Demo introduction
You can download the sample files for the Spring Cloud services that are deployed in this topic from the nacos-examples directory on GitHub.
The Spring Cloud services involved include a consumer service and a provider service.
The provider service has two versions: V1 and V2. Both versions of the provider service
are registered with the Nacos registry. The consumer service synchronizes the endpoints
of the two versions of the provider service from the Nacos registry and sends requests
to the endpoints in a load balancing manner. The consumer service exposes port 8080
and provides an echo interface. After the requests are forwarded to the provider service,
the provider service returns corresponding responses, and then the consumer service
delivers the responses. Different versions of the provider service return different
responses.
- The provider service of V1 responds to an echo request with the following information:
Hello Nacos Discovery From v1xxx
. - The provider service of V2 responds to an echo request with the following information:
Hello Nacos Discovery From v2xxx
.
The 
xxx
string in a response indicates the specific parameter in the corresponding echo request.
For example, if the /echo/world request is sent to the provider service of V1, the Hello Nacos Discovery From v1world
response is returned. 
Step 1: Configure a service entry and an Envoy filter
You must configure a service entry and an Envoy filter in ASM so that ASM can manage Spring Cloud services.
- Use kubectl to connect to an ASM instance.
- Create a service entry.
- Create an Envoy filter.
Step 2: Create Spring Cloud services in an ACK cluster
Note
- The registration process needs to be intercepted. Therefore, you must create an Envoy filter before you create deployments. If specific deployments are created before you create the Envoy filter, you must enable rolling update for the deployments.
- For Spring Cloud services, you must create Kubernetes service resources and provide a cluster IP address.
Step 3: Create a gateway rule and a virtual service
- Use kubectl to connect to an ASM instance.
- Create a gateway rule.
- Create a virtual service.
Step 4: Check whether ASM can manage the Spring Cloud services
FAQ
What do I do if the Spring Cloud services that I deployed by following the steps in
this topic do not take effect?
- Check whether throttling is enabled for the port or IP address of Nacos.
- Make sure that an Envoy filter is created before you create deployments so as to intercept the registration process. If specific deployments are created before you create the Envoy filter, you must enable rolling update for the deployments.
- Check whether you have created Kubernetes service resources and provided a cluster IP address for the Spring Cloud services.
- Make sure that the client SDK of Nacos is of a version earlier than V2.0. The client SDK of V2.0 or later uses gRPC to connect to the server, which is beyond the application scope of the solution provided in this topic.