简体   繁体   English

使用入口路由流量

[英]Route traffic using ingress

I had a working example of a project a year back, which is not working anymore.一年前我有一个项目的工作示例,该示例不再有效。

It's basically related to change in the behavior of nginx.ingress.kubernetes.io/rewrite-target property mentioned here - https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite它基本上与此处提到的nginx.ingress.kubernetes.io/rewrite-target属性的行为变化有关 - https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite

I have 3 application and I want to route based on conditions.我有 3 个应用程序,我想根据条件进行路由。

  • /* to frontend-cluster-ip-service /*到前端集群 IP 服务
  • /api/battleship/* to battleship-cluster-ip-service /api/battleship/*到 Battleship-cluster-ip-service
  • /api/connect4/* to connect-four-cluster-ip-service /api/connect4/* to connect-four-cluster-ip-service

The working example that was working an year back was一年前工作的工作示例是

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: frontend-cluster-ip-service
              servicePort: 3000
          - path: /api/connect4/
            backend:
              serviceName: connect-four-cluster-ip-service
              servicePort: 8080
          - path: /api/battleship/
            backend:
              serviceName: battleship-cluster-ip-service
              servicePort: 8080

However, this is not working anymore and only routing to / , ie to frontend-cluster-ip-service is working.但是,这不再起作用,只有路由到/ ,即到 frontend-cluster-ip-service 才起作用。 Routing to other serives fails and I get 404.路由到其他服务器失败,我得到 404。

Then I came to know about the change in nginx.ingress.kubernetes.io/rewrite-target .然后我才知道nginx.ingress.kubernetes.io/rewrite-target的变化。

I tried following then我试着跟随然后

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: frontend-cluster-ip-service
              servicePort: 3000
          - path: /api/connect4(/|$)(.*)
            backend:
              serviceName: connect-four-cluster-ip-service
              servicePort: 8080
          - path: /api/battleship(/|$)(.*)
            backend:
              serviceName: battleship-cluster-ip-service
              servicePort: 8080

Now the routing to connect-four-cluster-ip-service and battleship-cluster-ip-service is working but frontend-cluster-ip-service is not working and few js files loads are showing error:现在到connect-four-cluster-ip-servicebattleship-cluster-ip-service的路由正在工作,但frontend-cluster-ip-service不起作用,并且很少有 js 文件加载显示错误:

在此处输入图片说明

I had the same issue with a bit more complicated rewrite (it was only for one different path).我在更复杂的重写时遇到了同样的问题(它只针对一个不同的路径)。

Making multiple Ingresses for each path worked for me but might not be the cleanest solution.为每条路径制作多个 Ingress 对我有用,但可能不是最干净的解决方案。

My ingress definition: https://github.com/FORTH-ICS-INSPIRE/artemis/blob/master/artemis-chart/templates/ingresses.yaml我的入口定义: https : //github.com/FORTH-ICS-INSPIRE/artemis/blob/master/artemis-chart/templates/ingresses.yaml

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

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