简体   繁体   English

Kubernetes nginx 入口路由路径

[英]Kubernetes nginx ingress route paths

How do I rewrite the URI and send it to two different services?如何重写 URI 并将其发送到两个不同的服务? With this example from Azure.这个例子来自 Azure。 It route all traffic to "aks-helloworld" on https://demo.azure.com/ .它将所有流量路由到https://demo.azure.com/上的“aks-helloworld”。 However, if the url is: https://demo.azure.com/hello-world-two the traffic is sent to service "ingress-demo".但是,如果 url 是: https://demo.azure.com/hello-world-two流量被发送到服务“ingress-demo” This is fine.这可以。

The problem is when I request https://demo.azure.com/hello-world-two/test .问题是当我请求https://demo.azure.com/hello-world-two/test时。 How do I request an handler "/test" on the "ingress-demo" service?如何在“ingress-demo”服务上请求处理程序“/test”?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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