Front Proxy

To get a flavor of what Envoy has to offer as a front proxy, we are releasing a docker compose sandbox that deploys a front envoy and a couple of services (simple flask apps) colocated with a running service Envoy. The three containers will be deployed inside a virtual network called envoymesh.

Below you can see a graphic showing the docker compose deployment:

../../_images/docker_compose_v0.1.svg

All incoming requests are routed via the front Envoy, which is acting as a reverse proxy sitting on the edge of the envoymesh network. Port 80 is mapped to port 8000 by docker compose (see /examples/front-proxy/docker-compose.yaml). Moreover, notice that all traffic routed by the front Envoy to the service containers is actually routed to the service Envoys (routes setup in /examples/front-proxy/front-envoy.yaml). In turn the service envoys route the request to the flask app via the loopback address (routes setup in /examples/front-proxy/service-envoy.yaml). This setup illustrates the advantage of running service Envoys collocated with your services: all requests are handled by the service Envoy, and efficiently routed to your services.

Running the Sandbox

The following documentation runs through the setup of an Envoy cluster organized as is described in the image above.

Step 1: Install Docker

Ensure that you have a recent versions of docker and docker-compose installed.

A simple way to achieve this is via the Docker Desktop.

Step 2: Clone the Envoy repo, and start all of our containers

If you have not cloned the Envoy repo, clone it with git clone git@github.com:envoyproxy/envoy or git clone https://github.com/envoyproxy/envoy.git:

  1. $ pwd
  2. envoy/examples/front-proxy
  3. $ docker-compose pull
  4. $ docker-compose up --build -d
  5. $ docker-compose ps
  6. Name Command State Ports
  7. --------------------------------------------------------------------------------------------------------------------------
  8. front-proxy_front-envoy_1 /docker-entrypoint.sh /bin ... Up 10000/tcp, 0.0.0.0:8000->80/tcp, 0.0.0.0:8001->8001/tcp
  9. front-proxy_service1_1 /bin/sh -c /usr/local/bin/ ... Up 10000/tcp, 80/tcp
  10. front-proxy_service2_1 /bin/sh -c /usr/local/bin/ ... Up 10000/tcp, 80/tcp

Step 3: Test Envoy’s routing capabilities

You can now send a request to both services via the front-envoy.

For service1:

  1. $ curl -v localhost:8000/service/1
  2. * Trying 192.168.99.100...
  3. * Connected to 192.168.99.100 (192.168.99.100) port 8000 (#0)
  4. > GET /service/1 HTTP/1.1
  5. > Host: 192.168.99.100:8000
  6. > User-Agent: curl/7.54.0
  7. > Accept: */*
  8. >
  9. < HTTP/1.1 200 OK
  10. < content-type: text/html; charset=utf-8
  11. < content-length: 89
  12. < x-envoy-upstream-service-time: 1
  13. < server: envoy
  14. < date: Fri, 26 Aug 2018 19:39:19 GMT
  15. <
  16. Hello from behind Envoy (service 1)! hostname: f26027f1ce28 resolvedhostname: 172.19.0.6
  17. * Connection #0 to host 192.168.99.100 left intact

For service2:

  1. $ curl -v localhost:8000/service/2
  2. * Trying 192.168.99.100...
  3. * Connected to 192.168.99.100 (192.168.99.100) port 8000 (#0)
  4. > GET /service/2 HTTP/1.1
  5. > Host: 192.168.99.100:8000
  6. > User-Agent: curl/7.54.0
  7. > Accept: */*
  8. >
  9. < HTTP/1.1 200 OK
  10. < content-type: text/html; charset=utf-8
  11. < content-length: 89
  12. < x-envoy-upstream-service-time: 2
  13. < server: envoy
  14. < date: Fri, 26 Aug 2018 19:39:23 GMT
  15. <
  16. Hello from behind Envoy (service 2)! hostname: 92f4a3737bbc resolvedhostname: 172.19.0.2
  17. * Connection #0 to host 192.168.99.100 left intact

Notice that each request, while sent to the front Envoy, was correctly routed to the respective application.

Step 4: Test Envoy’s load balancing capabilities

Now let’s scale up our service1 nodes to demonstrate the load balancing abilities of Envoy.:

  1. $ docker-compose scale service1=3
  2. Creating and starting example_service1_2 ... done
  3. Creating and starting example_service1_3 ... done

Now if we send a request to service1 multiple times, the front Envoy will load balance the requests by doing a round robin of the three service1 machines:

  1. $ curl -v localhost:8000/service/1
  2. * Trying 192.168.99.100...
  3. * Connected to 192.168.99.100 (192.168.99.100) port 8000 (#0)
  4. > GET /service/1 HTTP/1.1
  5. > Host: 192.168.99.100:8000
  6. > User-Agent: curl/7.43.0
  7. > Accept: */*
  8. >
  9. < HTTP/1.1 200 OK
  10. < content-type: text/html; charset=utf-8
  11. < content-length: 89
  12. < x-envoy-upstream-service-time: 1
  13. < server: envoy
  14. < date: Fri, 26 Aug 2018 19:40:21 GMT
  15. < x-envoy-protocol-version: HTTP/1.1
  16. <
  17. Hello from behind Envoy (service 1)! hostname: 85ac151715c6 resolvedhostname: 172.19.0.3
  18. * Connection #0 to host 192.168.99.100 left intact
  19. $ curl -v localhost:8000/service/1
  20. * Trying 192.168.99.100...
  21. * Connected to 192.168.99.100 (192.168.99.100) port 8000 (#0)
  22. > GET /service/1 HTTP/1.1
  23. > Host: 192.168.99.100:8000
  24. > User-Agent: curl/7.54.0
  25. > Accept: */*
  26. >
  27. < HTTP/1.1 200 OK
  28. < content-type: text/html; charset=utf-8
  29. < content-length: 89
  30. < x-envoy-upstream-service-time: 1
  31. < server: envoy
  32. < date: Fri, 26 Aug 2018 19:40:22 GMT
  33. <
  34. Hello from behind Envoy (service 1)! hostname: 20da22cfc955 resolvedhostname: 172.19.0.5
  35. * Connection #0 to host 192.168.99.100 left intact
  36. $ curl -v localhost:8000/service/1
  37. * Trying 192.168.99.100...
  38. * Connected to 192.168.99.100 (192.168.99.100) port 8000 (#0)
  39. > GET /service/1 HTTP/1.1
  40. > Host: 192.168.99.100:8000
  41. > User-Agent: curl/7.43.0
  42. > Accept: */*
  43. >
  44. < HTTP/1.1 200 OK
  45. < content-type: text/html; charset=utf-8
  46. < content-length: 89
  47. < x-envoy-upstream-service-time: 1
  48. < server: envoy
  49. < date: Fri, 26 Aug 2018 19:40:24 GMT
  50. < x-envoy-protocol-version: HTTP/1.1
  51. <
  52. Hello from behind Envoy (service 1)! hostname: f26027f1ce28 resolvedhostname: 172.19.0.6
  53. * Connection #0 to host 192.168.99.100 left intact

Step 5: enter containers and curl services

In addition of using curl from your host machine, you can also enter the containers themselves and curl from inside them. To enter a container you can use docker-compose exec <container_name> /bin/bash. For example we can enter the front-envoy container, and curl for services locally:

  1. $ docker-compose exec front-envoy /bin/bash
  2. root@81288499f9d7:/# curl localhost:80/service/1
  3. Hello from behind Envoy (service 1)! hostname: 85ac151715c6 resolvedhostname: 172.19.0.3
  4. root@81288499f9d7:/# curl localhost:80/service/1
  5. Hello from behind Envoy (service 1)! hostname: 20da22cfc955 resolvedhostname: 172.19.0.5
  6. root@81288499f9d7:/# curl localhost:80/service/1
  7. Hello from behind Envoy (service 1)! hostname: f26027f1ce28 resolvedhostname: 172.19.0.6
  8. root@81288499f9d7:/# curl localhost:80/service/2
  9. Hello from behind Envoy (service 2)! hostname: 92f4a3737bbc resolvedhostname: 172.19.0.2

Step 6: enter containers and curl admin

When Envoy runs it also attaches an admin to your desired port. In the example configs the admin is bound to port 8001. We can curl it to gain useful information. For example you can curl /server_info to get information about the envoy version you are running. Additionally you can curl /stats to get statistics. For example inside frontenvoy we can get:

  1. $ docker-compose exec front-envoy /bin/bash
  2. root@e654c2c83277:/# curl localhost:8001/server_info
  1. {
  2. "version": "3ba949a9cb5b0b1cccd61e76159969a49377fd7d/1.10.0-dev/Clean/RELEASE/BoringSSL",
  3. "state": "LIVE",
  4. "command_line_options": {
  5. "base_id": "0",
  6. "concurrency": 4,
  7. "config_path": "/etc/front-envoy.yaml",
  8. "config_yaml": "",
  9. "allow_unknown_static_fields": false,
  10. "admin_address_path": "",
  11. "local_address_ip_version": "v4",
  12. "log_level": "info",
  13. "component_log_level": "",
  14. "log_format": "[%Y-%m-%d %T.%e][%t][%l][%n] %v",
  15. "log_path": "",
  16. "hot_restart_version": false,
  17. "service_cluster": "front-proxy",
  18. "service_node": "",
  19. "service_zone": "",
  20. "mode": "Serve",
  21. "disable_hot_restart": false,
  22. "enable_mutex_tracing": false,
  23. "restart_epoch": 0,
  24. "cpuset_threads": false,
  25. "file_flush_interval": "10s",
  26. "drain_time": "600s",
  27. "parent_shutdown_time": "900s"
  28. },
  29. "uptime_current_epoch": "401s",
  30. "uptime_all_epochs": "401s"
  31. }
  1. root@e654c2c83277:/# curl localhost:8001/stats
  2. cluster.service1.external.upstream_rq_200: 7
  3. ...
  4. cluster.service1.membership_change: 2
  5. cluster.service1.membership_total: 3
  6. ...
  7. cluster.service1.upstream_cx_http2_total: 3
  8. ...
  9. cluster.service1.upstream_rq_total: 7
  10. ...
  11. cluster.service2.external.upstream_rq_200: 2
  12. ...
  13. cluster.service2.membership_change: 1
  14. cluster.service2.membership_total: 1
  15. ...
  16. cluster.service2.upstream_cx_http2_total: 1
  17. ...
  18. cluster.service2.upstream_rq_total: 2
  19. ...

Notice that we can get the number of members of upstream clusters, number of requests fulfilled by them, information about http ingress, and a plethora of other useful stats.