I'm using Kubernetes with Nginx ingress controller and I have two services (srv1 and srv2) on my namespace which I want to access them like this:
https://xyz.example.com/srv1/ => (point to the root of srv1)
https://xyz.example.com/srv2/ => (point to the root of srv2)
for example, if someone hit the below URL :
https://xyz.example.com/srv1/page1.aspx
then, they will hit the page1.aspx which is in the root of my application in srv1
it works just fine with the below ingress file:
Problem:
I have a second page which is page2.aspx and I placed it next to page1.aspx, so both of them are in root, now if I click on a button on the page1 which has a server-side code to redirect us to the page2.aspx, then I expected to get us into the below URL:
https://xyz.example.com/srv1/page2.aspx
but instead, it will redirect me to the below path:
https://xyz.example.com/page2.aspx
Just for clarification, I put an HTML link in the page1 which point to page2, it works just fine because it works in the client-side instead of the server-side.
so far I used the below 3 languages for the server-side redirection and all of them have the same behaviour:
C# & .net core (versions 2.1 , 2.2 , 3.0 and 3.1)
Python (version 3.7)
Ruby (version 2.7.1)
so I think the problem is from Kubernetes, anyone has any idea?
here are my ingress YAML:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ds1-ingress
namespace: ds1
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
tls:
- hosts:
- xyz.example.com
secretName: tls-secret
rules:
- host: xyz.example.com
http:
paths:
- backend:
serviceName: srv1
servicePort: 80
path: /srv1/(.*)
- backend:
serviceName: srv2
servicePort: 80
path: /srv2/*
https://github.com/POC-Vault/Routing
https://hub.docker.com/repository/docker/farzadjalali/k8s-routing
How to pull the docker image:
docker push farzadjalali/k8s-routing:latest