Reputation: 360
I am abit confused on the kubernetes nginx virtual subroute. 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
will the /coffee be passed to the app?
because when I try to deploy the virtualserver with the route it doesn't work (exmaple below)
path: /one
action:
path: hellok8s
however, this route that I am using previously is working
path: /
action:
path: hellok8s
So taking for example, if I have an app-1 and app-2... Should I differentiate them through the host or through a sub-path?
or is there way that I can differentiate them through path like below?
--- edit
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: /
Upvotes: 1
Views: 1032
Reputation: 4407
So the path is the URL which will be exposed by the Nginx to world outside. What happens to that path internally depends on the action's sub attributes, some examples:
Here the /coffee
is what end user sees but the request is sent to root of coffee service. So if the coffee would be a service in K8S running at 8080, the request will land at coffee:8080
path: /coffee
action:
pass: coffee
But there are more actions. And let's say you use the action.proxy
then you can define at a lot more granular level what should happen with path. So in below example, we are forwarding to the coffee
service but the request path is being re-written to filtercoffee
proxy:
upstream: coffee
rewritePath: /filtercoffee
You can also use redirect, return in action's pass directive, but you must use one of the four listed here
Upvotes: 2