kubernetes nginx虚拟服务器子例程



我对kubernetes nginx虚拟子例程有点困惑。https://docs.nginx.com/nginx-ingress-controller/configuration/virtualserver-and-virtualserverroute-resources/#virtualserverroute-子程序

"在前缀的情况下,该路径必须以与引用该资源的VirtualServer的路由的路径相同的路径开始;

path: /coffee
action: 
path: coffee

咖啡会被传递到应用程序吗?

因为当我试图用路由部署虚拟服务器时,它不起作用(如下面的枫树(

path: /one
action: 
path: hellok8s

然而,我以前使用的这条路线正在使用

path: /
action: 
path: hellok8s

举个例子,如果我有一个app-1和app-2…我应该通过主机还是通过子路径来区分它们?

  • app-1:helloworld.test.com
  • app-2:helloworld2.test.com

或者有没有办法通过下面这样的路径来区分它们?

  • app-1:helloworld.test.com/appone
  • app-2:helloworld.test.com/apptwo

---编辑

apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: hellok8s-app-vs
spec:
host: helloworld.moonshot.com
tls:
secret: nginx-tls-secret
# basedOn: scheme
redirect:
enable: true
code: 301
upstream:
- name: hellok8s
service: hellok8s-service
port: 8080
routes:
- path: /one
action:
proxy:
upstream: hellok8s
rewritePath: /

因此,路径是Nginx将向外部世界公开的URL。该路径内部发生的情况取决于操作的子属性,例如:

这里/coffee是最终用户看到的,但请求被发送到咖啡服务的根。因此,如果咖啡是在8080运行的K8S中的服务,则请求将在coffee:8080处着陆

path: /coffee
action:
pass: coffee

但还有更多的行动。假设您使用action.proxy,那么您可以在更细粒度的级别上定义路径应该发生什么。因此,在下面的示例中,我们正在转发到coffee服务,但请求路径正在重新写入filtercoffee

proxy:
upstream: coffee
rewritePath: /filtercoffee 

您也可以使用重定向,返回操作中的pass指令,但您必须使用这里列出的四个之一

最新更新