1

I have a situation like this:

                    internet
                        |
   [ IngressController -namespace:kube-sustem ]
        |                                   |
   [ Ingress A -namespace:ocelot-ns]       [ Ingress B -namespace:private-ns]
        --|-----|--                                  --|-----|--
     [ Service ocelot]                           [ Service userservice]
           |                                            |
        [ Pod A]                                     [ Pod B]

Ingres A and Ingres B do not route more complex paths that should be resolved by regex rule, it seems like the regex is not working. example from ingress A yaml:

This combination does not work:

  anotations:
    kubernetes.io/ingress.class: addon-http-application-routing
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/ssl-redirect: 'false'
    nginx.ingress.kubernetes.io/use-regex: 'true'

path: /gateway(/|$)(.*)
pathType: ImplementationSpecific
backend:
  serviceName: ocelot
  servicePort: 80

This combination works:

kubernetes.io/ingress.class: addon-http-application-routing

path: /gateway
pathType: ImplementationSpecific
backend:
   serviceName: ocelot
   servicePort: 80

When I try to curl from Pod A(ocelot gateway) I can get response from pod B curl -v http://localhost/gateway/api/test

This is working ocelot config:

"DownstreamHostAndPorts": [
    {
      "Host": "userservice.private-ns",
      "Port": "80"
    }
  ],
  "UpstreamPathTemplate": "/gateway/api/test",

I'm stuck here :/ What I would like to have is one api-gateway(ocelot) and other apps behind it. So I think need to configure ingress A to handle any path since this will route everything to ocelot api gateway.

I started doing it this way, not sure if this is ok since I'm Kubernetes beginner. FYI I'm using Azure Kubernetes service

user1598696
  • 550
  • 1
  • 4
  • 22

1 Answers1

0

Your ingress spec is this:

   anotations:
    kubernetes.io/ingress.class: addon-http-application-routing
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/ssl-redirect: 'false'
    nginx.ingress.kubernetes.io/use-regex: 'true'

path: /gateway(/|$)(.*)
pathType: ImplementationSpecific
backend:
  serviceName: ocelot
  servicePort: 80

You're using /$1 as your capture group, but your regex is using capture group 1 to strip the trailing slash. Your actual path is capture group 2. Change that line to nginx.ingress.kubernetes.io/rewrite-target: /$2.

anaximander
  • 7,083
  • 3
  • 44
  • 62