一、先了解一下envoy
Envoy是Lyft开源的一个C++实现的代理(Proxy),和Nginx及HAProxy类似,可代理L3/L4层和L7层。
代理是它最核心和基础的功能,它也是服务网格框架Istio的Sidecar。

重点推荐文章:服务网格代理Envoy入门
二、envoy的静态配置和动态配置(运行时配置)
最好是跟着后面的试跑体验在本地跑一下,对与理解envoy的静态配置和动态配置(运行时配置)很有帮助。
(go build的二进制文件在容器里面跑不起来 报错: cannot execute binary file: Exec format error, 解决办法 env GOOS=linux GOARCH=amd64 go build eds.go)
envoy 混合配置(EDS动态配置)
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address:
protocol: TCP
address: 0.0.0.0 # 管理地址
port_value: 8081 # 管理端口
static_resources:
listeners: # 监听器数组
- name: listener_0 # 监听器
address:
socket_address:
protocol: TCP
address: 0.0.0.0 # 监听地址
port_value: 8080 # 监听端口
filter_chains: # 过滤器链
- filters: # 过滤器数组
- name: envoy.http_connection_manager # 过滤器名
typed_config:
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
stat_prefix: ingress_http
route_config: # 路由配置
name: local_route # 路由配置名
virtual_hosts: # 虚拟主机数组
- name: local_service
domains: ["*"] # 需代理的域名数组
routes: # 定义路由
- match:
prefix: "/" # 匹配规则
route:
host_rewrite: www.baidu.com # 将HOST重写为
cluster: bd_service # 下游集群名,通过它找到下游集群的配置
http_filters:
- name: envoy.router
clusters: # 下游集群数组
- name: bd_service # 下游集群名
connect_timeout: 0.25s # 连接下游的超时时长
type: eds
lb_policy: ROUND_ROBIN # 负载均衡策略
eds_cluster_config:
eds_config:
api_config_source:
api_type: rest
refresh_delay: "10s" # 动态一定要有这个配置
cluster_names: [xds_cluster] # 这里并不提供静态的endpoints,需访问EDS服务得到
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.api.v2.auth.UpstreamTlsContext
sni: www.baidu.com
- name: xds_cluster
connect_timeout: 0.25s
type: static
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1 # EDS的服务地址
port_value: 2020 # EDS的服务端口 |

envoy访问127.0.0.1:2020获取EDS动态配置信息,上图为配置信息结构

上图为动态配置静态配置的对应位置方便立即
参考资料:
- envoy实践 https://www.jianshu.com/p/90f9ee98ce70
- 官方文档 envoy的配置示例 https://www.envoyproxy.io/docs/envoy/latest/configuration/overview/examples
- 官方文档 envoy的配置中字段的说明 https://www.envoyproxy.io/docs/envoy/latest/api-v2/api
三、查看线上的配置环境
进入容器
kubectl exec -it api-v2-v13-d45f8544d-cfgpc -n sqkb-istio-qa -c istio-proxy -- /bin/bash
查看进程

或者直接查看
kubectl exec -it api-v2-v13-d45f8544d-cfgpc -n sqkb-istio-qa -c istio-proxy -- cat /etc/istio/proxy/envoy-rev0.json > /tmp/envoy.json
---
node:
id: "sidecar~172.25.11.236~api-v2-v13-d45f8544d-cfgpc.sqkb-istio-qa~sqkb-istio-qa.svc.cluster.local"
cluster: "api-v2.sqkb-istio-qa"
locality:
metadata:
CLUSTER_ID: "Kubernetes"
CONFIG_NAMESPACE: "sqkb-istio-qa"
EXCHANGE_KEYS: "NAME,NAMESPACE,INSTANCE_IPS,LABELS,OWNER,PLATFORM_METADATA,WORKLOAD_NAME,CANONICAL_TELEMETRY_SERVICE,MESH_ID,SERVICE_ACCOUNT"
INCLUDE_INBOUND_PORTS: "8312"
INSTANCE_IPS: "172.25.11.236"
INTERCEPTION_MODE: "REDIRECT"
|

本文介绍了Envoy代理的基础知识,强调其作为服务网格Istio的Sidecar角色。讨论了Envoy的静态和动态配置,并展示了如何在Kubernetes环境中查看Istio-proxy的配置。此外,还探讨了istio注入配置的本地测试,包括使用iptables进行流量转发。文章提供了丰富的参考资料链接以供深入学习。
最低0.47元/天 解锁文章
343

被折叠的 条评论
为什么被折叠?



