In addition to Lentil1016 answer, here is the example of the same rewrite solution for nginx-ingress-controller.
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/ssl-redirect: 'false'
nginx.ingress.kubernetes.io/force-ssl-redirect: 'false'
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: myapp
namespace: namespaceA
spec:
rules:
- host: mydomain.io
http:
paths:
- backend:
serviceName: myapp
servicePort: 80
path: /namespaceA(/|$)(.*)
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: myapp
namespace: namespaceB
spec:
rules:
- host: mydomain.io
http:
paths:
- backend:
serviceName: myapp
servicePort: 80
path: /namespaceB(/|$)(.*)
For example, the ingress definition above will result in the following rewrites:
For destination service myapp in the namespace namespaceA:
mydomain.io/namespaceA rewrites to mydomain.io/
mydomain.io/namespaceA/ rewrites to mydomain.io/
mydomain.io/namespaceA/ready/ rewrites to mydomain.io/ready/
For destination service myapp in the namespace namespaceB:
mydomain.io/namespaceB rewrites to mydomain.io/
mydomain.io/namespaceB/ rewrites to mydomain.io/
mydomain.io/namespaceB/ready/ rewrites to mydomain.io/ready/
Note: You may need to use nginx-config ConfigMap to completely switch off ssl-redirect for nginx-ingress-controller.
Note: There are two kinds of nginx-ingress-controllers, kubernetes and nginxinc. ConfigMap options and annotations could be different for each of them.
kind: ConfigMap
apiVersion: v1
metadata:
name: nginx-config
namespace: nginx-ingress # <--- or ingress-nginx, depends on your installation
data:
redirect-to-https: "false"
ssl-redirect: "false"