Skip to content

K8s controller to enable gzip in a Istio K8s cluster without having to understand the complexities of Envoy and Istio

Notifications You must be signed in to change notification settings

vadasambar/httpgzip

Repository files navigation

httpgzip

Httpgzip offers a Custom Resource to enable http gzip compression for your services in a Kubernetes cluster (with Istio installed) without having to understand the complexities of Envoy and Istio. It uses Istio's EnvoyFilter custom resource under the hood.

Note: httpgzip has been tested with 1.14.0 version of Istio

Please create an issue and mention @vadasambar if you want to use this controller for other versions of Istio.

Custom resource

apiVersion: apps.vadasambar.com/v1alpha1
kind: HttpGzip
metadata:
  name: httpgzip-sample
spec:
  applyTo:
    # supports [gateway, pod]
    kind: pod
    # apply gzip compression to the kind with the following labels
    selector:
      app: productpage

Above creates an EnvoyFilter resource which looks like this for Istio Gateways and like this for K8s Pods.

Before (notice the bottom right part of the screenshot. You can see gzip is not enabled): before After applying the HttpGzip custom resource (notice the bottom right part of the screenshot): after

Getting Started

You’ll need a Kubernetes cluster to run against. You can use KIND or K3D to get a local cluster for testing, or run against a remote cluster. Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster kubectl cluster-info shows).

Running on the cluster

  1. Build and push your image to the location specified by IMG:
make docker-build docker-push IMG=<some-registry>/httpgzip:tag
  1. Deploy the controller to the cluster with the image specified by IMG:
make deploy IMG=<some-registry>/httpgzip:tag

^ this installs CustomResourceDefinitions as well.

  1. Install Instances of Custom Resources:
kubectl apply -f config/samples/

Undeploy controller

UnDeploy the controller to the cluster:

make undeploy

FAQ

How do I test if the EnvoyFilter works?

  1. You can create a k3d cluster with LoadBalancer like this:
k3d cluster create mycluster -p "8082:80@loadbalancer" --k3s-server-arg "--kube-proxy-arg=conntrack-max-per-core=0"  --k3s-agent-arg "--kube-proxy-arg=conntrack-max-per-core=0" --agents 5 --registry-create

8082:80@loadbalancer exposes LoadBalancer at 8082 port of localhost (check official docs for more info).
2. Map your host name in VirtualService/Gateway to 127.0.0.1 in etc/hosts like this:

suraj@suraj:~$ cat /etc/hosts
127.0.0.1	localhost
127.0.0.1	helloworld.com
127.0.0.1	bookinfo.com
...
  1. Access the host in browser using url like http://bookinfo.com:8082/productpage
  2. Check the response headers in browser developer tools to see if gzip is enabled or not. gzip enabled

Contributing

Any contributions are welcome! This project uses Operator Framework. If you find any issues,

  • Create an issue and mention @vadasambar OR
  • Raise a PR and mention @vadasambar.

How it works

This project aims to follow the Kubernetes Operator pattern

It uses Controllers which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster

Test It Out

  1. Install the CRDs into the cluster:
make install
  1. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
make run

NOTE: You can also run this in one step by running: make install run

Modifying the API definitions

If you are editing the API definitions, generate the manifests such as CRs or CRDs using:

make manifests

NOTE: Run make --help for more information on all potential make targets

More information can be found via the Kubebuilder Documentation

License

Copyright 2022.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

K8s controller to enable gzip in a Istio K8s cluster without having to understand the complexities of Envoy and Istio

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published