Home > Enterprise >  Why ingress rewrite not work in openshift?
Why ingress rewrite not work in openshift?

Time:11-05

I create a ingress by this example:

$ echo '
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
spec:
  ingressClassName: nginx
  rules:
  - host: my.hostname.com
    http:
      paths:
      - path: /something(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: http-svc
            port: 
              number: 80
' | kubectl create -f -

But if I go to my.hostname.com/something the route is not matched, even if I changed it to

$ echo '
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: rewrite
spec:
  ingressClassName: nginx
  rules:
  - host: my.hostname.com
    http:
      paths:
      - path: /something
        pathType: Prefix
        backend:
          service:
            name: http-svc
            port: 
              number: 80
' | kubectl create -f -

The route pass me to http-svc but the rewrite is not working.

So how can I do a complex rewrite which haproxy.router.openshift.io/rewrite-target: / can not provide?

CodePudding user response:

OpenShift routers aren't based on nginx, so nginx annotations/rules aren't going to do anything. If the builtin HAProxy based functionality doesn't meet your needs, you'd have to either install an nginx based ingress controller or handle the rewrite at the application level.

  • Related