envoy proxy的配置介绍
§ envoy proxy的配置包含以下四个部分
§ 1. bootstrap: Envoy proxy启动时候加载的静态配置
Bootstrap 是 Envoy 中配置的根本来源,Bootstrap 消息中有一个关键的概念,就是静态和动态资源的之间的区别。
§ #2. listeners: 监听器配置,使用LDS下发
Listener 顾名思义,监听器,监听的IP地址和端口
§ 关键字段
address
改字段定义了服务的地址和端口
例如监听ingressgateway的的address"listener": { "name": "0.0.0.0_15443", "address": { "socket_address": { "address": "0.0.0.0", "port_value": 15443 } }
filter_chains:
改字段定义了一系列作用在该监听服务上的操作。
在istio中可以通过创建envoyfilter来拓展filter
例如ingressgateway的filter_chains"filter_chains": [ { "filter_chain_match": { "server_names": [ "*.uzone1.region1" ] }, "filters": [ { "name": "envoy.filters.network.sni_cluster" }, { "name": "mixer", "config": { "transport": { "check_cluster": "outbound|15004||istio-policy.istio-system.svc.cluster.local", "network_fail_policy": { "policy": "FAIL_CLOSE", "max_retry_wait": "1s", "base_retry_wait": "0.080s" }, "report_cluster": "outbound|15004||istio-telemetry.istio-system.svc.cluster.local" }, "mixer_attributes": { "attributes": { "context.reporter.kind": { "string_value": "outbound" }, "source.namespace": { "string_value": "istio-system" }, "context.reporter.uid": { "string_value": "kubernetes://istio-ingressgateway-77bbb77959-f9lgg.istio-system" }, "source.uid": { "string_value": "kubernetes://istio-ingressgateway-77bbb77959-f9lgg.istio-system" } } }, "disable_check_calls": true } }, { "name": "envoy.filters.network.tcp_cluster_rewrite", "config": { "cluster_replacement": ".svc.cluster.local", "cluster_pattern": "\\.global$" } }, { "name": "envoy.tcp_proxy", "config": { "stat_prefix": "BlackHoleCluster", "cluster": "BlackHoleCluster" } } ] } ]
§ 其他字段
具体其他字段可以参考
Envoy v2 API reference - listener
§ 3.clusters: 集群配置
Cluster指的是Envoy连接的一组逻辑相同的上游主机, Envoy通过服务发现来发现cluster成员。Istio中的ServiceEntry、DestinationRule都会作用到cluster字段
ServiceEntry配置
apiVersion: networking.istio.io/v1alpha3 kind: ServiceEntry metadata: generation: 1 name: gzone-productcatalogservice namespace: test spec: endpoints: - address: 192.xxx.xx.xx ports: grpc: 35522 hosts: - productcatalogservice.test.global location: MESH_INTERNAL ports: - name: grpc number: 3550 protocol: GRPC resolution: DNS
Envoyfilter cluster配置
{ "cluster": { "name": "outbound_.3550_._.productcatalogservice.test.global", "type": "STRICT_DNS", "connect_timeout": "10s", "circuit_breakers": { "thresholds": [ { "max_retries": 1024 } ] }, "dns_refresh_rate": "300s", "dns_lookup_family": "V4_ONLY", "metadata": { "filter_metadata": { "istio": { "config": "/apis/networking/v1alpha3/namespaces/micro-demo/destination-rule/istio-dr-product" } } }, "load_assignment": { "cluster_name": "outbound_.3550_._.productcatalogservice.test.global", "endpoints": [ { "lb_endpoints": [ { "endpoint": { "address": { "socket_address": { "address": "192.xx.xx.xx", "port_value": 35522 } } }, "load_balancing_weight": 1 } ], "load_balancing_weight": 1 } ] }
§ 关键字段
type:即服务发现类型,支持的参数有
STATIC
(缺省值)、STRICT_DNS
、LOGICAL_DNS
、EDS
、ORIGINAL_DST
。
例如一个istio ServiceEntry对应的cluster, 指明了流向流向cluster要去的地址
§ 其他字段
具体其他字段可以参考
Envoy v2 API reference - cluster
§ 4.routes: 路由配置
这个路由配置的作用是,是把流量路由到上面提到过的cluster中。 可以做重定向、转发、重试等任务。
改字段可以通过istio中的VirtualService字段来设置生成,通过RDS下发
VirtualService例子
改virtualService吧url 前缀为 /(所有请求)的流量都路由到了frontend
kind: VirtualService apiVersion: networking.istio.io/v1alpha3 metadata: name: frontend-vs namespace: test selfLink: >- /apis/networking.istio.io/v1alpha3/namespaces/micro-demo/virtualservices/frontend-ingress spec: hosts: - '*' gateways: - frontend-gateway http: - match: - uri: prefix: / route: - destination: host: frontend port: number: 80
route例子
"virtual_hosts": [ { "name": "*:81", "domains": [ "*", "*:81" ], "routes": [ { "match": { "prefix": "/" }, "route": { "cluster": "outbound|80||frontend.test.svc.cluster.local", "timeout": "0s", "retry_policy": { "retry_on": "connect-failure,refused-stream,unavailable,cancelled,resource-exhausted,retriable-status-codes", "num_retries": 2, "retry_host_predicate": [ { "name": "envoy.retry_host_predicates.previous_hosts" } ], "host_selection_retry_max_attempts": "5", "retriable_status_codes": [ 503 ] }, "max_grpc_timeout": "0s" }, "metadata": { "filter_metadata": { "istio": { "config": "/apis/networking/v1alpha3/namespaces/test/virtual-service/frontend-vs" } } }, "decorator": { "operation": "frontend.test.svc.cluster.local:80/*" }, "per_filter_config": { "mixer": { "forward_attributes": { "attributes": { "destination.service.uid": { "string_value": "istio://test/services/frontend" }, "destination.service.host": { "string_value": "frontend.test.svc.cluster.local" }, "destination.service.namespace": { "string_value": "test" }, "destination.service.name": { "string_value": "frontend" } } }, "disable_check_calls": true } } } ]
§ 关键字段
match:路由匹配参数。例如 URL prefix(前缀)、path(URL 的完整路径)、regex(规则表达式)等。
route:这里面配置路由的行为,可以是 route、redirect 和 direct_response,不过这里面没有专门的一个配置项用来配置以上三种行为,而是根据实际填充的配置项来确定的。例如在此处添加
cluster
配置则暗示路由动作为”route“,表示将流量路由到该 cluster。详情请参考 route.RouteAction。
§ 其他字段
§ 参考
https://jimmysong.io/istio-handbook/data-plane/envoy-proxy-config-deep-dive.html
- 点赞
- 收藏
- 关注作者
评论(0)