A service mesh implementation for connecting, control, and observe services in spring-cloud.
EaseMesh
EaseMesh is a service mesh that is compatible with the Spring Cloud ecosystem. It is based on Easegress for the sidecar of service management and EaseAgent for the monitor of service observing.
EaseMesh ingress
serviceWhy do we reinvent another wheel?
Service mesh compatible with Spring Cloud ecosystem: Micro-service in Spring Cloud ecosystem has its own service registry/discovery components. It is quite different from Kubernetes ecosystem using DNS for service discovery. The major Service Mesh solution (e.g. Istio) using the Kubernetes domain technology. It is painful and conflicted with Java Spring Cloud ecosystem. EaseMesh aims to make Service Mesh compatible with Java Spring Cloud completely.
Integrated Observability: Currently Kubernetes-based service mesh only can see the ingress/egress traffic, and it has no idea what's happened in service/application. So, combining with Java Agent technology, we can have the full capability to observe everything inside and outside of service/application.
Sophisticated capability of traffic split: The EaseMesh has the sophisticated capability of traffic split, it can split traffic of a request chain into not only first service but also last. The capability could be applied in the canary deployment, online production testing scenarios.
Shortly, the EaseMesh leverages the Kubernetes sidecar and Java Agent techniques to make Java applications have service governance and integrated observability without change a line of source code.
The throughput is represented by m1, m5, m15 The latency is represented by P99, P98, P95, P90, P80, P75, P50, etc...
kubectl get nodes
to check your Kubernetes cluster's healthy.Please check out install.md to install EaseMesh.
Demonstration
Spring Cloud PetClinic microservice example.
It uses Spring Cloud Gateway, Spring Cloud Circuit Breaker, Spring Cloud Config, Spring Cloud Sleuth, Resilience4j, Micrometer and Eureka Service Discovery from Spring Cloud Netflix technology stack.
Prepare the emctl
git clone https://github.com/megaease/easemesh cd emctl && make export PATH=$(pwd)/bin:${PATH}
7.1 Start PetClinic in EaseMesh 7.1.1 Step 1: Apply mesh configuration
Apply the EaseMesh configuration files
emctl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/mesh-conf/a-pet-tenant.yaml emctl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/mesh-conf/api-gateway.yaml emctl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/mesh-conf/customers.yaml emctl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/mesh-conf/ingress.yaml emctl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/mesh-conf/vets.yaml emctl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/mesh-conf/visits.yaml
7.1.2 Step 2: Create namespace
leverage kubectl to create spring-petclinic
namespace
We support to automatically inject sidecar and the JavaAgent when a deployment was created or updated in an interested namespace. So you need to create a namespace with a specific label, we are prepared a spring-petclinic namespace, you can create it via:
kubectl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/namespace/spring-petclinic.yaml
7.1.3 Step 3: Setup Database
The pet clinic demo needs to access database, the default is memory database. But in the EaseMesh quick start, you could to use memory database by default.
If you want to use the MySQL database, you could create the DB table schemes and import records from PetClinic example to set up yours.
7.1.4 Step 4: Apply petclinic stack
Deploy petclinic resources to k8s cluster, we have developed an operator to manage the custom resource (MeshDeployment) of the EaseMesh. Meshdeployment
contains a K8s' complete deployment spec and a piece of extra information about the service.
The Operator of the EaseMesh will automatically inject a sidecar to pod and a JavaAgent into the application's JVM
Now, we support injecting the JavaAgent and sidecar into the native deployment, but you need to explicitly specify the service name in the Deployment spec via mesh.megaease.com/service-name: "{service-name}"
of the annotation. EaseMesh has a admission control
server, which will watch Create/Update operation of Deployments in the specified namespace. If a deployment with mesh.megaease.com/service-name
annotation was created in the specific namespace (labeled with key mesh.megaease.com/mesh-service
), the admission control server will mutate the deployment spec and inject the sidecar and the JavaAgent.
kubectl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/deployments/01-vets.yaml kubectl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/deployments/02-visits.yaml kubectl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/deployments/03-customers.yaml kubectl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/deployments/04-api-gateway.yaml
ATTENTION: There is a ConfigMap spec in yaml file, if you to want to use the MySQL database, you need to change it per your environments.
7.1.5 Get exposed port of EaseMesh ingress
service
kubectl get service -n easemesh easemesh-ingress-service
ATTENTION: From the output, you may notice exposed port of the Ingress service. If you needn't use reverse proxy service, you can directly access pet-clinic application via http://{your_host}:{exposed_port}/
7.1.6 Step 5: Configure reverse proxy
ATTENTION: The step is optional. It can be omitted when you have no requirements about reverse proxy.
7.1.6.1 Config reverse proxy via Easegress
ATTENTION: Only for scenarios that the Easegress acts as the role of reverse proxy service
If you leverage the Easegress as a reverse proxy service, the following configuration can be applied.
HTTP Server spec (file name: http-server.yaml):
kind: HTTPServer name: spring-petclinic-example port: 443 https: true keepAlive: true keepAliveTimeout: 75s maxConnection: 10240 cacheSize: 0 certs: key: {add your certs information to here} rules:
HTTP Pipeline spec (file name: http-petclinic-pipeline.yaml):
name: http-petclinic-pipeline kind: HTTPPipeline flow:
Change contents in {}
as per your environment, and apply it via Easegress client command tool egctl
:
egctl apply -f http-server.yaml egctl apply -f http-petclinic-pipeline.yaml
egctl is the client command line of the Easegress
Visiting PetClinic website with $your_domain/#!/welcome
ATTENTION: Only for scenarios that the Nginx acts as the role of reverse proxy service
if you leverage the Nginx as a reverse proxy service, the following configuration should be added.
Then configure the NodPort IP address and port number into your traffic gateway's routing address, e.g, add config to NGINX:
location /pet/ {
proxy_pass http://{node1_of_k8s_cluster}:{port_exposed_by_ingress_service}/;
}
ATTENTION: that the PetClinic website should be routed by the
/
subpath, or it should useNGINX
's replacing response content feature for correcting resource URL:
location /pet/ {
proxy_pass http://{node1_of_k8s_cluster}:{port_exposed_by_ingress_service/;
sub_filter 'href="/' 'href="/pet/';
sub_filter 'src="/' 'src="/pet/';
sub_filter_once off;
}
Visiting PetClinic website with $your_domain/pet/#!/welcome
.
Canary deployment demonstrates how to route coloring traffic (request) to a canary version of the specific service.
Customer Service (v2)
is the canary version service.Coloring traffic with HTTP header X-Canary: lv1
by using Chrome browser's ModHeader plugin. Then EaseMesh will route this colored traffic into the Customer service's canary version instance.
Apply mesh configuration file:
emctl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/canary/customer-canary.yaml`7.2.3 Step 3: Prepare a canary version of the application
ATTENTION You can skip the step, we have provides the canary image to docker hub
megaease/spring-petclinic-customers-service:canary
you can found it in the docker hub.
Developing a canary version of Customer service to add an extra suffix to the city field for each record.
diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java index 360e765..cc2df3d 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java @@ -99,7 +99,7 @@ public class Owner { }
public String getAddress() {
public void setAddress(String address) {k 7.2.4 Step 4: Build canary image
ATTENTION You can skip the step, we have provides the canary image to docker hub
megaease/spring-petclinic-customers-service:canary
you can found it in the docker hub.
Building the canary Customer service's image, and update image version in https://github.com/megaease/easemesh-spring-petclinic/blob/main/canary/customers-service-deployment-canary.yaml
. Or just use our default canary image which already was in it.
7.2.5 Step 5. Deploy canary version
Being similar to 7.1.4, we leverage kubectl to deploy the canary version of the Deployment
kubectl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/canary/customers-service-deployment-canary.yaml`
ATTENTION: There is a ConfigMap spec in echo yaml spec, it describes how to connect the database for applications. You need to change its contents for your environment.
7.2.6 Step 6: Sending coloring traffic
Turning on the chrome ModHeader plugin to color the traffic, then visit PetClinic website. You can see the change to the table which adds an "-US" suffix to every city record.
ModHeader is a chrome extension, we use it solely for demonstrating coloring the requests.
7.3 Clean
kubectl delete namespace spring-petclinic
.emctl delete ingress pet-ingress emctl delete service api-gateway emctl delete service customers-service emctl delete service vets-service emctl delete service visits-service emctl delete tenant pet
Roadmap
See EaseMesh Roadmap for details.
Contributing
See MegaEase Community to follow our contributing details.
License
EaseMesh is under the Apache 2.0 license. See the LICENSE file for details.
User Manual
See EaseMesh User Manual for details.
Twice a month we will interview people behind open source businesses. We will talk about how they are building a business on top of open source projects.
We'll never share your email with anyone else.