Enabling GZIP compression with Istio

Although Istio documentation does not specify how to enable GZIP compression, it is in fact possible to enable it via the built-in Compressor filter.

Assuming that you want to enable GZIP compression on specific applications, the following EnvoyFilter manifest will do the trick:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: gzip
spec:
workloadSelector:
labels:
# Put same labels that will identify your application
app.kubernetes.io/instance: my-application
configPatches:
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
filterChain:
filter:
name: envoy.http_connection_manager
subFilter:
name: envoy.router
patch:
operation: INSERT_BEFORE
value:
name: envoy.filters.http.compressor
typed_config:
# See https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/compressor_filter for full options
'@type': type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor
compressor_library:
name: text_optimized
typed_config:
'@type': type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip
remove_accept_encoding_header: true

It is also possible to enable the compression globally at Istio gateway level. For that, you can replace “context” with “GATEWAY” and switch workloadSelector to a selector that will match to Istio gateways. (e.g. app: istio-ingressgateway)

typed_config is an important field where you can configure the filter. There are quite some configuration options you can check at the filter documentation. I am enabling remove_accept_encoding_header to make sure that the sidecar proxy strips away the Accept-Encoding header, so my application, if it accepts this header, does not attempt to compress the response.

Software Development Manager @ebay, and Founder of @instelacom. Author of Building Serverless Architectures and AWS Certified Solutions Architect.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store