1什么是http filter
http filter是envoy用来支持http协议的过滤器,他们是配置在HtttpConnectionManager这个网络过滤器里面的。其中route过滤器必须有,而且必须是http过滤器链中最后一个,用来选择路由的。这一小节的过滤器配置都比较简单,所以放在一节中统一介绍。http过滤器可以处理http1.1,http2,https协议。
2本节要讲的http filter列表
alternate_protocols_cache
cdn_loop
dynamo
health_check
ip_tagging
set_metadata
squash
sxg
3配置
3.1alternate_protocols_cache
{"alternate_protocols_cache_options": "{...}"缓存配置选项}
alternate_protocols_cache_options:
{"name": "...",缓存名称"max_entries": "{...}",最大缓存个数,默认1024"key_value_store_config": "{...}"key,value存储配置}
key_value_store_config:
{"name": "...",名称"typed_config": "{...}"配置}
3.2cdn_loop
{"cdn_id": "...",cdn的id"max_allowed_occurrences": "..."最大允许的cdn id个数}
3.3dynamo
没有配置
3.4health_check
{"pass_through_mode": "{...}",是否使用pass through模式"cache_time": "{...}",如果是pass through模式上游响应缓存时间"cluster_min_healthy_percentages": "{...}",如果是非pass through模式,上游集群健康百分比"headers": []匹配头}
3.5ip_tagging
{"request_type": "...",请求类型"ip_tags": []tag集合}
request_type:
•BOTH(DEFAULT) Both external and internal requests will be tagged. This is the default value.•INTERNALOnly internal requests will be tagged.•EXTERNALOnly external requests will be tagged.
ip_tags:
{"ip_tag_name": "...",ip 标签名称"ip_list": []会被标记的ip列表}
3.6set_metadata
{"metadata_namespace": "...",元数据名称空间"value": "{...}"元数据值}
3.7squash
{"cluster": "...",squash服务器的cluster"attachment_template": "{...}",创建DebugAttachment时的资源模板"request_timeout": "{...}",请求超时时间,默认1s"attachment_timeout": "{...}",attachment超时时间,默认60秒"attachment_poll_period": "{...}"检查attach状态周期,默认1秒}
有关介绍参考 https://blog.csdn.net/kunyus/article/details/88616443
3.8sxg
{"certificate": "{...}",用于签名的证书"private_key": "{...}",用于签名的私钥"duration": "{...}",sxg包有效期,默认 604800s (7天)"mi_record_size": "...",Merkle Integrity记录大小,默认4096"cbor_url": "...",CBOR 文件的url,path格式"validity_url": "...",抽取验证信息的url"client_can_accept_sxg_header": "...",客户端可以接受sxg的头,默认x-client-can-accept-sxg"should_encode_sxg_header": "...",响应应该转换为sxg的头,默认x-should-encode-sxg"header_prefix_filters": []抽离sxg文档头的前缀}
sxg全称signed exchange (SXG)
参考 https://web.dev/signed-exchanges/
4实战
4.1alternate_protocols_cache
缓存和解析 Alt-Svc http 头的,用于http3
httpsimple/ef-alternate_protocols_cache.yaml
kubectl apply -f ef-alternate_protocols_cache.yaml -n istio-system
apiVersion: networking.istio.io/v1alpha3kind: EnvoyFiltermetadata:name: simplespec:workloadSelector:labels:istio: ingressgatewayconfigPatches:- applyTo: HTTP_FILTERmatch:context: GATEWAYlistener:portNumber: 8080filterChain:filter:name: "envoy.filters.network.http_connection_manager"subFilter:name: "envoy.filters.http.router"patch:operation: INSERT_FIRSTvalue:name: envoy.filters.http.alternate_protocols_cachetyped_config:"@type": type.googleapis.com/envoy.extensions.filters.http.alternate_protocols_cache.v3.FilterConfigalternate_protocols_cache_options:name: protocols_cachemax_entries: 1024#key_value_store_config:
key_value_store_config配置文档没有说,有哪些类型
4.2cdn_loop
ef-cdn_loop.yaml
kubectl apply -f ef-cdn_loop.yaml -n istio-system
apiVersion: networking.istio.io/v1alpha3kind: EnvoyFiltermetadata:name: simplespec:workloadSelector:labels:istio: ingressgatewayconfigPatches:- applyTo: HTTP_FILTERmatch:context: GATEWAYlistener:portNumber: 8080filterChain:filter:name: "envoy.filters.network.http_connection_manager"subFilter:name: "envoy.filters.http.router"patch:operation: INSERT_FIRSTvalue:name: envoy.filters.http.cdn_looptyped_config:"@type": type.googleapis.com/envoy.extensions.filters.http.cdn_loop.v3alpha.CdnLoopConfigcdn_id: myidmax_allowed_occurrences: 0
由于我没有cdn,这个无法验证
4.3dynamo
Envoy 支持一个 HTTP 级 DynamoDB 嗅探过滤器,该过滤器有以下特性:
•DynamoDB API 请求/响应解析。•DynamoDB 按每操作、每数据库表、每分区以及操作的统计信息。•故障类型统计覆盖 4xx 响应、由响应 JSON 解析,例如 ProvisionedThroughputExceededException。•批处理操作部分失败的统计信息。
部署dynamodb
helm repo add keyporttech https://keyporttech.github.io/helm-charts/helm install dynamo keyporttech/dynamodb
ef-dynamo.yaml
kubectl apply -f ef-dynamo.yaml -n istio
apiVersion: networking.istio.io/v1alpha3kind: EnvoyFiltermetadata:name: simplespec:workloadSelector:labels:istio: ingressgatewayconfigPatches:- applyTo: HTTP_FILTERmatch:context: GATEWAYlistener:portNumber: 8080filterChain:filter:name: "envoy.filters.network.http_connection_manager"subFilter:name: "envoy.filters.http.router"patch:operation: INSERT_BEFOREvalue:name: envoy.filters.http.dynamotyped_config:"@type": type.googleapis.com/envoy.extensions.filters.http.dynamo.v3.Dynamo
4.4health_check
ef-health_check.yaml
kubectl apply -f ef-health_check.yaml -n istio-system
apiVersion: networking.istio.io/v1alpha3kind: EnvoyFiltermetadata:name: simplespec:workloadSelector:labels:istio: ingressgatewayconfigPatches:- applyTo: HTTP_FILTERmatch:context: GATEWAYlistener:portNumber: 8080filterChain:filter:name: "envoy.filters.network.http_connection_manager"subFilter:name: "envoy.filters.http.router"patch:operation: INSERT_BEFOREvalue:name: envoy.filters.http.health_checktyped_config:"@type": type.googleapis.com/envoy.extensions.filters.http.health_check.v3.HealthCheckpass_through_mode: truecache_time: 10mscluster_min_healthy_percentages:outbound|9080||productpage.istio.svc.cluster.local:value: 100headers:- name: testpresent_match: false
4.5ip_tagging
The implementation for IP Tagging provides a scalable way to compare an IP address to a large list of CIDR ranges efficiently.
ef-ip_tagging.yaml
kubectl apply -f ef-ip_tagging.yaml -n istio-system
apiVersion: networking.istio.io/v1alpha3kind: EnvoyFiltermetadata:name: simplespec:workloadSelector:labels:istio: ingressgatewayconfigPatches:- applyTo: HTTP_FILTERmatch:context: GATEWAYlistener:portNumber: 8080filterChain:filter:name: "envoy.filters.network.http_connection_manager"subFilter:name: "envoy.filters.http.router"patch:operation: INSERT_BEFOREvalue:name: envoy.filters.http.ip_taggingtyped_config:"@type": type.googleapis.com/envoy.extensions.filters.http.ip_tagging.v3.IPTaggingrequest_type: BOTHip_tags:- ip_tag_name: testip_list:- address_prefix: 0.0.0.0prefix_len: 0
具体使用案例,目前还不知道
4.6set_metadata
用来设置元数据
ef-set_metadata.yaml
kubectl apply -f ef-set_metadata.yaml -n istio-system
apiVersion: networking.istio.io/v1alpha3kind: EnvoyFiltermetadata:name: simplespec:workloadSelector:labels:istio: ingressgatewayconfigPatches:- applyTo: HTTP_FILTERmatch:context: GATEWAYlistener:portNumber: 8080filterChain:filter:name: "envoy.filters.network.http_connection_manager"subFilter:name: "envoy.filters.http.router"patch:operation: INSERT_BEFOREvalue:name: envoy.filters.http.set_metadatatyped_config:"@type": type.googleapis.com/envoy.extensions.filters.http.set_metadata.v3.Configmetadata_namespace: envoy.lbvalue:version: v1
4.7squash
部署:
squash-server.yaml
kubectl apply -f squash-server.yaml -n istio
apiVersion: v1kind: ServiceAccountmetadata:name: squash-server---kind: RoleapiVersion: rbac.authorization.k8s.io/v1beta1metadata:name: squash-pod-readerrules:- apiGroups: [""] # "" indicates the core API groupresources: ["pods"]verbs: ["get", "watch", "list"]---kind: RoleBindingapiVersion: rbac.authorization.k8s.io/v1beta1metadata:name: squash-read-pod-infosubjects:- kind: ServiceAccountname: squash-server# apiGroup: rbac.authorization.k8s.io # some reason this fails on kube 1.7.4roleRef:kind: Rolename: squash-pod-readerapiGroup: rbac.authorization.k8s.io---apiVersion: apps/v1beta1kind: Deploymentmetadata:name: squash-serverlabels:app: squash-serverspec:replicas: 1selector:matchLabels:app: squash-servertemplate:metadata:labels:app: squash-serverspec:serviceAccountName: squash-servercontainers:- name: squash-serverimage: soloio/squash-server:v0.2.0-46-gf2c3713ports:- containerPort: 8080protocol: TCPname: http-squash-api---kind: ServiceapiVersion: v1metadata:name: squash-serverspec:selector:app: squash-serverports:- name: http-squash-apiprotocol: TCPport: 80targetPort: 8080
squash-client.yaml
kubectl apply -f squash-client.yaml -n istio
apiVersion: extensions/v1beta1kind: DaemonSetmetadata:labels:app: squash-clientname: squash-clientspec:template:metadata:labels:app: squash-clientspec:hostPID: truecontainers:- name: squash-clientimage: soloio/squash-client:v0.2.0-46-gf2c3713volumeMounts:- mountPath: /var/run/cri.sockname: crisocksecurityContext:privileged: trueports:- containerPort: 1234protocol: TCPenv:- name: SERVERURLvalue: "http://$(SQUASH_SERVER_SERVICE_HOST):$(SQUASH_SERVER_SERVICE_PORT)"- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespace- name: HOST_ADDRvalue: "$(POD_NAME).$(POD_NAMESPACE)"- name: NODE_NAMEvalueFrom:fieldRef:fieldPath: spec.nodeNamevolumes:- name: crisockhostPath:path: /var/run/dockershim.sock
2019年开始就不更新了,这个不讲了
4.8sxg
The SXG filter is experimental and is currently under active development.
还在开发中,这个不讲了,也不知道干嘛用的。示例配置如下
cbor_url: "/.sxg/cert.cbor"validity_url: "/.sxg/validity.msg"certificate:name: certificatesds_config:path: "/etc/envoy/sxg-certificate.yaml"private_key:name: private_keysds_config:path: "/etc/envoy/sxg-private-key.yaml"duration: 432000smi_record_size: 1024client_can_accept_sxg_header: "x-custom-accept-sxg"should_encode_sxg_header: "x-custom-should-encode"header_prefix_filters:- "x-foo-"- "x-bar-"




