0

My goal is to have a single Gateway that can be used to host multiple applications at different paths. The URLRewrite filter exists, however, when it does not seem to be working as expected.

Using Cilium's Hubble for example, I have the following resource:

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: hubble
  namespace: kube-system
spec:
  parentRefs:
    - name: gateway
      namespace: gateway-system
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /hubble
      filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /
      backendRefs:
        - name: hubble-ui
          port: 80

I would like to navigate to http://k8s-ingress/hubble to access Hubble, http://k8s-ingress/argo-cd to access Argo CD, http://k8s-ingress/foobar to access Foobar, etc.

However, when I apply this resource and navigate to http://k8s-ingress/hubble, I do get a response, but it's an empty page, not the normal Hubble dashboard. (I can tell that the server is responding, however, because the browser tab name is set to Hubble UI.

enter image description here

And if I curl it I do get a response:

$> curl http://k8s-ingress/hubble
<!doctype html><html><head><meta charset="utf-8"/><title>Hubble UI</title><base href="/"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,user-scalable=0,initial-scale=1,minimum-scale=1,maximum-scale=1"/><link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png"/><link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png"/><link rel="shortcut icon" href="favicon.ico"/><script defer="defer" src="bundle.main.104f057a7d45238d9d45.js"></script><link href="bundle.main.3818224e482785607640.css" rel="stylesheet"></head><body><div id="app"></div></body></html>%

I assume things aren't working because my server is treating my request like it's targeted at /hubble instead of /. Which doesn't normally resolve to anything. But isn't that the point of URLRewrite/ReplacePrefixMatch? To rewrite the path of a URI before routing to the server?

Perhaps I'm misremembering, but isn't this how things work under Istio? For example the following VirtualService spec:

http:
  - match:
      - uri: 
          prefix: /hubble
    route:
      - destination:
          host: hubble-ui
          port: 
            number: 80
    rewrite:
      uri: /

I've also tried to use URLRewrite/ReplaceFullPath but it results in the same behavior as above.

    - matches:
        - path:
            type: PathPrefix
            value: /hubble
      filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplaceFullPath
              replaceFullPath: /
      backendRefs:
        - name: hubble-ui
          port: 80

RequestRedirect/ReplaceFullpath works somewhat. In that I can navigate to http://k8s-ingress/hubble and have my browser 302-redirected to http://k8s-ingress where I can successfully hit the Hubble UI. But this isn't what I want, as I would only be able to host a single application on the gateway at /.

    - matches:
        - path:
            type: PathPrefix
            value: /hubble
      filters:
        - type: RequestRedirect
          requestRedirect:
            path:
              type: ReplaceFullPath
              replaceFullPath: /
            statusCode: 302
    - backendRefs:
        - name: hubble-ui
          port: 80

1 Answer 1

1

I could not get / to work but when I thought about it as a Route for my REST services it made more sense to me. The following works.

 rules:
  - matches:
    - path:
        type: PathPrefix
        value: /api/weather
    filters:
      - type: URLRewrite
        urlRewrite:
          path:
            type: ReplacePrefixMatch
            replacePrefixMatch: /weatherforecast
    backendRefs:
    - name: weather-svc
      port: 8080

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.