Kubernetes: GatewayAPI URLRewrite Filter

In this example, request to /echo or /echo/ (because of the type: PathPrefix) will be rewritten as / and becomes the request of “web” Service.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: web
spec:
  parentRefs:
  - name: nginx
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /echo
    backendRefs:
    - name: web
      kind: Service
      port: 80
    filters:
    - type: URLRewrite
      urlRewrite:
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: /

In this example, request only to /echo (because of the type: Exact) will be rewritten as / and becomes the request of “web” Service.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: web
spec:
  parentRefs:
  - name: nginx
  rules:
  - matches:
    - path:
        type: Exact
        value: /echo
    backendRefs:
    - name: web
      kind: Service
      port: 80
    filters:
    - type: URLRewrite
      urlRewrite:
        path:
          type: ReplaceFullPath
          replaceFullPath: /


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *