Introduction to Original Destination in Envoy

Introduction

  • Listener — A listener typically opens a port in Envoy for a downstream client to send traffic to.
  • Filter — A filter reads metadata about incoming connections/requests and enhances it further to affect routing decisions.
  • Route — A route is used for mapping incoming HTTP requests using its attributes to clusters.
  • Cluster — A cluster is generally a collection of endpoints, configured with a load balancing policy.
  • Endpoint — An endpoint is the address of an upstream server or another Envoy if it's a service mesh.
  • You want to literally route to previously unknown destinations, think of a general egress proxy.
  • You want to route to user-specified, arbitrary, upstream addresses i.e. without load balancing.

Original Destination

  1. Original Destination Listener Filter
  2. Original Destination Cluster

Original Destination Listener Filter

Original Destination Cluster

Original Destination in Action

Setup

$ tree .
.
├── Dockerfile
├── docker-compose.yaml
└── envoy.yaml

Demo

# Route traffic from the "sleeper" user on port 80 to Envoy.
$ docker exec -u root -it sleep \
iptables -t nat \
-A OUTPUT \
-p tcp \
--dport 80 \
-j REDIRECT \
--to-port 9000 \
-m owner \
--uid-owner sleeper
# Traffic on port 80 is routed to Envoy on port 9000 via iptables.
# The DNS within the sleep container resolves httpbin.org to an IP
# like 54.166.163.67, which Envoy then identifies and routes to.
$ docker exec -it sleep curl httpbin.org:80/status/418

-=[ teapot ]=-
_...._
.' _ _ `.
| ."` ^ `". _,
\_;`"---"`|//
| ;/
\_ _/
`"""`
# Traffic is routed to Envoy on port 9001 with a special header.
# The special x-envoy-original-dst-host header tells the Original
# Destination cluster to route to the said address.
$ docker exec -it sleep \
curl -H "x-envoy-original-dst-host: 54.166.163.67:80" \
127.0.0.1:9001/status/418

-=[ teapot ]=-
_...._
.' _ _ `.
| ."` ^ `". _,
\_;`"---"`|//
| ;/
\_ _/
`"""`

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store