入门istio,envoy现在看来必不可少,花点时间了解一下吧。
Envoy 是什么
我们援引一段官网的描述:
Envoy is an L7 proxy and communication bus designed for large modern service oriented architectures. The project was born out of the belief that: "The network should be transparent to applications. When network and application problems do occur it should be easy to determine the source of the problem."
Envoy 的核心功能/卖点
- 非侵入的架构:
Envoy
是和应用服务并行运行的,透明地代理应用服务发出/接收的流量。应用服务只需要和Envoy
通信,无需知道其他微服务应用在哪里。 - 基于 Modern C++11实现,性能优异。
- L3/L4 过滤器架构:
Envoy
的核心是一个 L3/L4 代理,然后通过插件式的过滤器(network filters
)链条来执行 TCP/UDP 的相关任务,例如 TCP 转发,TLS 认证等工作。 - HTTP L7 过滤器架构:HTTP在现代应用体系里是地位非常特殊的应用层协议,所以
Envoy
内置了一个非常核心的过滤器:http_connection_manager
。http_connection_manager
本身是如此特殊和复杂,支持丰富的配置,以及本身也是过滤器架构,可以通过一系列 http 过滤器(http filters
)来实现 http协议层面的任务,例如:http路由,重定向,CORS支持等等。 - HTTP/2 作为第一公民:
Envoy
支持 HTTP/1.1 和 HTTP/2,推荐使用 HTTP/2。 - gRPC 支持:因为对 HTTP/2 的良好支持,
Envoy
可以方便的支持 gRPC,特别是在负载和代理上。 - 服务发现: 支持包括 DNS, EDS 在内的多种服务发现方案。
- 健康检查:内置健康检查子系统。
- 高级的负载均衡方案:除了一般的负载均衡,Envoy 还支持基于 rate limit 服务的多种高级负载均衡方案,包括: automatic retries, circuit breaking, global rate limiting
- Tracing:方便集成 Open Tracing 系统,追踪请求
- 统计与监控:内置 stats 模块,方便集成诸如 prometheus/statsd 等监控方案
- 动态配置:通过“动态配置API”实现配置的动态调整,而无需重启
Envoy
服务的。
核心术语解释
Host
这里的 Host,可以理解为由 IP, Port 唯一确定的服务实例
Downstream
发送请求给 Envoy 的 Host 是 Downstream(下游),例如gRPC的 client
Upstream
接收 Enovy 发出的请求的 Host 是Upstream(上游),例如 gRPC的 server
Listener
Envoy 监听的一个地址,例如 ip:port, unix socket 等等
Cluster
一组功能一致的上游 Host,称为一个cluster。类似 k8s
的 Service
, nginx
的 upstream
Http Route Table
HTTP 的路由规则,例如请求的域名,Path符合什么规则,转发给哪个 Cluster。
这次用的只有静态的配置文件:
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 7777 }
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: some_service }
http_filters:
- name: envoy.router
clusters:
- name: some_service
connect_timeout: 0.25s
type: STATIC
lb_policy: ROUND_ROBIN
hosts: [{ socket_address: { address: 127.0.0.1, port_value: 8000 }}]