TryingMyBest
TryingMyBest

Reputation: 131

Kubernetes nginx ingress route paths

How do I rewrite the URI and send it to two different services? With this example from Azure. It route all traffic to "aks-helloworld" on https://demo.azure.com/. However, if the url is: https://demo.azure.com/hello-world-two the traffic is sent to service "ingress-demo". This is fine.

The problem is when I request https://demo.azure.com/hello-world-two/test. How do I request an handler "/test" on the "ingress-demo" service?

Logically you would think to write:
/hello-world-two/*
and
/*
And this would then send the request to the correct service.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-world-ingress
  namespace: ingress-basic
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  tls:
  - hosts:
    - demo.azure.com
    secretName: aks-ingress-tls
  rules:
  - host: demo.azure.com
    http:
      paths:
      - backend:
          serviceName: aks-helloworld
          servicePort: 80
        path: /(.*)
      - backend:
          serviceName: ingress-demo
          servicePort: 80
        path: /hello-world-two(/|$)(.*)

Upvotes: 1

Views: 762

Answers (1)

TryingMyBest
TryingMyBest

Reputation: 131

I solved it, by changing the path to this:

      - backend:
          serviceName: ingress-demo
          servicePort: 80
        path: /hello-world-two/?(.*)

Upvotes: 2

Related Questions