By default, Spring Cloud Gateway doesn't check if the upstream services are healthy, leaving some requests timeout or responding incorrectly. You can use active Health Checks to help unhealthy upstream services recover more smoothly in the event of a disruption.

By periodically checking a configurable health endpoint, the gateway knows when to short-circuit the request and return a 503 response code, instead of putting additional load on an already struggling API. To activate active Health Checks, set spec.healthCheck.enabled to true in your gateway definition:

apiVersion: "tanzu.vmware.com/v1"
kind: SpringCloudGateway
metadata:
  name: my-gateway
spec:
  healthCheck:
    enabled: true

By default, the upstream services will be checked periodically every 25s. The Health Check interval can be changed by specifying spec.healthCheck.interval field. The interval value is a text format for a duration, for example, 1h, 60m or 3600s.

Health Check endpoint configuration

The decide if a service is healthy, by default the gateway checks the endpoint /actuator/health periodically. Globally, the Health Check path /actuator/health can be overridden setting up the env variable spring.cloud.loadbalancer.health-check.path.default. At route level, Health Check can be deactivated or customized using the metadata section of the specific route.

  • spec.routes[*].metadata.healthCheck.enabled deactivates Health Check in a particular route specifying false as value.
  • spec.routes[*].metadata.healthCheck.path overrides the default health check endpoint /actuator/health.

This route configuration will deactivate health check for the first route, and change the endpoint for the second.

apiVersion: "tanzu.vmware.com/v1"
kind: SpringCloudGatewayRouteConfig
metadata:
  name: my-gateway-routes
spec:
  routes:
    - uri: https://httpbingo.org
      predicates:
        - Path=/get/**
      metadata:
        healthCheck:
          enabled: false
    - uri: https://httpbingo.org
      predicates:
        - Path=/get/**
      metadata:
        healthCheck:
          path: /custom-endpoint/health
check-circle-line exclamation-circle-line close-line
Scroll to top icon