組態設定:從檔案系統動態載入
您可以使用實作 xDS 通訊協定的檔案,以動態組態啟動 Envoy。
當檔案系統上的檔案變更時,Envoy 將自動更新其組態設定。
注意
Envoy 僅在組態設定檔被檔案移動取代時才會更新,而不是在檔案就地編輯時更新。
這樣實作是為了確保組態設定的一致性。
至少,您需要啟動 Envoy 並設定以下區段
node 以唯一識別代理節點。
dynamic_resources 告訴 Envoy 在哪裡找到其動態組態設定。
對於給定的範例,您還需要兩個動態組態設定檔
如果您希望監控 Envoy 或擷取統計資料或組態設定資訊,您也可以新增 admin 區段。
以下章節將逐步說明 demo dynamic filesystem configuration file
中提供的動態組態設定。
node
node 應指定 cluster
和 id
。
1node:
2 cluster: test-cluster
3 id: test-id
4
5dynamic_resources:
6 cds_config:
7 path: /var/lib/envoy/cds.yaml
dynamic_resources
dynamic_resources 指定從哪裡載入動態組態設定。
在此範例中,組態設定由以下設定的 yaml
檔案提供。
3 id: test-id
4
5dynamic_resources:
6 cds_config:
7 path: /var/lib/envoy/cds.yaml
8 lds_config:
9 path: /var/lib/envoy/lds.yaml
resources
- 監聽器
連結的 lds_config
應該是 Listener discovery service (LDS) 的實作。
以下 dynamic LDS file
範例會在連接埠 10000
上設定 HTTP
listener。
所有網域和路徑都會被比對並路由至 service_envoyproxy_io
叢集。
host
標頭會被重寫為 www.envoyproxy.io
1resources:
2- "@type": type.googleapis.com/envoy.config.listener.v3.Listener
3 name: listener_0
4 address:
5 socket_address:
6 address: 0.0.0.0
7 port_value: 10000
8 filter_chains:
9 - filters:
10 - name: envoy.http_connection_manager
11 typed_config:
12 "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
13 stat_prefix: ingress_http
14 http_filters:
15 - name: envoy.router
16 typed_config:
17 "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
18 route_config:
19 name: local_route
20 virtual_hosts:
21 - name: local_service
22 domains:
23 - "*"
24 routes:
25 - match:
26 prefix: "/"
27 route:
28 host_rewrite_literal: www.envoyproxy.io
29 cluster: example_proxy_cluster
resources
- 叢集
連結的 cds_config
應該是 Cluster discovery service (CDS) 的實作。
在以下 dynamic CDS file
範例中,example_proxy_cluster
cluster 會透過 TLS
代理到 https://envoy.dev.org.tw。
1resources:
2- "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
3 name: example_proxy_cluster
4 type: STRICT_DNS
5 typed_extension_protocol_options:
6 envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
7 "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
8 explicit_http_config:
9 http2_protocol_options: {}
10 load_assignment:
11 cluster_name: example_proxy_cluster
12 endpoints:
13 - lb_endpoints:
14 - endpoint:
15 address:
16 socket_address:
17 address: www.envoyproxy.io
18 port_value: 443
19 transport_socket:
20 name: envoy.transport_sockets.tls
21 typed_config:
22 "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
23 sni: www.envoyproxy.io
另請參閱
- 原子交換
有關如何更新執行階段組態設定的詳細資訊。