0

I have different applications running in Kubernetes and I wrote an ingress file to access them using the path.

I have tried removing the annotation nginx.ingress.kubernetes.io/rewrite-target but then I cannot find the applications anymore

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: farmconnect-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/app-root: /location1/myapp
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "route"
    nginx.ingress.kubernetes.io/session-cookie-expires: "86400"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "86400"
spec:
  rules:
  - http:
      paths:
      - path: /?(.*)
        backend:
          serviceName: location1-service
          servicePort: 80
      - path: /location1/?(.*)
        backend:
          serviceName: location1-service
          servicePort: 80
      - path: /location2/?(.*)
        backend:
          serviceName: location2-service
          servicePort: 80

What I want is to keep my location in the URL like this:

www.mysite.com/location1/myapp
www.mysite.com/location2/myapp
.
.

At the moment it goes like this:

www.mysite.com/myapp

How can I keep the path in my URL?

Thanks

Rico
  • 58,485
  • 12
  • 111
  • 141
Linkavich14
  • 243
  • 1
  • 5
  • 15
  • Trey addding annotation with the value of `/` > nginx.ingress.kubernetes.io/rewrite-target : `/` – Harsh Manvar Jul 12 '19 at 03:42
  • 1
    @HarshManvar Thank your for your response but if I just use `/` in the annotation `nginx.ingress.kubernetes.io/rewrite-target` it won't show the application – Linkavich14 Jul 12 '19 at 04:11
  • `nginx.ingress.kubernetes.io/rewrite-target : /location/$2` – Harsh Manvar Jul 12 '19 at 04:27
  • https://stackoverflow.com/questions/47837087/nginx-ingress-rewrite-target – Harsh Manvar Jul 12 '19 at 04:28
  • 1
    @HarshManvar I cannot do it like that either if I change it like that I get the 404 error – Linkavich14 Jul 12 '19 at 04:52
  • `AppRoot` will make all incoming requests to be redirected to that particular path, once they reach the application's pod. Is your application listening on '*/location1/*' in both services? Are incoming requests looking specifically for these paths or you want to rewrite the path once the request has hit the application? If that's the case, it might be best to use [RegEx for location modification](https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/#warning) – yyyyahir Jul 17 '19 at 13:18
  • @YahirHernández Thank you for your response, what I wanted was to keep the URL with the location like this www.mysite.com/location1/myapp, but the application itself in the container is like this www.mysite.com/myapp. We have it working in IIS with the location1 before the app name, that is why I was wondering how to have it working in kubernetes – Linkavich14 Jul 18 '19 at 01:45
  • Well, you can [rewrite the URL](https://stackoverflow.com/a/57093874/10892354). Since the incoming request contains the location URI, you can rewrite it to `/myapp` so that your backend can understand where the request is going. – yyyyahir Jul 22 '19 at 07:38

0 Answers0