You can define the following properties at the service level and they will be shared across all routes unless overridden. This allows you to avoid repetition across all or most API routes in their route configuration.
The preferred and simplest way to specific an upstream endpoint is pointing routes to a Kubernetes service. The following example will configure the service provided it's located in the Gateway namespace. The port to connect will be the one set in the actual service.
spec:
service:
name: myapp
Optionally, you can add namespace
and port
if the service is not located in the same namespace or you want to enforce a specific port.
spec:
service:
namespace: myapp-namespace
name: myapp
port: 8080
If your service cannot be accessed with a Kubernetes service you can also set a normal URI.
spec:
service:
namespace: myapp-namespace
name: myapp
port: 8080
To have certain filters prepended to all routes, you can use the service.filters
property. For example, that's how you can add rate limiting to all routes:
spec:
service:
name: myapp
filters:
- RateLimit=2,10s
In case a filter is also defined in a specific route, only the later will be applied in the order specified at the service level.
To have certain predicates prepended to all routes, you can use the service.predicates
property. Example of all routes configured with a mandatory header:
spec:
service:
name: myapp
predicates:
- Header=X-Request-Id
In case a predicate is also defined in a specific route, only the later will be applied in the order specified at the service level.
To define SSO validation for all routes, you can use the service.ssoEnabled
property.
spec:
service:
name: myapp
ssoEnabled: true
If necessary you can override it some routes. In this example, we deactivate it for the /users/**
route.
spec:
service:
name: myapp
ssoEnabled: true
routes:
- predicates:
- Path=/api/**
- predicates:
- Path=/users/**
ssoEnabled: false