在最新的eShopOnContainers 3.0 中Ocelot 网关被Envoy Proxy 替换。下面就来简要带大家了解下Envoy,并尝试梳理下为什么要使用Envoy替代Ocelot。
2. Hello EnvoyENVOY IS AN OPEN SOURCE EDGE AND SERVICE PROXY, DESIGNED FOR CLOUD-NATIVE APPLICATIONS.
Enovy(信使) 是一款开源的专为云原生应用设计的服务代理。
首先基于本地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端口的入站请求路由到。
下面启动容器测试:
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