I've google a lot about this and I couldn't find nothing useful to solve my issue.
I need to serve two different type of services with the same hostname, differentiating them by the URI:
Frontend: https://app.example.com/
APIs: https://app.example.com/api/
I have two different Kubernetes services running: a frontend (a SPA with Angular) and a backend (a collection of REST APIs).
Those two services are exposed on different internal context paths, like this:
Frontent: http://frontend:80/static/index.html
Backend http://backend:8080/services/
The flow I need is the following:
https://app.example.com/index.html -> http://frontend:80/static/index.html
https://app.example.com/api/login -> http://backend:8080/services/login
Using the rewrite-target annotation is not enough, because it's applied to all the backend services defined in the paths. Basically, I would need a specific rewrite-path for each path listed under the same host. I need the Nginx Ingress to allow me to differentiate the rewrite-path for each service.
To give a better idea using pseudo-code, this is what I would like to achieve.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: app-ingress
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: app.example.org
http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: 8080
serviceContext: /static/ <-- Desideratum
- path: /api/
backend:
serviceName: backend
servicePort: 8080
serviceContext: /services/ <-- Desideratum
tls:
- hosts:
- app.example.org
secretName: my_secret
I'm using Kubernetes version 1.10.5 on Azure.
Thanks a lot!
Closing. You can achieve this creating two different ingresses for the same host, having different paths and applying the required rewrite-target
Omg, I didn't figure it out!
Worked, thanks :)
Hi @iakko and @aledbf can you please share an example of these two different ingresses for the same host? I think that I need something like that for my company's project.
Thanks in advance
@iakko @alanbover I would also love an example for this.
Most helpful comment
@iakko @alanbover I would also love an example for this.