0 Star 0 Fork 12

zwmagic / easemesh

forked from MegaEase / easemesh 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

EaseMesh

EaseMesh是一个与Spring Cloud生态系统兼容的服务网格。它基于Easegress开发了Mesh的控制组件和流量边车,并且利用了EaseAgent的服务监测,调用链追踪等特性。

EaseMesh logo

1. 宗旨

为什么我们要重新发明一个轮子?

  • 服务网与Spring Cloud生态系统兼容: Spring Cloud生态系统中的微服务有自己的服务注册/发现组件。这与使用DNS进行服务发现的Kubernetes生态系统完全不同。主要的服务网格解决方案(如Istio)使用Kubernetes领域技术。但这样的方案会带来许多痛苦,且与Java Spring Cloud生态系统有冲突。EaseMesh旨在使Service Mesh与Java Spring Cloud完全兼容。

  • 更细致的观察性: 目前基于Kubernetes的服务网格只能看到入口/出口流量,它不知道服务/应用中发生了什么。因此,结合Java Agent技术,我们可以拥有观察服务/应用内部和外部的全部能力。

  • 复杂的流量分割能力: EaseMesh具有复杂的流量分割能力,它可以将一个请求链的流量分割到多个服务。这种能力可以应用于金丝雀部署、在线生产测试等场景。

简而言之,EaseMesh利用Kubernetes sidecar和Java Agent技术,使Java应用具有服务治理和细致观察能力,而无需改变任何一行源代码

2. 原则

  • Spring Cloud兼容性: Spring Cloud领域服务管理和弹性设计。
  • 无需修改代码: 使用sidecar和Java Agent来完成服务治理和综合观测。
  • 服务监控: 服务运行指标/跟踪/日志监控。

3. 架构

The architecture diagram

4. 特点

  • 非侵入式设计 对Java Spring Cloud应用程序的迁移不做任何代码修改,只需要进行小规模的配置更新。
  • Java注册/发现 与流行的Java Spring Cloud生态系统的服务注册/发现兼容。
    • 多个租户(命名空间) 支持多个租户的服务注册,隔离不同租户的服务。
    • 共享(全局)租户 支持共享租户,所有服务对全局租户中注册的服务都有可见性。
    • 兼容性
      • 与Eureka注册表兼容。
      • 与Consul注册表兼容。
      • 与Nacos注册表兼容。
    • 可扩展性 支持用元数据注册服务。
  • 资源管理 依靠Kubernetes平台来管理CPU/内存资源。
  • 流量编排
    • 丰富的路由规则 精确的路径、路径前缀、路径的正则表达式、方法、头部匹配。
    • 流量分割 对东西向和南北向流量进行着色和调度到配置的服务。
    • 负载平衡 支持Round Robin, Weight Round Robin, Random, Hash by Client IP Address, Hash by HTTP Headers。
  • 弹性设计 包括超时/断路/重选/限制器,完全遵循复杂的弹性设计。
    • 弹性和容错性
      • 断路器 暂时阻止可能的故障。
      • 速率限制器 限制传入请求的速率。
      • 重选器 重复失败的执行。
      • 时间限制器 限制执行的时间。
    • 混沌工程
      • 故障注入 正在进行的工作。
      • 延迟注入 工作正在进行中。
  • 可观察性
    • 日志
      • 访问日志 为每个服务的所有请求生成HTTP访问日志。
      • 应用日志 自动将跟踪上下文注入到日志数据中。
    • 追踪
      • JDBC 对JDBC的调用进行跟踪。
      • HTTP请求 对HTTP RPC的追踪。
      • Kafka 对Kafka传递的消息进行追踪。
      • Redis 追踪Redis缓存的访问。
      • RabbitMQ 跟踪由RabbitMQ传递的消息。
      • 采样
        • 支持概率采样。
        • 支持 QPS 采样。
    • 指标
      • HTTP请求 报告每个URL的吞吐量延迟。
      • JDBC 报告每个SQL的吞吐量和延时。
      • Kafka 报告每个消费者、生产者和主题的吞吐量和延时。
      • Redis 报告每个方法的吞吐量和延时。
      • RabbitMQ 报告每个主题的吞吐量和延时。
  • 安全
    • mTLS Working in progress.
    • mTLS强制执行 Working in progress.
    • 外部CA证书 Working in progress.
    • 服务到服务的授权规则 Working in progress.

吞吐量由m1, m5, m15表示。 延迟由P99、P98、P95、P90、P80、P75、P50等表示。

5. 依赖项目

  1. EaseAgent
  2. Easegress

6. 快速启动

6.1 环境要求

  • Linux内核版本4.15以上
  • Kubernetes版本1.18以上
  • MySQL版本5.7+

6.2 健全测试

  • 运行kubectl get nodes来检查你的Kubernetes集群是否健康。

6.3 安装

请查看 install.md 来安装EaseMesh。

7. 示范

  • Spring Cloud PetClinic 微服务实例。

  • 它使用了Spring Cloud Gateway、Spring Cloud Circuit Breaker、Spring Cloud Config、Spring Cloud Sleuth、Resilience4j、Micrometer和Spring Cloud Netflix技术栈的Eureka Service Discovery。

拓扑迁移图

准备好emctl

git clone https://github.com/megaease/easemesh
cd emctl && make
export PATH=$(pwd)/bin:${PATH}.

7.1 在EaseMesh中启动PetClinic

7.1.1 步骤1:应用网格配置

应用EaseMesh的配置文件

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 步骤2:创建命名空间

利用kubectl来创建spring-petclinic命名空间

我们支持在你想要的命名空间中创建或更新Deployment时自动注入sidecar和JavaAgent。所以你需要创建一个有特定标签的命名空间,我们准备了一个spring-petclinic命名空间,你可以通过以下方式创建它。

kubectl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/namespace/spring-petclinic.yaml

7.1.3 第四步:设置数据库

Petclinic的演示需要访问数据库,默认的是内存数据库。但在EaseMesh快速启动中,你可以默认使用内存数据库。

如果你想使用MySQL数据库,你可以创建DB表方案,并从PetClinic范例导入记录来设置你的数据库。

7.1.4 第三步:应用Ppetclinic栈

将Petclinic资源部署到k8s集群,我们已经开发了一个operator来管理EaseMesh的自定义资源(MeshDeployment)。Meshdeployment包含一个K8s的完整部署规范和一个关于服务的额外信息。

EaseMesh的操作者会自动向pod注入一个sidecar和一个JavaAgent到应用程序的JVM中。

现在,我们支持将JavaAgent和sidecar注入到本地部署中,但你需要通过注解的mesh.megaease.com/service-name: "{service-name}"在部署规格中明确指定服务名称。EaseMesh有一个admission control服务器,它将观察指定命名空间中的部署的创建/更新操作。如果一个带有mesh.megaease.com/service-name注解的部署是在特定的命名空间中创建的(附有key为mesh.megaease.com/mesh-service的label),准入控制服务将改变Deployment规格去注入sidecar和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

注意:在yaml文件中有一个ConfigMap,如果你想使用MySQL数据库,你需要根据你的环境改变它。

7.1.5 获取EaseMesh ingress服务的暴露端口

kubectl get service -n easemesh easemesh-ingress-service

注意:从输出中,你可能会注意到Ingress服务的暴露端口。如果你不需要使用反向代理服务,你可以通过http://{your_host}:{exposed_port}/直接访问Petclinic应用程序。

7.1.6 第五步:配置反向代理

注意:该步骤是可选的。如果你对反向代理没有要求,可以省略这一步。

7.1.6.1 通过Easegress配置反向代理

注意:仅适用于Easegress充当反向代理服务的场景

如果你利用Easegress作为反向代理服务,可以应用以下配置。

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

根据你的环境改变{}中的内容,并通过Easegress客户端命令工具egctl生效它。

egctl apply -f http-server.yaml
egctl apply -f http-petclinic-pipeline.yaml

egctl是Easegress的客户端命令行。

使用$your_domain/#!/welcome访问PetClinic网站

7.1.6.2 通过Nginx配置反向代理

注意:只适用于Nginx充当反向代理服务的场景

如果你利用Nginx作为反向代理服务,应该添加以下配置。

然后将NodPort的IP地址和端口号配置到你的流量网关的路由地址中,例如,在Nginx中添加配置。

location /pet/ {
    proxy_pass http://{node1_of_k8s_cluster}:{port_exposed_by_ingress_service}/;
}

注意:PetClinic网站应通过/子路径进行路由,或者使用Nginx的替换响应内容功能来纠正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;
}

$your_domain/pet/#!/welcome访问PetClinic网站。

7.2 金丝雀部署

Canary部署演示了如何将着色流量(请求)路由到特定服务的canary版本。

EaseMesh Canary拓扑结构

  • Customer Service (v2)是金丝雀版本的服务。
  • 图中红色的线代表着色流量(请求)。
  • 着色流量在通过第一个服务(API网关)后,被正确路由到canary版本服务。

7.2.1 步骤1:流量着色

通过使用Chrome浏览器的**ModHeader**插件给带有HTTP头X-Canary: lv1的流量着色。然后EaseMesh将把这些着色的流量路由到Customer Service 的canary版本实例中。

7.2.2 步骤2:应用EaseMesh的金丝雀配置

应用Mesh配置文件。

emctl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/canary/customer-canary.yaml`

7.2.3 第3步:准备好应用程序的金丝雀版本

注意:你可以跳过这一步,我们已经提供了canary镜像到Docker Hub megaease/spring-petclinic-customers-service:canary 你可以在Docker Hub找到它。

我们开发一个canary版本的Customer Service,为每条记录的城市字段添加一个额外的后缀。

diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java b/spring-petclinic-customers-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 步骤4:建立canary图像

注意:你可以跳过这一步,我们已经提供了canary镜像到Docker Hubmegaease/spring-petclinic-customers-service:canary,你可以在Docker Hub找到它。

建立金丝雀客户服务的镜像,并在https://github.com/megaease/easemesh-spring-petclinic/blob/main/canary/customers-service-deployment-canary.yaml中更新镜像版本。或者直接使用我们默认的canary镜像,它已经在里面了。

7.2.5 步骤5. 部署金丝雀版本

7.1.4类似,我们利用kubectl来部署canary版本的Deployment

kubectl apply -f https://raw.githubusercontent.com/megaease/easemesh-spring-petclinic/main/canary/customers-service-deployment-canary.yaml`

注意:canary yaml spec中有一个ConfigMap spec,它描述了如何为应用程序连接数据库。你需要根据你的环境改变其内容。

7.2.6 步骤6:发送着色流量

打开chrome ModHeader 插件为流量着色,然后访问PetClinic网站。你可以看到表格的变化,它为每条城市记录添加了一个"-US "的后缀。

plugin

ModHeader是一个chrome扩展,我们只用它来演示对请求进行着色。

7.3 清理Demo

  • 运行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

8. 路线图

参见EaseMesh路线图了解详情。

9. 贡献

请参阅MegaEase Community以了解我们的社区贡献细节。

10. 许可证

EaseMesh采用Apache 2.0许可证。详情请见LICENSE文件。

11. 用戶手冊

详情请见EaseMesh用戶手冊

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2020 Open Service Mesh Authors. and others that have contributed code to the public domain. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

A service mesh implementation for connecting, control, and observe services in spring-cloud. 展开 收起
Go
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/wilbert/easemesh.git
git@gitee.com:wilbert/easemesh.git
wilbert
easemesh
easemesh
main

搜索帮助