Skip to content

WebAssembly

In this scenario we demonstrate how to apply a wasm extension to an HttpRoute.

You will apply an extension policy that references a simple, pre-built wasm plugin to the HttpRoute for the httpbin sample application.

The basic logic of the plugin is to inject arbitrary, configurable headers into HTTP responses on the associated route.

Context

httpbin is already deployed to the default namespace and the simple HttpRoute is already defined for it.

Instructions

  1. Send a test request to the httpbin route:

     curl -v http://httpbin.esuez.org/json --resolve httpbin.esuez.org:80:$GATEWAY_IP
    

    The request should succeed, and return some json.

    Note the headers in the HTTP response.

  2. Review the following extension policy:

    ---
    apiVersion: gateway.envoyproxy.io/v1alpha1
    kind: EnvoyExtensionPolicy
    metadata:
      name: wasm-plugin
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: HTTPRoute
        name: httpbin
      wasm:
      - code:
          type: Image
          image:
            url: us-central1-docker.pkg.dev/eitan-tetrate/misc-repo/wasm:v1
        config:
          header_1: my first header
          header_2: "yet another header.."
    

    Apply the policy:

    kubectl apply -f wasm/extension-policy.yaml
    
  3. Repeat the request:

    curl -v http://httpbin.esuez.org/json --resolve httpbin.esuez.org:80:$GATEWAY_IP
    

    Note the response headers contain extra headers from the configuration of the wasm plugin.