SpringCloud Consul Registry Integration
In this doc, we will demonstrate integrating Spring Cloud Consul microservices into the service mesh and testing the commonly used canary release scenario.
Demo Application
For the demonstration of Spring Cloud microservices integration into the service mesh, we have rewritten the classic BookStore application https://github.com/flomesh-io/springboot-bookstore-demo.
The application currently supports both Netflix Eureka and HashiCorp Consul registries (switchable at compile time), and specific usage can be referred to in the documentation.
Prerequisites
- Kubernetes cluster
- kubectl CLI
- FSM CLI
Initialization
First, clone the repository.
Then deploy Consul using a single-node instance for simplicity.
Deploying FSM
Deploy the control plane and connectors with the following parameters:
fsm.serviceAccessMode
: The service access mode,mixed
indicates support for accessing services using both Service names and pod IPs.fsm.deployConsulConnector
: Deploy the Consul connector.fsm.cloudConnector.consul.deriveNamespace
: The namespace where the encapsulated Consul services as K8s Services will reside.fsm.cloudConnector.consul.httpAddr
: The HTTP address for Consul.fsm.cloudConnector.consul.passingOnly
: Synchronize only the healthy service nodes.fsm.cloudConnector.consul.suffixTag
: By default, the Consul connector creates a Service in the specified namespace with the same name as the service. For canary releases, synchronized Services for different versions are needed, such asbookstore-v1
,bookstore-v2
for different versions ofbookstore
. ThesuffixTag
denotes using the service node’stag
version
value as the service name suffix. In the example application, the version tag is specified by adding the environment variableSPRING_CLOUD_CONSUL_DISCOVERY_TAGS="version=v1"
to the service nodes.
Next, create the namespace specified above and bring it under the management of the service mesh.
Configuring Access Control Policies
By default, services within the mesh can access services outside the mesh; however, the reverse is not allowed. Therefore, set up access control policies to allow Consul to access microservices within the mesh for health checks.
Deploying Applications
Create namespaces and add them to the mesh.
Deploy the applications.
In the consul-derive
namespace, you can see the synchronized Services.
Use port forwarding or create Ingress rules to view the running services: the page auto-refreshes and the counter increases continuously.
Canary Release Testing
Next is the common scenario for canary releases. Referencing FSM documentation examples, we use weight-based canary releases.
Before releasing a new version, create TrafficSplit bookstore-v1
to ensure all traffic routes to bookstore-v1
:
Then deploy the new version bookstore-v2
:
At this point, viewing the bookstore-v2
page via port forwarding reveals no change in the counter, indicating no traffic is entering the new version of the service node.
Next, modify the traffic split strategy to route 50% of the traffic to the new version, and you will see the bookstore-v2
counter begin to increase.
Continue adjusting the strategy to route 100% of the traffic to the new version. The counter for the old version bookstore-v1
will cease to increase.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.