eShopOnContainers 知多少[12]:Envoy gateways

eShopOnContainers 知多少[12]:Envoy gateways

1. 引言

在最新的eShopOnContainers 3.0 中Ocelot 网关被Envoy Proxy 替换。下面就来简要带大家了解下Envoy,并尝试梳理下为什么要使用Envoy替代Ocelot。

2. Hello Envoy

ENVOY IS AN OPEN SOURCE EDGE AND SERVICE PROXY, DESIGNED FOR CLOUD-NATIVE APPLICATIONS.
Enovy(信使) 是一款开源的专为云原生应用设计的服务代理。

2.1. 快速体验

首先基于本地Dockers快速体验以下,先启动本地Docker-Desktop,拉取Envoy镜像:

> docker search envoy-dev NAME DESCRIPTION STARS OFFICIAL AUTOMATED envoyproxy/envoy Images for tagged releases. Use envoy-dev fo… 96 > docker image pull envoyproxy:envoy-dev latest: Pulling from envoyproxy/envoy-dev 171857c49d0f: Pull complete 419640447d26: Pull complete 61e52f862619: Pull complete 3f2a8c910457: Pull complete b2ce823b3fd3: Pull complete ec09faba9bc7: Pull complete b0b9168845d0: Pull complete 39a220277151: Pull complete 9081a11f5983: Pull complete 1880b475bc3a: Pull complete Digest: sha256:cd8dbbbd8ce4c8c6eb52e4f8eebf55f29d1e597ca8311fecf9eda08b8cca813a Status: Downloaded newer image for envoyproxy/envoy-dev:latest docker.io/envoyproxy/envoy-dev:latest

该Docker 镜像将包含最新版本的 Envoy 和一个基本的 Envoy 配置,可以将10000端口的入站请求路由到。
下面启动容器测试:

> docker run -d --name envoy -p 10000:10000 envoyproxy/envoy-dev:latest 27e422f34b389d99e9180e47d8109a19975ccd139f42ac2f4fa9f724906b72f6 > docker ps | findstr 'envoy' 27e422f34b38 envoyproxy/envoy-dev:latest "/docker-entrypoint.?? 2 minutes ago Up 2 minutes 0.0.0.0:10000->10000/tcp envoy > curl -I :10000 HTTP/1.1 200 OK content-type: text/html; charset=ISO-8859-1 p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info." date: Sat, 17 Oct 2020 04:38:38 GMT server: envoy x-xss-protection: 0 x-frame-options: SAMEORIGIN expires: Sat, 17 Oct 2020 04:38:38 GMT cache-control: private set-cookie: 1P_JAR=2020-10-17-04; expires=Mon, 16-Nov-2020 04:38:38 GMT; path=http://www.likecs.com/; domain=.google.com; Secure set-cookie: NID=204=h0EoJXNOTbQA11L-tVowqcwloS0-BCTR71IeN4irsmpubdPIIS4sU8Gco79pt1NhONAxxFdUJ46SKvbX4Ni-jKMWbSW0k_kn3fFkVrfLm7OOBbAtUWtxGGOCRJGbSNIRyOPfDB7_wMngEWW3yoFEs9diSCtZK9DWFZdtJJZtWuI; expires=Sun, 18-Apr-2021 04:38:38 GMT; path=http://www.likecs.com/; domain=.google.com; HttpOnly alt-svc: h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" x-envoy-upstream-service-time: 37 transfer-encoding: chunked

PS: 请确保本地机器能访问Google,否则curl -I :10000 会出错。

接下来我们进入容器内部,查看下配置文件,默认路径为/etc/envoy/envoy.yaml:

docker exec -it envoy /bin/bash root@27e422f34b38:/# cat /etc/envoy/envoy.yaml admin: access_log_path: /tmp/admin_access.log address: socket_address: protocol: TCP address: 127.0.0.1 port_value: 9901 static_resources: listeners: - name: listener_0 address: socket_address: protocol: TCP address: 0.0.0.0 port_value: 10000 filter_chains: - filters: - name: envoy.filters.network.http_connection_manager typed_config: "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager stat_prefix: ingress_http route_config: name: local_route virtual_hosts: - name: local_service domains: ["*"] routes: - match: prefix: "http://www.likecs.com/" route: host_rewrite_literal: cluster: service_google http_filters: - name: envoy.filters.http.router clusters: - name: service_google connect_timeout: 30s type: LOGICAL_DNS # Comment out the following line to test on v6 networks dns_lookup_family: V4_ONLY lb_policy: ROUND_ROBIN load_assignment: cluster_name: service_google endpoints: - lb_endpoints: - endpoint: address: socket_address: address: port_value: 443 transport_socket: name: envoy.transport_sockets.tls typed_config: "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext sni:

我们把上面的配置文件拷贝到本地,将上面的改为,将admin.address.socket_address.address: 127.0.0.1该为0.0.0.0,然后把配置文件命名为envoy-baidu.yaml,然后挂载到容器的/etc/envoy/envoy.yaml。

> docker run --rm -d --name envoy-baidu -v $Home/k8s/envoy-baidu.yaml:/etc/envoy/envoy.yaml -p 9901:9901 -p 15001:15001 envoyproxy/envoy-dev:latest > docker ps | findstr 'envoy' f07f6a1e9305 envoyproxy/envoy-dev:latest "/docker-entrypoint.?? 2 minutes ago Up 2 minutes 10000/tcp, 0.0.0.0:9901->9901/tcp, 0.0.0.0:15001->15001/tcp envoy-baidu 3cd12b5f6ddd envoyproxy/envoy-dev:latest "/docker-entrypoint.?? About an hour ago Up About an hour 0.0.0.0:10000->10000/tcp envoy > curl -I :15001 HTTP/1.1 200 OK accept-ranges: bytes cache-control: private, no-cache, no-store, proxy-revalidate, no-transform content-length: 277 content-type: text/html date: Sat, 17 Oct 2020 05:41:01 GMT etag: "575e1f65-115" last-modified: Mon, 13 Jun 2016 02:50:13 GMT pragma: no-cache server: envoy x-envoy-upstream-service-time: 24

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwgsjs.html