HTTP responses from backend services often contain compressible text content such as HTML, JSON, and CSS. Without compression, the ingress gateway forwards these responses at full size, which increases bandwidth costs and slows client load times. Gzip compression on the ASM ingress gateway compresses eligible responses before they reach the client, reducing response sizes and improving transfer speed.
How it works
When a client sends an HTTP request with the Accept-Encoding: gzip header, the ingress gateway compresses the response body before returning it. The gateway compresses a response only when all of the following conditions are met:
The request includes
Accept-Encoding: gzip(or*).The response
Content-Typematches one of the types specified incompression.content_type.The response is not already compressed (no existing
Content-Encodingheader).
If remove_accept_encoding_header is set to true, the gateway strips the Accept-Encoding header before forwarding the request upstream. This prevents the upstream service from compressing the response on its own, keeping the gateway as the single point of compression.
Prerequisites
A cluster is added to the ASM instance. See Add a cluster to an ASM instance.
An ingress gateway is deployed. See Create an ingress gateway.
A sample application is deployed in the Container Service for Kubernetes (ACK) cluster, with a virtual service and Istio gateway routing traffic through the ASM ingress gateway. If you do not have an existing application, see Set up a sample application.
An Internet Content Provider (ICP) filing is obtained for a domain name if you want to use one.
Configure gzip compression
Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.
On the Mesh Management page, find the target ASM instance. Click the instance name or click Manage in the Actions column.
In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.
On the Ingress Gateway page, find the target ingress gateway and click YAML.
In the Edit dialog box, add the following
compressionblock to the YAML and click OK.compression: content_type: - text/html enabled: true gzip: memory_level: 9 remove_accept_encoding_header: true
Configuration reference
The table below describes the compression fields. For all ingress gateway fields, see Create and manage an ingress gateway by using the Kubernetes API.
| Field | Description |
|---|---|
compression.enabled | Specifies whether to enable data compression for the ingress gateway service. |
compression.content_type | The Content-Type values eligible for compression. Only responses with a matching Content-Type header are compressed. |
compression.gzip.memory_level | The amount of internal memory used for compression. Higher values use more memory but can produce better compression. |
compression.remove_accept_encoding_header | Whether to strip the Accept-Encoding header before forwarding requests to the upstream service. Set to true to prevent the upstream from double-compressing responses. |
Note: Specify multiple content types to compress a wider range of responses. Common types includetext/html,application/json,application/javascript,text/css,text/plain, andapplication/xml.
Verify compression
After you configure compression, confirm that the ingress gateway returns gzip-compressed responses.
Get the external IP address of the ingress gateway.
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click the cluster name. In the left-side navigation pane, choose Network > Services.
On the Services page, select istio-system from the Namespace drop-down list. Find istio_ingressgateway and note the IP address for port 80 in the External IP column.
Send a request with the
Accept-Encoding: gzipheader and check the response headers. Replace<ingress-gateway-ip>with the external IP address from step 1.curl -s -o /dev/null -D - -H "Accept-Encoding: gzip" http://<ingress-gateway-ip>/Check the output. If the response includes
content-encoding: gzip, compression is working.HTTP/1.1 200 OK content-encoding: gzip content-type: text/html ...If the
content-encodingheader is absent, verify the following:The request includes the
Accept-Encoding: gzipheader.The response
Content-Typematches a type listed incompression.content_type.compression.enabledis set totrue.The response is not already compressed by the upstream service. If
remove_accept_encoding_headerisfalse, the upstream may have applied its own compression, and the gateway skips re-compression.
Alternatively, open Chrome DevTools (More tools > Developer tools), navigate to the ingress gateway IP address, and look for
content-encoding: gzipin the Response Headers section of the Network tab.
Set up a sample application (optional)
If you do not have an existing application behind the ingress gateway, deploy a sample NGINX application with the required Istio gateway and virtual service.
Step 1: Deploy the NGINX application
Create a file named nginx.yaml with the following content and apply it to the ACK cluster.
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
sidecarset-injected: "true"
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: ClusterIPkubectl apply -f nginx.yamlStep 2: Create the Istio gateway and virtual service
In the ASM console, navigate to the details page of your ASM instance.
In the left-side navigation pane, choose ASM Gateways > Gateway. Click Create from YAML.
Select a namespace, paste the following YAML, and click Create.
apiVersion: networking.istio.io/v1beta1 kind: Gateway metadata: name: nginx-gateway namespace: default spec: selector: istio: ingressgateway servers: - hosts: - '*' port: name: http number: 80 protocol: HTTPIn the left-side navigation pane, choose Traffic Management Center > VirtualService. Click Create from YAML.
Select a namespace, paste the following YAML, and click Create.
apiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: nginx namespace: default spec: gateways: - nginx-gateway hosts: - '*' http: - match: - uri: exact: / route: - destination: host: nginx port: number: 80
After the gateway and virtual service are created, return to Configure gzip compression to enable compression on the ingress gateway.
What's next
Create and manage an ingress gateway by using the Kubernetes API -- full reference for ingress gateway YAML fields.