Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 347
znat Avatar asked Oct 01 '18 00:10

znat


People also ask

How would you describe ingress?

Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource. An Ingress may be configured to give Services externally-reachable URLs, load balance traffic, terminate SSL / TLS, and offer name-based virtual hosting.

What is pathType in ingress?

A new pathType field that can specify how Ingress paths should be matched. A new IngressClass resource that can specify how Ingresses should be implemented by controllers. Support for wildcards in hostnames.

What is service ingress?

Unlike NodePort or LoadBalancer, Ingress is not actually a type of service. Instead, it is an entry point that sits in front of multiple services in the cluster. It can be defined as a collection of routing rules that govern how external users access services running inside a Kubernetes cluster.

What is rewrite target in ingress?

In this ingress definition, any characters captured by (. *) will be assigned to the placeholder $2 , which is then used as a parameter in the rewrite-target annotation. For example, the ingress definition above will result in the following rewrites: rewrite.bar.com/something rewrites to rewrite.bar.com/


1 Answers

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

like image 180
Sage Avatar answered Nov 15 '22 19:11

Sage