关于istio:istio关于开启gzip压缩

12次阅读

共计 2315 个字符,预计需要花费 6 分钟才能阅读完成。

简介

开始阶段咱们在 kubernetes 中应用 ingress-nginx 来提供 http 对外暴漏服务,因为服务网格的风行,开始将 ingress 切换了 istio,通常只是应用了gatewayvs相干性能和一些网络鉴权性能,前期业务需要,须要 http 压缩性能,所以须要开启 istiogzip性能,经官网文档 istio 默认时没有开启压缩的性能,然而能够通过 EnvoyFilter 来对代理进行插件扩大。

环境

  • kubernetes1.18 版本
  • istio 1.10.1 版本。

压缩计划

  1. gateway进行压缩,对此 gateway 下的 http 业务对立都进行压缩。
  2. sidecat压缩,对指定业务进行压缩。

单个压缩

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: gzip
spec:
  workloadSelector:
    labels:
      app: productpage #抉择你要压缩的利用
  configPatches:
    - applyTo: HTTP_FILTER #指定利用 envoy 配置中的补丁地位
      match:
        context: SIDECAR_INBOUND #sidercar 入站的路由监听集群
        listener:
          filterChain: #匹配监听器中特定的过滤链
            filter: #要利用补丁的特定过滤器的名称
              name: envoy.filters.network.http_connection_manager #匹配的过滤器名称
              subFilter: #匹配上级过滤器名称
                name: envoy.filters.http.router
      patch:
        operation: INSERT_BEFORE #进行的操作 进行插入操作
        value: ### 插入 envoy 配置
          name: envoy.filters.http.compressor 
          typed_config:
            '@type': type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor
            response_direction_config:
              common_config:
                content_type:
                  - text/html
                  - text/css
                  - application/javascript
              disable_on_etag_header: true
            request_direction_config:
              common_config:
                enabled:
                  default_value: false
                  runtime_key: request_compressor_enabled                
            compressor_library:
              name: text_optimized
              typed_config:     
                '@type': type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip
                compression_level: BEST_COMPRESSION
                compression_strategy: DEFAULT_STRATEGY 

网关压缩

 kind: EnvoyFilter
 metadata:
   name: gzip
   namespace: istio-system
 spec:
   workloadSelector:
     labels:
       app: istio-ingressgateway
   configPatches:
     - applyTo: HTTP_FILTER
       match:
-        context: SIDECAR_INBOUND
+        context: GATEWAY
         listener:
           filterChain:
             filter:
            name: envoy.filters.network.http_connection_manager #匹配的过滤器名称
              subFilter: #匹配上级过滤器名称
                name: envoy.filters.http.router
      patch:
        operation: INSERT_BEFORE #进行的操作 进行插入操作
        value: ### 插入 envoy 配置
          name: envoy.filters.http.compressor 
          typed_config:
            '@type': type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor
            response_direction_config:
              common_config:
                content_type:
                  - text/html
                  - text/css
                  - application/javascript
              disable_on_etag_header: true
            request_direction_config:
              common_config:
                enabled:
                  default_value: false
                  runtime_key: request_compressor_enabled                
            compressor_library:
              name: text_optimized
              typed_config:     
                '@type': type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip
                compression_level: BEST_COMPRESSION
                compression_strategy: DEFAULT_STRATEGY 

参考文档

  1. https://www.envoyproxy.io/doc…
  2. https://istio.io/latest/docs/…

正文完
 0