To define the API routes that your Spring Cloud Gateway will expose to consumers, you must create a SpringCloudGatewayRouteConfig resource.

Resource specification

The definition for SpringCloudGatewayRouteConfig specifies:


apiVersion: "tanzu.vmware.com/v1"
kind: SpringCloudGatewayRouteConfig
metadata:
  name:            # (Required) Name given to this route configuration
spec:
  basicAuth:
    secret:        # The secret name containing basic auth credentials.
  openapi:
    generation:
      enabled:           # Mark routes to be included in the OpenApi generation. (true)
    components:
      schemas:           # Reusable schema objects.
      requestBodies:     # Reusable request body objects.
    ref:                 # A reference to the openapi used for this route config, for informative purposes
  routes:                # Array of API routes.
    - description:       # (Optional) A description, will be applied to methods in the generated OpenAPI documentation.
      filters:           # See Available Filters.
      metadata:          # (Optional) Additional configuration, see Route Metadata Configuration.
      model:
        requestBody      # Reusable requestBodyObject objects.
        responses        # Reusable responsesObject objects.
      order:             # Route processing order, follows the same rules as Spring Cloud Gateway OSS
      openapi:
        generation:
          enabled:       # (Optional) Override 'SpringCloudGatewayRouteConfig.spec.openapi.generation.enabled' for a specific route. It indicates if the route should be included in the OpenApi generation.
      predicates:        # See Available Predicates.
      ssoEnabled:        # Activate SSO validation. See the SSO guide.
      tags:              # Classification tags, will be applied to methods in the generated OpenAPI documentation
      title:             # (Optional) A title, will be applied to methods in the generated OpenAPI documentation.
      tokenRelay:        # Pass the currently authenticated user's identity token to the upstream service.
      uri:               # (Optional) Full uri, will override `service.name` and `service.uri`.
  service:               # Configures the Kubernetes Service to route traffic matching the routes specified in `spec.routes` to.
    filters:             # (Optional) Filters to be prepended to all routes. See Available Filters.
    name:                # Name of a service to route to. Takes lower precedence than `uri`. Either `name` or `uri` are required unless all routes define their own uri.
    namespace:           # (Optional) If not set will use the RouteConfig's namespace.
    port:                # (Optional) If not set will use one of the available service ports.
    predicates:          # (Optional) Predicates to be prepended to all routes. See Available Predicates.
    ssoEnabled:          # (Optional) Define Single Sign-On validation for all routes. See the SSO guide.
    tokenRelay:          # (Optional) Pass the currently authenticated user's identity token to the upstream service for all routes.
    uri:                 # A URI to apply to all routes. Takes precedence over `name`. Either `name` or `uri` are required unless all routes define their own `uri`. Routes can override this value.

See the Getting Started guide for examples of how to populate these fields.

Note service.name is the recommended method to route traffic to services running on the Kubernetes cluster. Use routes.uri only when routing to external resources.

Example

The following is an example SpringCloudGatewayRouteConfig resource file:

apiVersion: "tanzu.vmware.com/v1"
kind: SpringCloudGatewayRouteConfig
metadata:
  name: myapp-route-config
spec:
  service:
    name: myapp
  routes:
  - predicates:
      - Path=/api/public/**
    filters:
      - StripPrefix=2

Default configuration

To simplify configuration, StripPrefix=1 is applied by default to all routes when no value for StripPrefix is set. This strips the first segment from the path of incoming requests. For example requests reaching the gateway with path /api/example will be forwarded to the target of matching routes with a path of /example.

Special considerations

Application services that are the target of Spring Cloud Gateway routes must respect the X-Forwarded-* HTTP headers, since the gateway is acting as a reverse proxy on behalf of the client.

For Spring Boot applications, this can be configured by setting server.forward-headers-strategy=NATIVE. Please utilize the appropriate approach for your application's programming language and framework.

Errors on route configurations

If the Spring Cloud Gateway Operator encounters an issue while applying a specific SpringCloudGatewayRouteConfig, none of the routes within that configuration will be applied.

In case where multiple SpringCloudGatewayRouteConfig configurations are applied, and only one has errors, the remaining valid configurations will still be applied.

check-circle-line exclamation-circle-line close-line
Scroll to top icon