I have a Kubernetes cluster with two applications which provide web-frontends, and I would like to make both of them accesible through an NGINX ingress controller. This is the relevant part of my ingress.yaml:
tls:
- hosts:
- myapp.com
secretName: my-certificate
rules:
- host: myapp.com
http:
paths:
- backend:
serviceName: myapp2-service
servicePort: 12345
path: /myapp2/(.*)
- backend:
serviceName: myapp1-service
servicePort: 80
path: /(.*)
With this setup, I can reach the frontend of myapp1 through the URL myapp.com. When I change it to
paths:
- backend:
serviceName: myapp2-service
servicePort: 12345
path: /(.*)
- backend:
serviceName: myapp1-service
servicePort: 80
path: /(.*)
I can reach the frontend of myapp2 through the URL myapp.com.
What I want to achieve is that I can reach the frontend of myapp1 through myapp.com and the frontend myapp.com/myapp2. Is that possible? And if so where is my mistake? As I've said, the frontend of myapp2 is basically accesible, just not through a sub-URL.
Your path is configured to /myapp2/(.*)
so myapp.com/myapp2
does not match that.
Right now myapp.com/myapp2
goes to myapp1-service
looking for /myapp2
content.
You can configure /
at the end to be optional. But it will affect other path strings that match myapp2
.
tls:
- hosts:
- myapp.com
secretName: my-certificate
rules:
- host: myapp.com
http:
paths:
- backend:
serviceName: myapp2-service
servicePort: 12345
path: /myapp2(/|$)(.*)
- backend:
serviceName: myapp1-service
servicePort: 80
path: /(.*)
It is also possible to rewrite myapp.com/myapp2
to myapp.com/myapp2/
but it is little bit more complicated on free version of nginx ingress.
Hope it helps.