kubernetes nginx 虚拟服务器子路由

kubernetes nginx virtual server subroute

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

"In the case of a prefix, the path must start with the same path as the path of the route of the VirtualServer that references this resource"

path: /coffee
action: 
    path: coffee

/coffee 会被传递到应用程序吗?

因为当我尝试使用路由部署虚拟服务器时它不起作用(下面的示例)

path: /one
action: 
    path: hellok8s

然而,我之前使用的这条路线是有效的

path: /
action: 
    path: hellok8s

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

或者有什么方法可以通过如下路径区分它们?

--- 编辑

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: /

所以路径是 URL,它将被 Nginx 暴露给外界。该路径在内部会发生什么取决于操作的子属性,一些示例:

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

path: /coffee
 action:
  pass: coffee

但是还有更多 actions. And let's say you use the action.proxy 那么您可以在更精细的级别定义路径应该发生什么。所以在下面的例子中,我们转发到 coffee 服务,但请求路径被重写为 filtercoffee

proxy:
  upstream: coffee
  rewritePath: /filtercoffee 

你也可以在action的pass指令中使用重定向,return,但是你必须use one of the four listed here