Kubernetes nginx 入口路由路径

Kubernetes nginx ingress route paths

如何重写 URI 并将其发送到两个不同的服务? 使用 Azure 中的这个示例。它将所有流量路由到 https://demo.azure.com/. However, if the url is: https://demo.azure.com/hello-world-two 上的 "aks-helloworld",流量被发送到服务 "ingress-demo"。这可以。

问题出在我请求 https://demo.azure.com/hello-world-two/test 时。 如何在 "ingress-demo" 服务上请求处理程序“/test”?

逻辑上你会想写:
/hello-world-two/*

/*
然后这会将请求发送到正确的服务。

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

我解决了, 通过将路径更改为此:

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