I'm trying to achieve this simple configuration on a kubernetes nginx ingress controler:
location /path1/ {
proxy_pass http://server-1:8000/;
proxy_redirect http://server-1:8000/ /path1/;
}
location /path2/ {
proxy_pass http://server-2:8000/;
proxy_redirect http://server-2:8000/ /path2/;
}
location / {
proxy_pass http://server-auth:8000;
}
The idea is to redirect /pathX/
to the /
of different servers (server-X
) and the root path to server-auth
To do this, I ended up with two ingresses for the same host name (www.mysite.com):
- One for the server-x redirections with the rewrite-target annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
(...)
- host: "www.mysite.com"
http:
- path: /path1(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: server-1
port:
number: 8000
- path: /path2(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: server-2
port:
number: 8000
- And another one just for the authenticator without the rewrite-target annotations:
- host: "www.mysite.com"
http:
- path: /
pathType: Prefix
backend:
service:
name: server-auth
port:
number: 8000
This is because the annotations can't be dedicated to one path (or I don't know how to proceed)
I feel like that's a lot of code for such a small configuration, so I'd like to know if there's a simpler or more elegant way to do it ?
Thank you Julien