Envoy tcp_proxy配置
作者:互联网
环境说明
envoy:Front Proxy, 地址为 172.31.1.2
webserver01:后端服务,地址为 172.31.1.11
webserver01:后端服务,地址为 172.31.1.12
envoy配置文件
static_resources:
listeners:
name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 80 }
filter_chains:
- filters:
- name: envoy.tcp_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
stat_prefix: tcp
cluster: local_cluster
clusters:
- name: local_cluster
connect_timeout: 0.25s
type: STATIC
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: local_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address: { address: 172.31.1.11, port_value: 8080 }
- endpoint:
address:
socket_address: { address: 172.31.1.12, port_value: 8080 }
docker-compose.yaml
version: '3.3'
services:
envoy:
image: envoyproxy/envoy:v1.23-latest
volumes:
- ./envoy.yaml:/etc/envoy/envoy.yaml
environment:
- ENVOY_UID=0
- ENVOY_GID=0
networks:
envoymesh:
ipv4_address: 172.31.1.2
aliases:
- front-proxy
depends_on:
- webserver01
- webserver02
webserver01:
image: ikubernetes/demoapp:v1.0
environment:
- PORT=8080
hostname: webserver01
networks:
envoymesh:
ipv4_address: 172.31.1.11
aliases:
- webserver01
webserver02:
image: ikubernetes/demoapp:v1.0
environment:
- PORT=8080
hostname: webserver02
networks:
envoymesh:
ipv4_address: 172.31.1.12
aliases:
- webserver02
networks:
envoymesh:
driver: bridge
ipam:
config:
- subnet: 172.31.1.0/24
运行envoy
docker-compose up -d
测试envoy
# docker-compose exec envoy bash
root@cf8793e06502:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
26: eth0@if27: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:1f:01:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.31.1.2/24 brd 172.31.1.255 scope global eth0
valid_lft forever preferred_lft forever
root@cf8793e06502:/# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.11:33257 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1/envoy
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1/envoy
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1/envoy
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1/envoy
root@cf8793e06502:/# curl http://172.31.1.2:80
iKubernetes demoapp v1.0 !! ClientIP: 172.31.1.2, ServerName: webserver01, ServerIP: 172.31.1.11!
root@cf8793e06502:/# curl http://172.31.1.2:80
iKubernetes demoapp v1.0 !! ClientIP: 172.31.1.2, ServerName: webserver02, ServerIP: 172.31.1.12!
清理envoy
docker-compose down
标签:00,0.0,Envoy,envoy,tcp,proxy,address,172.31 来源: https://www.cnblogs.com/wangguishe/p/16580969.html