Ingress sends traffic to the domain root

9/8/2019

I have a workload which is exposed through NodePort service with the name online-forms-lib-service. This workload has the /version route.

Also I have the following ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: online-forms-lib-service
          servicePort: 80
        path: /formslib/

The problem is, the /version route is not available at:

example.com/formslib/version

How to solve this?

Update

It goes to the application root when I call:

example.com/formslib/

Adding any path from there directs me to the default backend

Update Added the annotation:

  annotations:
    ingress.kubernetes.io/rewrite-target: /

Still the same behaviour.

-- Charlie
kubernetes
kubernetes-ingress

2 Answers

9/11/2019

This behaviour is controlled by the rewrite annotations.

  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /

As of September, 2019, the GKE ingress doesn't support the rewrite rules.

https://github.com/kubernetes/ingress-gce/issues/109

And no published plans for implementing it either.

The only solution is nginx or other 3rd party ingress controller which supports rewrite annotations.

-- Charlie
Source: StackOverflow

9/10/2019

Actually, Ingress resource mostly relies on the Ingress controller implemented in K8s cluster with the aim to propagate Ingress rules and supplying load-balancing and traffic routing features.

As @ Utku Ă–zdemir mentioned in the comment, most of the cloud providers on the market propose native Ingress controllers support, i.e. Ingress-gce in Google Cloud, making possible to create External HTTP(S) load balancer via particular Ingress resource.

In addition, you might find a lot of third party Ingress controllers solutions, that can potentially expand L7 network traffic functionality depending on the client needs.

I've checked your current Ingress configuration in a similar scenario, and I've managed a proper sub-path routing adopting wildcard * matching rule, preceding the root application path for the particular backend service:

- backend:
    serviceName: online-forms-lib-service
    servicePort: 80
    path: /formslib/*
-- mk_sta
Source: StackOverflow