- is it possible to implement this routing out of the box or will I have to write a plugin to achieve this?
Short answer: Not possible out of the box, I’m afraid you will need a custom plugin which resets the value of
upstream_url depending on the consumer id.
Slightly longer answer: Kong’s load balancer can redirect to different targets depending on the consumer hash, but it’s not possible to specify which consumers are redirected to which targets, so the only option is a custom plutin. Your plugin will have to manually se
ngx.ctx.balancer_address.host (if you use a load balancer) depending on the consumer_id. If you decide to store the different destinations in the database, make sure to memoize the results, so that you don’t hit the database on each request!
- How do I go about the adding and configuring an API for this use case?
First you must register at least one API in your kong instance. You can do so with the admin api interface for adding new APIs. If the routing rules of all your domains/functions/operations are the same, you just need one api. If they differ, you will need one for each group. For example, if all requests to
/users/registration/new are routed to one server, but
/companies/report/sales goes to a different endpoint for each group of users, then you need to register two APIs.\
Next is registering your users. In kong, they are called consumers. The tutorial about consumers explains how you can set them up basically. See also the key-auth plugin docs for more details.
Finally you will need to configure your custom plugin (unless you have hardcoded the values). This depends on how you write it, but you will probably have to associate some consumer_id with some property (either the server uri/name or some sort of “user group”, to which you will assign the server later). The recommended way for doing this is that your plugin should include an admin API interface so you can do this with curl. Alternatively you can always write the data on the database.