Can kong call into my application for routing rules?

Hello All:

I’m a kubernetes and kong newbie. So, please bear with me.

I’m trying to build an API for my services where I need to be able to dynamically proxy an incoming request to a service based on some logic that’s maintained within my application.

e.g.,

  • my application has some routing logic (can be implemented either in nodejs or python) essentially a map of user -> service.
  • The routing logic (mapping) can be dynamic in nature… meaning new users and/or new services can be added at any time and this map can be changed to reflect that.

I’ve tried using the default ingress-nginx to write some rules, but, was not able to dynamically change them when new users are added.

Question:

  • can kong call into my application for the routing?
    (or)
  • is there a better / alternative way of achieving such routing?

Thanks in advance,
Ram C

Possibly, but there’s not really any standard way to do it–it will depend heavily on the specifics of your application and needs. Offhand, these are the options I can think of:

  • In the simplest case, you use paths that omit the dynamic component or match it using regexes. For example, if you have a path like /users/<USER_ID>/foo, you could use either /users or /users/\d+/foo to match it. The first is simpler, but doesn’t allow for as much complex logic, since you can’t use anything after the user ID as matching criteria. When using regexes, you can use more complex routing logic and expose captured path components to custom plugins.
  • Custom plugins (or serverless functions) can retrieve data from external sources (e.g. your application) and use them to modify the upstream path via manipulation of the upstream_uri variable during the access phase. This approach is fairly limited, however, as it doesn’t change the route or service Kong initially selected (and by extension, what other plugin configurations will run), only the actual paths used upstream. Manipulation of the upstream host may be possible, but I’m less sure, as it requires manipulating balancer data and that’s a bit more complex.
  • You can push route configuration to Kong if you provide the application (or some helper that scans its data) with admin API access. This is less likely to encounter unexpected behavior than manipulating routing state via plugin/serverless code, though will usually require additional code elsewhere (assuming your application doesn’t have any existing knowledge of the Kong admin API).

Do those approaches make sense at a high level and/or do you have questions on them?

@traines Thanks much for your response. Going over the various resources over the last couple of days, I think option 3 seems like a simpler way for us to go.