feat: support for path based routing to other services #362
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for path based routing. This can be used to allow a path on an existing route to be directed to a different service within the environment.
For example you have an application that serves a static or other site on
www.example.com
via nginx, but you need to passwww.example.com/api/v1
to a node application running in the environment. Currently the only way to do that would be via nginx configuration.This feature allows you to define paths on a route to a different backend.
Usage
Here is an example
.lagoon.yml
file that shows how path based routes can be defined. There is support for global autogenerated routes, per environment autogenerated routes, and custom routes.Autogenerated Routes
Firstly, there are global autogenerated route configurations, these would apply to ALL environments that this
.lagoon.yml
file would cover. Second is per environment autogenerated route configurations, the fields are the same, just where they are defined is different.The 3 fields are
fromService
- the autogenerated route for the service you want to add the path based route totoService
- the backend service you want to route topath
- the path to send to thetoService
Custom Routes
It is possible to turn on path based routes for a specific route too, the following
.lagoon.yml
example shows how.The fields are the same, except that
fromService
is omit because of the way that custom routes are defined to already be associated to afromService
in their normal configuration.Conditions
Autogenerated Route configurations
If the global path routes for autogenerated routes are defined, but an environment has overrides, the global defined path routes are ignored by that environment.
Additional Ports/Docker Compose Ports reference
If the docker compose label
lagoon.service.usecomposeports=true
has been defined on a service, then the service name with the port number as a suffix to any ports beyond the default (first defined port) must be used as thetoService
.The following
docker-compose.yml
has an example of this label and the ports. This would create the default service port namednode
referencing port 1234, but also another servicenode-4321
. If you need to create a path based route to port 4321, you would need to define thetoService
asnode-4321
.URLs
The
path
defined in thepathRoute
will be passed to whichevertoService
is defined in all URL queries. This means if you're using thepath
defined as/api/v1
for example, then you may need to cater for this in your backend depending on how your backend is built.Path Types
Currently only
Prefix
is supported (see Ingress path types). If there is a need, thepathRoutes
could be extended to include atype
that acceptsPrefix
orExact
, with the default beingPrefix
if not provided.Example repo
An example repo was created to show how this could be used, it will be completely unmaintained, do not build off this example.
Closing Issues
closes uselagoon/lagoon#3642