Focusing specifically on the title of this question and extending on the example of such setup as pointed by user @Raunak Jhawar.
You can configure your nginx-ingress to compress the data by updating the ingress-nginx-controller configmap.
This would work on the path:
Pod ----> NGINX Ingress controller - GZIP -> Client (Web browser)
To enable such setup you will need to edit the Ingress controller configmap like below:
$ kubectl edit configmap -n ingress-nginx ingress-nginx-controller
data: # ADD IF NOT PRESENT
use-gzip: "true" # ENABLE GZIP COMPRESSION
gzip-types: "*" # SPECIFY MIME TYPES TO COMPRESS ("*" FOR ALL)
You can find more reference and options to configure by following below link:
A side note!
You can also use other methods of editing resources like: $ kubectl patch
This changes would make the nginx-ingress-controller Pod to be automatically reconfigured.
I've included an example of such setup below.
To check if the compression occurs and if it's working I've used following setup:
NGINX Ingress Controller spawned by:
NGINX pod with a 5mb.txt file filled with 0's
Service and Ingress resource that will expose the NGINX pod with NGINX Ingress Controller
You can check if your setup with nginx-ingress supoorts gzip compression by either:
Above methods have shown the compression rate of about 99% (5MB file compressed to 50KB)
I also encourage you to check below links for additional reference: