Route & Redirect with envoy
An example envoy.yaml showing how to route & redirect.
There are different options, see here
https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route.proto#route-redirectaction
This envoy.yaml routes /taxgod and /taxgod/ (the second could probably be omitted because the first one should also match it, I think) to a new port and a different protocol.
/picockpit is simply redirected to /
and then finally / is routed to the target_picockpit backend
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 80
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
codec_type: auto
stat_prefix: ingress_http
route_config:
virtual_hosts:
- name: backend
domains: ["*"]
routes:
- match: { prefix: "/" }
redirect:
path_redirect: "/"
https_redirect: true
http_filters:
- name: envoy.router
config: {}
- address:
socket_address:
address: 0.0.0.0
port_value: 443
filter_chains:
- tls_context:
common_tls_context:
tls_certificates:
- certificate_chain: { filename: "/etc/example-com.crt" }
private_key: { filename: "/etc/example-com.key" }
alpn_protocols: [ "h2,http/1.1" ]
filters:
- name: envoy.http_connection_manager
config:
stat_prefix: ingress_https
route_config:
virtual_hosts:
- name: backend
domains: ["*"]
routes:
- match: { prefix: "/taxgod" }
redirect: { port_redirect: 2080, path_redirect: "/", scheme_redirect: "http"}
- match: { prefix: "/taxgod" }
redirect: { port_redirect: 2080, path_redirect: "/", scheme_redirect: "http"}
- match: { prefix: "/picockpit/" }
redirect: { path_redirect: "/" }
- match: { prefix: "/picockpit" }
redirect: { path_redirect: "/" }
- match: { prefix: "/gagarin" }
direct_response: { status: 200, body: { inline_string: "Bringing redemption to my dark night. Beautiful surrender is where I wanna be." } }
- match: { prefix: "/" }
route: { cluster: target_picockpit }
http_filters:
- name: envoy.router
config: {}
clusters:
- name: target_taxgod
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
hosts:
- socket_address:
address: taxgod
port_value: 3000
- name: target_picockpit
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
hosts:
- socket_address:
address: picockpit
port_value: 3000
admin:
access_log_path: "/tmp/envoy.log"
address:
socket_address:
address: 0.0.0.0
port_value: 9901
