Envoy镜像流量
# HTTP Request Mirror Demo
### 环境说明
#### 六个Service:
- envoy:Front Proxy,地址为172.31.60.10
- 5个后端服务
- demoapp-v1.0-1、demoapp-v1.0-2和demoapp-v1.0-3:对应于Envoy中的demoappv10集群
- demoapp-v1.1-1和demoapp-v1.1-2:对应于Envoy中的demoappv11集群
#### 使用的路由配置
```
virtual_hosts:
- name: demoapp
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: demoappv10
request_mirror_policies:
- cluster: demoappv11
runtime_fraction:
default_value:
numerator: 20 # 默认只镜像demoappv10集群上20%的流量到该集群
denominator: HUNDRED
runtime_key: routing.request_mirror.demoapp
启动
cd servicemesh_in_practise/HTTP-Connection-Manager/http-request-mirror
docker-compose up
[root@k8s-master http-request-mirror]# cat docker-compose.yaml
version: '3'
services:
front-envoy:
image: envoyproxy/envoy-alpine:v1.21-latest
environment:
- ENVOY_UID=0
- ENVOY_GID=0
volumes:
- ./front-envoy.yaml:/etc/envoy/envoy.yaml
networks:
envoymesh:
ipv4_address: 172.31.60.10
expose:
# Expose ports 80 (for general traffic) and 9901 (for the admin server)
- "80"
- "9901"
demoapp-v1.0-1:
image: ikubernetes/demoapp:v1.0
hostname: demoapp-v1.0-1
networks:
envoymesh:
aliases:
- demoappv10
expose:
- "80"
demoapp-v1.0-2:
image: ikubernetes/demoapp:v1.0
hostname: demoapp-v1.0-2
networks:
envoymesh:
aliases:
- demoappv10
expose:
- "80"
demoapp-v1.0-3:
image: ikubernetes/demoapp:v1.0
hostname: demoapp-v1.0-3
networks:
envoymesh:
aliases:
- demoappv10
expose:
- "80"
demoapp-v1.1-1:
image: ikubernetes/demoapp:v1.1
hostname: demoapp-v1.1-1
networks:
envoymesh:
aliases:
- demoappv11
expose:
- "80"
demoapp-v1.1-2:
image: ikubernetes/demoapp:v1.1
hostname: demoapp-v1.1-2
networks:
envoymesh:
aliases:
- demoappv11
expose:
- "80"
networks:
envoymesh:
driver: bridge
ipam:
config:
- subnet: 172.31.60.0/24
[root@k8s-master http-request-mirror]# cat front-envoy.yaml
admin:
profile_path: /tmp/envoy.prof
access_log_path: /tmp/admin_access.log
address:
socket_address:
address: 0.0.0.0
port_value: 9901
layered_runtime:
layers:
- name: admin
admin_layer: {}
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 80 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: demoapp
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: demoappv10
request_mirror_policies:
- cluster: demoappv11
runtime_fraction:
default_value:
numerator: 20
denominator: HUNDRED
runtime_key: routing.request_mirror.demoapp
http_filters:
- name: envoy.filters.http.router
clusters:
- name: demoappv10
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: demoappv10
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: demoappv10
port_value: 80
- name: demoappv11
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: demoappv11
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: demoappv11
port_value: 80
[root@k8s-master http-request-mirror]# cat send-request.sh
#!/bin/bash
interval="0.5"
while true; do
curl -s http://$1/hostname
# $1 is the host address of the front-envoy.
sleep $interval
done
查看访问日志有访问到V1.1,说明流量被引入到了新版本
./send-request.sh 172.31.60.10
调整镜像流量的比例,查看访问日志访问V1.1的基本占了一半
curl -XPOST 'http://172.31.60.10:9901/runtime_modify?routing.request_mirror.demoapp=100'