1
votes

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
1
please share the ingress xml filedassum
The first and second services are accessible through the ingress, but they are different apps and do not have a login page (they are example echo web servers that display a test message). The third redirects to a login page and loses the URL that is initially entered.maxman722
Please edit your question and insert your yaml definition there, not in the comment, so it can be formatted properly. Press Ctrl + K after selecting the text that needs to be formatted.mario
I have added the ingress definition to the question. Like I mentioned, I have the ingress working with a few test services, but the one that requires a redirect to a login page is giving me issues. Thanks @mariomaxman722

1 Answers

1
votes

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"
   }]