视频讲解:Envoy手把手入门视频讲解

Envoy 4 层 TCP/UDP 协议转发

4 层协议现在只支持 tcp,udp 协议的支持还在设计开发中 UDP proxying support

Envoy 的 4 层代理转发通过名为 envoy.tcp_proxy 的 network filter 完成,该 filter 的定义见 TCP Proxy configuration overview

envoy tcp 转发示例

监听 81 端口,将到达该端口的 tcp 报文转发给 echo_cluster,示例配置文件为 envoy-to-tcp.yaml

...省略...
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address:
        protocol: TCP
        address: 0.0.0.0
        port_value: 81
    filter_chains:
    - filters:
      - name: envoy.tcp_proxy
        config:
          stat_prefix: tcp_proxy_81
          cluster: echo_tcp_80
  clusters:
  - name: echo_tcp_80
    connect_timeout: 0.25s
    type: STATIC
    lb_policy: ROUND_ROBIN
    #http2_protocol_options: {}  #echoserver不支持http 2.0
    load_assignment:
      cluster_name: service_echo
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address:  172.17.0.2
                port_value: 8080

注意使用的 filter 名称为 “envoy.tcp_proxy”,运行效果如下:

$ ./run.sh  envoy-to-tcp.yaml
$ curl 127.0.0.1:81

Hostname: 7759cabd7402

Pod Information:
	-no pod information available-
... 省略...

tcp_proxy 还支持 weighted_clusters,可以设置 access_log,详情见 TCP Proxy configuration overview

参考