Kubernetes Ingress Controller redirects to basic login path, does not hold the ingress port or the service path for the specified service

12/24/2019

I am attempting to use an ingress controller within k8s to access my web servers running within the cluster. I am testing using path based routing ingress resources, and testing by accessing a worker IP address (as the ingress is using a node port service accessible through any of the worker nodes).

When I access other test web applications (without a login page), I am able to access my service as the following: http://{worker-ip}:{ingress-node-port}/{svc-name}

When I am trying to access an application that has a login page, I am redirected to the following after entering the above: http://{worker-ip}/vui/login

This obviously does not redirect me to the correct login page, and I am shown an error on the screen. Is there any way to hold the path and port name throughout this process so that the /vui/login path is sent with the correct service name and port number? If I input the entire path directly, I am still not able to access the service. I am thinking that since the path is changed to the correct login page, but cannot actually access the service, the redirection is working up to a certain point, and then failing out once the URL is changed to not use the path and service name.

Any advice on ingress, path based routing, and using them both with a login page redirection would be much appreciated.

Below is the ingress definition that I am using in my testing:

apiVersion: extensions/v1beta1
kind: Ingress 
metadata: 
  name: test-ingress 
  annotations: ingress.kubernetes.io/rewrite-target: / 
spec: 
  rules: 
  - http: 
      paths: 
      - path: /test1 
      backend: 
        serviceName: test1-service 
        servicePort: 5678 
      - path: /test2 
      backend: 
        serviceName: test2-service 
        servicePort: 5678 
      - path: /test3 
      backend: 
        serviceName: test3-service 
        servicePort: 8080
-- mm_wvu18
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

12/31/2019

You can use the next URL parameter for your case. For example, you are entering

https://example.com/test3

This redirects you to the login page if I've understood your problem correctly. The URL then becomes the login page URL -

https://example.com/vui/login

In this case, the URL that it originally came from isn't preserved.

So, I think you can use the next parameter in your URL and redirect the route to that URL once the user is authenticated. The URL will be -

https://example.com/vui/login?next=/test3/

Then you can deploy your k8s Ingress resource with the query-routing annotation -

ingress.kubernetes.io/query-routing: default/query-routing

and add a ConfigMap from where the URL params will be exerted -

kind:ConfigMap
apiVersion: v1
metadata:
  name: query-routing
data:
  mapping: |-
   [{
    "field": "login",
    "value": "1",
    "path": "/test3",
    "service": "test3-service ",
    "port": "8080"
   }]
-- Shahed Mehbub
Source: StackOverflow