简体   繁体   中英

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(/|$)(.*)

I solved it, by changing the path to this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM