简体   繁体   中英

How to map multiple services to a single ingress using AWS ALB as Ingress Controller?

I have a single ingress (example, www.a.com ). I have mapped the root to a service, like so:

- backend:
    serviceName: ui-svc
    servicePort: 80
  path: /

This routes to the correct service when go to www.a.com . I want to mount another service on /api, like so:

- backend:
    serviceName: api-svc
    servicePort: 80
  path: /api

The routing to www.a.com/api works fine, however any trailing endpoints get 404'd (etc www.a.com/api/swagger , even though this endpoint is mounted in the application itself (spring application)). Previously, using Traefik, I've used the rewriteTarget: / annotation to remedy this, however ALB does not support this. Is there a kubernetes native way that I can solve this problem?

I am using kubernetes 1.17 and EKS as my kubernetes platform.

You can use regular expressions to match the path

- backend:
    serviceName: api-svc
    servicePort: 80
  path: /api/.*

This can be enabled by setting this annotation in your ingress deployment:

nginx.ingress.kubernetes.io/use-regex: "true"

more info https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/

This has since been remedied by adding

server.servlet.context-path=/*relvantPathName*

As an environment variable to the containers. This is a spring specific thing, where it needs to rewrite the root in order to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM