4

I have a container running on url like http://localhost:8000/ps/app/ui/?pid=201. The container is deployed on kubernetes and exposed to a service as "ps-app-ui:8000" I want to create an ingress which can be accessible from outside. Ingress template is like:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ps-ingress
spec:
  rules:
  - http:
      paths:
      - path: /myapp/
        backend:
          serviceName: ps-app-ui
          servicePort: 8000

The problem is its not working with this ingress. I also tried adding "ingress.kubernetes.io/rewrite-target: /" but had no success. Can anyone help me to get my application accessible via "http://INGRESS-IP/myapp/ps/app/ui/?pid=201"

Will be really grateful.

Shahzeb Khan
  • 41
  • 1
  • 3

3 Answers3

1

Ingress version 0.22.0 or higher has changed the way how rewrite-target works. You'll need to regex-match the path and add it to the rewrite-target.

nginx.ingress.kubernetes.io/rewrite-target: /$2
...
...
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something(/|$)(.*)

Refer to changelog here. How to article here

Vasudev
  • 803
  • 1
  • 7
  • 16
0

I'm thinking

- path: /myapp/

matches your app at http://myapp/myapp/

So if I have a definition:

  - host: app.example.com
    http:
      paths:
      - path: /myapp

This would be http://app.example.com/myapp

Dylan
  • 868
  • 12
  • 21
0

if you want to use http://myapp/ps/app/ui/?pid=201 you need to:

  • make sure that your operating system translates myapp to a IP address where your ingress controller is listening
  • add the host myapp to the ingress
  • you can leave the path empty (assuming that your application is handling the complete /ps/app/ui/?pid=201 path)

This results in

rules:
  - host: myapp
    http:
      paths:
      - backend:
          serviceName: ps-app-ui
          servicePort: 8000

This ingress will forward all traffic to the host myapp to your service

slintes
  • 740
  • 5
  • 9
  • What i exactly want is to get my application working on http:///myapp/ps/app/ui/?pid=201. Application iteself is served on path /ps/app/ui/?pid=201 But problem is using ingress add this myapp path to applications path and make things ambigious . The path / (empty) works fine but adding any string make it stop working – Shahzeb Khan Jul 22 '17 at 00:40
  • ok, I see you edited your question... in that case: try without host, but set `/myapp` (without trailing slash) as path. And your application needs to listen on the `/myapp` part too, because as far as I know the that part won't be removed from the request! – slintes Jul 23 '17 at 08:09
  • I just found out that you can influence that behaviour of keeping the path, by adding some metadata to the ingress: ```apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: ingress.kubernetes.io/rewrite-target: /``` see https://github.com/kubernetes/ingress/tree/master/examples/rewrite/nginx – slintes Jul 23 '17 at 08:18