megaease / easemesh

A service mesh implementation for connecting, control, and observe services in spring-cloud.
https://megaease.com/easemesh
Apache License 2.0
505 stars 60 forks source link
go kubernetes mesh microservice microservices observability service service-governance service-mesh servicemesh spring-cloud traffic-splitting

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.

<img src="./imgs/easemesh.svg" alt="EaseMesh logo" title="EaseMesh" height="175" width="175" align="right"/>

1. Purposes

Why do we reinvent another wheel?

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.

2. Principles

3. Architecture

The architecture diagram

4. Features

The throughput is represented by m1, m5, m15 The latency is represented by P99, P98, P95, P90, P80, P75, P50, etc...

5. Dependent Projects

  1. EaseAgent
  2. Easegress

6. Quick Start

6.1 Environment Requirement

6.2 Sanity Checking

6.3 Installation

Please check out install.md to install EaseMesh.

7. Demonstration

The topology migration diagram

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:
  - paths:
    - pathPrefix: /
      backend: http-petclinic-pipeline

HTTP Pipeline spec (file name: http-petclinic-pipeline.yaml):

name: http-petclinic-pipeline
kind: HTTPPipeline
flow:
  - filter: requestAdaptor
  - filter: proxy
filters:
  - name: requestAdaptor
    kind: RequestAdaptor
    method: ""
    path: null
    header:
      del: []
      set:
        Host: "{you host name, can be omitted}"
        X-Forwarded-Proto: "https"
        Connection: "upgrade"
      add:
        Host: "{you host name, can be omitted}"
  - name: proxy
    kind: Proxy
    mainPool:
      servers:
      - url: http://{node1_of_k8s_cluster}:{port_exposed_by_ingress_service}
      - url: http://{node2_of_k8s_cluster}:{port_exposed_by_ingress_service}
      loadBalance:
        policy: roundRobin

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

7.1.6.2 Config reverse proxy via Nginx

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 use NGINX'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="https://github.com/megaease/easemesh/blob/main/' 'href="https://github.com/megaease/easemesh/blob/main/pet/';
    sub_filter 'src="https://github.com/megaease/easemesh/raw/main/' 'src="https://github.com/megaease/easemesh/raw/main/pet/';
    sub_filter_once  off;
}

Visiting PetClinic website with $your_domain/pet/#!/welcome.

7.2 Canary Deployment

Canary deployment demonstrates how to route coloring traffic (request) to a canary version of the specific service.

EaseMesh Canary topology

7.2.1 Step 1: Coloring traffic

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.

7.2.2 Step 2: Apply canary configuration of the EaseMesh

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() {
-        return this.address;
+        return this.address + " - US";
    }

    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.

plugin

ModHeader is a chrome extension, we use it solely for demonstrating coloring the requests.

7.3 Clean

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

8. Roadmap

See EaseMesh Roadmap for details.

9. Contributing

See MegaEase Community to follow our contributing details.

10. License

EaseMesh is under the Apache 2.0 license. See the LICENSE file for details.

11. User Manual

See EaseMesh User Manual for details.