如何在Kubernetes中路由基于端口或特定路径的路由

时间:2020-07-05 16:03:12

标签: kubernetes routes portforwarding nginx-ingress

我有两项服务,并使用端口转发在本地主机的不同代理中转发它们。例如,可以通过localhost:port1访问service1,可以通过localhost:port2访问service2。

在service1的工作流中,在service1的UI中,有时会生成一个新链接,例如"localhost:port1/_/path"。但是它实际上可以在service2中用于该链接。我可以通过将port1更改为port2来访问然后链接,但无法使用生成的链接访问。我的意思是我可以访问"localhost:port2/_/path",而不是由service1后端生成的“ localhost:port1/_/path"”。如果service {1}中存在路径"_/path",我想进行端口路由。我该怎么做?我阅读了入口文档,找不到端口路由示例。 谢谢!

1 个答案:

答案 0 :(得分:1)

您需要部署nginx入口控制器并设置基于路径的路由。请点击链接以供参考

https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/ingress-path-matching.md