-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docs for microservice discovery integration
- Loading branch information
Showing
10 changed files
with
238 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: "Integration" | ||
description: "" | ||
type: docs | ||
weight: 12 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
--- | ||
title: "SpringCloud Consul Registry Integration" | ||
description: "Efficient Integration of Consul Microservices in Service Mesh" | ||
type: docs | ||
weight: 3 | ||
--- | ||
|
||
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](https://github.com/flomesh-io/springboot-bookstore-demo#bookstore-demo). | ||
|
||
![](/images/integration/spring-cloud-bookstore.png) | ||
|
||
### Prerequisites | ||
|
||
- Kubernetes cluster | ||
- kubectl CLI | ||
- FSM CLI | ||
|
||
### Initialization | ||
|
||
First, clone the repository. | ||
|
||
```shell | ||
git clone https://github.com/flomesh-io/springboot-bookstore-demo.git | ||
``` | ||
|
||
Then deploy Consul using a single-node instance for simplicity. | ||
|
||
```shell | ||
kubectl apply -n default -f manifests/consul.yaml | ||
``` | ||
|
||
### 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 as `bookstore-v1`, `bookstore-v2` for different versions of `bookstore`. The `suffixTag` denotes using the service node's `tag` `version` value as the service name suffix. In the example application, the version tag is specified by adding the environment variable `SPRING_CLOUD_CONSUL_DISCOVERY_TAGS="version=v1"` to the service nodes. | ||
|
||
```shell | ||
export fsm_namespace=fsm-system | ||
export fsm_mesh_name=fsm | ||
export consul_svc_addr="$(kubectl get svc -l name=consul -o jsonpath='{.items[0].spec.clusterIP}')" | ||
fsm install \ | ||
--mesh-name "$fsm_mesh_name" \ | ||
--fsm-namespace "$fsm_namespace" \ | ||
--set=fsm.serviceAccessMode=mixed \ | ||
--set=fsm.deployConsulConnector=true \ | ||
--set=fsm.cloudConnector.consul.deriveNamespace=consul-derive \ | ||
--set=fsm.cloudConnector.consul.httpAddr=$consul_svc_addr:8500 \ | ||
--set=fsm.cloudConnector.consul.passingOnly=false \ | ||
--set=fsm.cloudConnector.consul.suffixTag=version \ | ||
--timeout=900s | ||
``` | ||
|
||
Next, create the namespace specified above and bring it under the management of the service mesh. | ||
|
||
```shell | ||
kubectl create namespace consul-derive | ||
fsm namespace add consul-derive | ||
kubectl patch namespace consul-derive -p '{"metadata":{"annotations":{"flomesh.io/mesh-service-sync":"consul"}}}' --type=merge | ||
``` | ||
|
||
### 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. | ||
|
||
```shell | ||
kubectl apply -n consul-derive -f - <<EOF | ||
kind: AccessControl | ||
apiVersion: policy.flomesh.io/v1alpha1 | ||
metadata: | ||
name: consul | ||
spec: | ||
sources: | ||
- kind: Service | ||
namespace: default | ||
name: consul | ||
EOF | ||
``` | ||
|
||
### Deploying Applications | ||
|
||
Create namespaces and add them to the mesh. | ||
|
||
```shell | ||
kubectl create namespace bookstore | ||
kubectl create namespace bookbuyer | ||
kubectl create namespace bookwarehouse | ||
fsm namespace add bookstore bookbuyer bookwarehouse | ||
``` | ||
|
||
Deploy the applications. | ||
|
||
```shell | ||
kubectl apply -n bookwarehouse -f manifests/consul/bookwarehouse-consul.yaml | ||
kubectl apply -n bookstore -f manifests/consul/bookstore-consul.yaml | ||
kubectl apply -n bookbuyer -f manifests/consul/bookbuyer-consul.yaml | ||
``` | ||
|
||
![](/images/integration/consul-service-list.png) | ||
|
||
In the `consul-derive` namespace, you can see the synchronized Services. | ||
|
||
```shell | ||
kubectl get service -n consul-derive | ||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | ||
bookstore ClusterIP None <none> 14001/TCP 8m42s | ||
bookstore-v1 ClusterIP None <none> 14001/TCP 8m42s | ||
bookwarehouse ClusterIP None <none> 14001/TCP 8m38s | ||
bookwarehouse-v1 ClusterIP None <none> 14001/TCP 8m38s | ||
bookbuyer ClusterIP None <none> 14001/TCP 8m38s | ||
bookbuyer-v1 ClusterIP None <none> 14001/TCP 8m38s | ||
``` | ||
|
||
Use port forwarding or create Ingress rules to view the running services: the page auto-refreshes and the counter increases continuously. | ||
|
||
![](/images/integration/bookstore-books-bought.png) | ||
|
||
### Canary Release Testing | ||
|
||
Next is the common scenario for canary releases. Referencing [FSM documentation examples](https://fsm-docs.flomesh.io/demos/traffic_management/canary_rollout/), we use weight-based canary releases. | ||
|
||
Before releasing a new version, create TrafficSplit `bookstore-v1` to ensure all traffic routes to `bookstore-v1`: | ||
|
||
```shell | ||
kubectl apply -n consul-derive -f - <<EOF | ||
apiVersion: split.smi-spec.io/v1alpha4 | ||
kind: TrafficSplit | ||
metadata: | ||
name: bookstore-split | ||
spec: | ||
service: bookstore | ||
backends: | ||
- service: bookstore-v1 | ||
weight: 100 | ||
- service: bookstore-v2 | ||
weight: 0 | ||
EOF | ||
``` | ||
|
||
Then deploy the new version `bookstore-v2`: | ||
|
||
```shell | ||
kubectl apply -n bookstore -f ./manifests/consul/bookstore-v2-consul.yaml | ||
``` | ||
|
||
![](/images/integration/consul-service-list2.png) | ||
|
||
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. | ||
|
||
```shell | ||
kubectl apply -n consul-derive -f - <<EOF | ||
apiVersion: split.smi-spec.io/v1alpha4 | ||
kind: TrafficSplit | ||
metadata: | ||
name: bookstore-split | ||
spec: | ||
service: bookstore | ||
backends: | ||
- service: bookstore-v1 | ||
weight: 50 | ||
- service: bookstore-v2 | ||
weight: 50 | ||
EOF | ||
``` | ||
|
||
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. | ||
|
||
```shell | ||
kubectl apply -n consul-derive -f - <<EOF | ||
apiVersion: split.smi-spec.io/v1alpha4 | ||
kind: TrafficSplit | ||
metadata: | ||
name: bookstore-split | ||
spec: | ||
service: bookstore | ||
backends: | ||
- service: bookstore-v1 | ||
weight: 0 | ||
- service: bookstore-v2 | ||
weight: 100 | ||
EOF | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: "Microservice Discovery Integration" | ||
description: "Efficient Integration Microservices in Service Meshes" | ||
type: docs | ||
draft: false | ||
weight: 4 | ||
--- | ||
|
||
FSM, as a service mesh product, operates on the concept of a "unified service directory" to manage and accommodate various microservice architectures. It automatically identifies and integrates deployed services into a centralized service directory. This enables real-time and automated interactions among microservices, whether they are deployed on Kubernetes (K8s) or other environments. | ||
|
||
For non-K8s environments, FSM supports multiple popular service registries. This means it can integrate with different service discovery systems, including: | ||
|
||
- **Consul**: A service mesh solution by HashiCorp for service discovery and configuration. | ||
- **Eureka**: A service discovery tool developed by Netflix, part of the Spring Cloud Netflix microservice suite. | ||
- **Nacos**: An open-source service discovery and configuration management system by Alibaba, aimed at providing dynamic service discovery and configuration management for cloud-native applications. | ||
|
||
Adapting these registries, FSM enhances its application in hybrid architectures, allowing users to enjoy the benefits of a service mesh without being limited to a specific microservice framework. This compatibility positions FSM as a strong service mesh option in diverse microservice environments. | ||
|
||
### Unified Service Directory | ||
|
||
The unified service directory provides a smooth integration experience. By abstracting services from different microservice registries into Kubernetes services (K8s Services), FSM standardizes service information. This approach has several key advantages: | ||
|
||
1. Simplified service discovery: Services from different sources need not write and maintain multiple sets of code for different discovery mechanisms; everything is uniformly handled through K8s Services. | ||
2. Reduced complexity: Encapsulating different service registries as K8s Services means users only need to interact with the K8s API, simplifying operations. | ||
3. Seamless cloud-native integration: For services already running on Kubernetes, this unified service model integrates seamlessly, enhancing inter-service operability. | ||
|
||
![](/images/integration/unified-service-catalog.png) | ||
|
||
### Connectors | ||
|
||
FSM uses framework-specific connectors to interface with different microservice registries. Each connector is tasked with communicating with a specific registry (such as Consul, Eureka, or Nacos), performing key tasks like service registration, monitoring service changes, encapsulating as K8s Services, and writing to the cluster. | ||
|
||
Connectors are independent components developed in Go (theoretically supporting other languages as well) that can quickly interface with packages provided by the corresponding registry. | ||
|
||
![](/images/integration/unified-service-connector.png) | ||
|
||
Next, we demonstrate [integrating Spring Cloud Consul microservices into the service mesh](/demos/integration/consul_registry) and testing the commonly used canary release scenario. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.