write ingress rule for application running with context-root

2.4k Views Asked by At

I have a web app and its corresponding backend service deployed in k8s. They are exposed as follows through services:

  1. Web App -> http://1.2.3.4:8080/webapp/login
  2. Backend -> http://5.6.7.8:8081/backend-service/login

I have configured ingress resource for these service but it turns out NGINX ingress controller is skipping the context root part while rewriting the url which is making my service unavailable when I am deploying it through ingress. Below is my ingress resource:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  namespace: default
  name: gateway-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/use-regex: true
spec:
  rules:
    - http:
        paths:
          - path: /webapp/*
            backend:
              serviceName: webapp-service
              servicePort: 8080
          - path: /backend-service/*
            backend:
              serviceName: backend-service
              servicePort: 8081


**Output of : kubectl describe ingress gateway-ingress**

Name:             gateway-ingress
Namespace:        default
Address:          test.elb.us-east-2.amazonaws.com
Default backend:  default-http-backend:80 (<none>)
Rules:
  Host  Path  Backends
  ----  ----  --------
  *     
        /webapp/*                 webapp-service:8080 (1.2.3.4:8080)
        /backend-service/*        backend-service:8081 (5.6.7.8:8081)

So when I am accessing my application using http://test.elb.us-east-2.amazonaws.com/webapp/login I am getting 404 not found. How can i configure ingress resource correctly?

1

There are 1 best solutions below

0
On BEST ANSWER

Application context removal is caused by the rewrite-target annotation. Just remove it if it's not needed.