How to specify a prefix to a service exposed with an ingress

10/1/2018

I want exposing various services with a single ingress.

rules:
  - http:
      paths:
      # The path is the URL prefix for the service, e.g. /api/* or just /*
      # Note that the service will receive the entire URL with the prefix
      - path: /service1/*
        backend:
          serviceName: service1
          servicePort: 5000
      - path: /service2/*
        backend:
          serviceName: service2
          servicePort: 5000

The problem is the whole URL including the prefix is passed to the underlying services so all requests return 404 errors: service1 and api don't respond on /service1/some/path but directly on /some/path

How can I specify a prefix to the underlying services?

UPDATE

I tried using rewrite-target as follows. Requests are sent to the rasa-nlu service, but they all trigger 404 because rasa-nlu still gets the /nlu

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /nlu
        backend:
          serviceName: rasa-nlu
          servicePort: 5000
-- znat
google-kubernetes-engine
kubernetes

2 Answers

3/18/2019

This thread might be solved till now, but just for the sake of solution. below will solve the issue, the default path will be /nlu when it is added to the re-write annotation. It is from the nginx re-write rule which gets applies to the definition of location directive.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /nlu
spec:
  rules:
  - http:
      paths:
      - path: /nlu
        backend:
          serviceName: rasa-nlu
          servicePort: 5000
-- Abhi
Source: StackOverflow

10/1/2018

This might be what you are looking for;

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/rewrite-target: /
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: echoheaders
          servicePort: 80
        path: /something

Note the annotation to rewrite-target.

Found this here

-- Sage
Source: StackOverflow