envoy proxy配置

envoy proxy的配置包含以下四個(gè)部分

1. bootstrap: Envoy proxy啟動(dòng)時(shí)候加載的靜態(tài)配置

Bootstrap 是 Envoy 中配置的根本來(lái)源,Bootstrap 消息中有一個(gè)關(guān)鍵的概念,就是靜態(tài)和動(dòng)態(tài)資源的之間的區(qū)別。

2. listeners: 監(jiān)聽(tīng)器配置,使用LDS下發(fā)

Listener 顧名思義,監(jiān)聽(tīng)器,監(jiān)聽(tīng)的IP地址和端口

關(guān)鍵字段

  • address
    改字段定義了服務(wù)的地址和端口
    例如監(jiān)聽(tīng)ingressgateway的的address
      "listener": {
        "name": "0.0.0.0_15443",
        "address": {
         "socket_address": {
          "address": "0.0.0.0",
          "port_value": 15443
         }
      }
    
    
  • filter_chains:
    改字段定義了一系列作用在該監(jiān)聽(tīng)服務(wù)上的操作。
    在istio中可以通過(guò)創(chuàng)建envoyfilter來(lái)拓展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"
            }
           }
          ]
         }
        ]
    

其他字段

3.clusters: 集群配置

Cluster指的是Envoy連接的一組邏輯相同的上游主機(jī), Envoy通過(guò)服務(wù)發(fā)現(xiàn)來(lái)發(fā)現(xiàn)cluster成員。Istio中的ServiceEntry、DestinationRule都會(huì)作用到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
        }
       ]
      }

關(guān)鍵字段

例如一個(gè)istio ServiceEntry對(duì)應(yīng)的cluster, 指明了流向流向cluster要去的地址

其他字段

4.routes: 路由配置

這個(gè)路由配置的作用是,是把流量路由到上面提到過(guò)的cluster中。 可以做重定向、轉(zhuǎn)發(fā)、重試等任務(wù)。

改字段可以通過(guò)istio中的VirtualService字段來(lái)設(shè)置生成,通過(guò)RDS下發(fā)
VirtualService例子
改virtualService吧url 前綴為 /(所有請(qǐng)求)的流量都路由到了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
           }
          }
         }
        ]

關(guān)鍵字段

  • match:路由匹配參數(shù)。例如 URL prefix(前綴)、path(URL 的完整路徑)、regex(規(guī)則表達(dá)式)等。
  • route:這里面配置路由的行為,可以是 route、redirectdirect_response,不過(guò)這里面沒(méi)有專(zhuān)門(mén)的一個(gè)配置項(xiàng)用來(lái)配置以上三種行為,而是根據(jù)實(shí)際填充的配置項(xiàng)來(lái)確定的。例如在此處添加 cluster 配置則暗示路由動(dòng)作為”route“,表示將流量路由到該 cluster。詳情請(qǐng)參考 route.RouteAction。

其他字段

參考

https://jimmysong.io/istio-handbook/data-plane/envoy-proxy-config-deep-dive.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容