Skip to content

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Use a custom Envoy image

Page as Markdown

Build a custom envoy-wrapper image on top of any upstream Envoy release and point kgateway at it, without waiting for an official kgateway release.

Build a custom envoy-wrapper image on top of any upstream Envoy release and use it in your gateway proxies. For example, this process can be useful to apply CVE fixes that were released upstream, but aren’t yet released in kgateway.

How it works

The kgateway data plane isn’t a plain Envoy binary. It bundles two extra components on top of upstream Envoy:

  • envoyinit: A Go binary that runs as PID 1, manages the Envoy process lifecycle, and injects bootstrap configuration from xDS.
  • librust_module.so: A Rust dynamic module that powers kgateway’s transformation engine (rustformation) and other data-plane features. Envoy loads this .so module at startup through its Dynamic Modules API.

Because the Dynamic Modules ABI is tied to a specific Envoy minor version, you can’t swap in a plain upstream Envoy image. Instead, you must build the module and image together. The envoy-wrapper-docker Makefile target handles this: it compiles the Rust module against the Envoy SDK and layers it on top of whatever base image you pass in.

Compatibility

The Rust dynamic module is compiled against the envoy-proxy-dynamic-modules-rust-sdk, which is pinned to the same Envoy version that kgateway targets in a given release. This means:

  • Patch-version bumps are safe. The Dynamic Modules ABI is stable within a minor release. If kgateway targets v1.37.2, you can safely use v1.37.3 or any other v1.37.x patch.
  • Minor-version bumps aren’t a simple image swap. Going from v1.37.x to v1.38.x means updating the SDK pin and rebuilding the module. That’s a full Envoy upgrade at the kgateway source level, not something you’d do with this guide.

If you are unsure which Envoy minor version your kgateway release targets, check the ENVOY_IMAGE variable at the top of the project Makefile.

Before you begin

  1. Clone the kgateway repository at the same version as the kgateway control plane running in your cluster. For example, if your cluster runs kgateway v2.3.0, check out the v2.3.0 tag. The Rust module gets compiled from that checkout, so the versions need to line up.

    git clone https://github.com/kgateway-dev/kgateway.git
    cd kgateway
    git checkout v2.3.0
  2. Set up a Docker engine with BuildKit / buildx support. For example, you can install the Docker Desktop app.

  3. Set up a container registry that your cluster can pull from and connect to it. If your cluster pulls from a private registry, set up image pull secrets on the proxy pods. You can add them with the podTemplate.imagePullSecrets field in GatewayParameters.

  4. Install rustup, the Rust toolchain installer. The correct Rust version is then picked up automatically from the rust-toolchain.toml file in the repository.

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Step 1: Build the wrapper image

Set the following environment variables, then run the build target.

  • ENVOY_IMAGE: The upstream Envoy image that you want to use as the base image.
  • IMAGE_REGISTRY: Your container registry path. This is where the built envoy-wrapper image gets pushed.
  • VERSION: The image version tag for your custom image, such as v2.3.0-custom. This tag is used to name the output image as $IMAGE_REGISTRY/envoy-wrapper:$VERSION.
  1. Set the environment variables.

    export ENVOY_IMAGE=docker.io/envoyproxy/envoy:v1.37.3
    export IMAGE_REGISTRY=registry.example.com/myorg
    export VERSION=v2.3.0-custom
  2. Build the custom image.

    make envoy-wrapper-docker

    Under the hood, this:

    1. Builds the Rust dynamic module (librust_module.so) from internal/envoy_modules/ by using cargo-zigbuild.
    2. Creates a Dockerfile that sets the ENVOY_IMAGE as the base image (FROM entry).
    3. Copies the compiled .so library, envoyinit binary, and entrypoint script to the output directory.
    4. Builds the image with docker buildx build and tags the image as $IMAGE_REGISTRY/envoy-wrapper:$VERSION.

    By default, the build targets your host architecture. If you’re on an arm64 machine but need an amd64 image, set GOARCH explicitly:

    GOARCH=amd64 ENVOY_IMAGE=... IMAGE_REGISTRY=... VERSION=... make envoy-wrapper-docker
  3. Verify the image is available locally.

    docker images registry.example.com/myorg/envoy-wrapper

    Example output:

    REPOSITORY                               TAG            IMAGE ID       CREATED         SIZE
    registry.example.com/myorg/envoy-wrapper v2.3.0-custom  d3f1a2b3c4e5   1 minute ago    200MB

Step 2: Push the image

docker push registry.example.com/myorg/envoy-wrapper:v2.3.0-custom

Step 3: Customize the Envoy image

Create a GatewayParameters resource that points spec.kube.envoyContainer.image to your custom wrapper image.

kubectl apply -f- <<EOF
apiVersion: gateway.kgateway.dev/v1alpha1
kind: GatewayParameters
metadata:
  name: custom-envoy-image
  namespace: kgateway-system
spec:
  kube:
    envoyContainer:
      image:
        registry: registry.example.com/myorg
        repository: envoy-wrapper
        tag: v2.3.0-custom
EOF

The image field follows the same structure used for all container images in kgateway:

FieldDescription
registryContainer registry hostname, for example registry.example.com/myorg
repositoryImage name, typically envoy-wrapper
tagImage tag
digestOptional. Use instead of or alongside tag to pin to an exact image digest
pullPolicyOptional. Defaults to IfNotPresent

Step 4: Reference the GatewayParameters from your Gateway

Create or update your Gateway resource to reference the GatewayParameters you just created.

kubectl apply -f- <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: my-gateway
  namespace: kgateway-system
spec:
  gatewayClassName: kgateway
  infrastructure:
    parametersRef:
      group: gateway.kgateway.dev
      kind: GatewayParameters
      name: custom-envoy-image
  listeners:
    - name: http
      protocol: HTTP
      port: 80
      allowedRoutes:
        namespaces:
          from: All
EOF

When kgateway reconciles this Gateway, it creates a proxy Deployment with the custom image. Existing proxy pods roll over automatically.

Apply to all gateways by default

If you want every Gateway using the kgateway GatewayClass to pick up your custom image automatically, set the gatewayClassParametersRefs.kgateway Helm value instead of attaching the GatewayParameters to each Gateway individually.

  1. Get the current Helm values for your kgateway installation.

    helm get values kgateway -n kgateway-system -o yaml > values.yaml
  2. Configure the kgateway GatewayClass with the GatewayParameters resource that you created earlier. Add the following to your values.yaml file.

    gatewayClassParametersRefs:
      kgateway:
        name: custom-envoy-image
        namespace: kgateway-system
  3. Upgrade your kgateway installation with the updated values.

    helm upgrade -i -n kgateway-system kgateway \
      --version v2.4.7 \
      oci://cr.kgateway.dev/kgateway-dev/charts/kgateway \
      -f values.yaml

Verify

Check that the proxy pods are running the custom image.

kubectl get pods -n kgateway-system -l gateway.networking.k8s.io/gateway-name=my-gateway \
  -o jsonpath='{.items[0].spec.containers[0].image}'

Example output:

registry.example.com/myorg/envoy-wrapper:v2.3.0-custom

Cleanup

You can remove the resources that you created in this guide.
kubectl delete gateway my-gateway -n kgateway-system
kubectl delete GatewayParameters custom-envoy-image -n kgateway-system
Was this page helpful?