This might look like a duplicate but it isn't as the solution in the linked thread doesn't work for me.
I have Ingress configured to dispatch requests to different pods based on the path
Desired behavior:
public_ip/app1 -> pod1_ip:container1_port/
public_ip/app2 -> pod2_ip:container2_port/
public_ip/app3 -> pod3_ip:container3_port/
Actual behavior:
public_ip/app1 -> pod1_ip:container1_port/app1
public_ip/app2 -> pod2_ip:container2_port/app2
public_ip/app3 -> pod3_ip:container3_port/app3
So we get 404's on app1, app2, app3
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: some_name
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
acme.cert-manager.io/http01-edit-in-place: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
ingressClassName: "nginx"
tls:
- hosts:
- some.host
secretName: tls-cafe-ingress
rules:
- host: some.host
http:
paths:
- path: /app1(/|$)(.*)
backend:
serviceName: app1
servicePort: 1234
- path: /app2(/|$)(.*)
backend:
serviceName: app2
servicePort: 2345
- path: /app3(/|$)(.*)
backend:
serviceName: app3
servicePort: 3456
The problem is that Ingress igores the path specifications once there are regular expressions in it. This can be seen by checking the logs of Ingress:
k logs -n nginx-ingress ingress-pod-name
Here we can see hat nginx has requests to /appX in the log and tries to serve them form the local html folder, in other words, the path defined in the yaml are ignored.
If regexes are removed from the path it works but then the path is sent downstream to the target pod which breaks the application