Mesh HTTP Route (beta)

    The policy allows altering and redirecting HTTP requests depending on where the request coming from and where it’s going to.

    MeshHTTPRoute does not route cross-zone traffic yet!

    If you don’t understand this table you should read .

    Unlike others outbound policies MeshHTTPRoute doesn’t contain default directly in the to array. The default section is nested inside rules, so the policy structure looks like this:

    • path - (optional) - HTTP path to match the request on
      • type - one of Exact, Prefix, RegularExpression
      • value - actual value that’s going to be matched depending on the type
    • method - (optional) - HTTP2 method, available values are CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, TRACE
    • queryParams - (optional) - list of HTTP URL query parameters. Multiple matches are ANDed together such that all listed matches must succeed
      • type - one of Exact or RegularExpression
      • name - name of the query parameter
      • value - actual value that’s going to be matched depending on the type
    • filters - (optional) - a list of modifications applied to the matched request
      • type - available values are RequestHeaderModifier, ResponseHeaderModifier, RequestRedirect, URLRewrite.
      • requestHeaderModifier - , must be set if the type is RequestHeaderModifier.
      • responseHeaderModifier - HeaderModifier, must be set if the type is ResponseHeaderModifier.
      • requestRedirect - must be set if the type is RequestRedirect
        • scheme - one of http or http2
        • hostname - is the fully qualified domain name of a network host. This matches the RFC 1123 definition of a hostname with 1 notable exception that numeric IP addresses are not allowed.
        • port - is the port to be used in the value of the Location header in the response. When empty, port (if specified) of the request is used.
        • statusCode - is the HTTP status code to be used in response. Available values are 301, 302, 303, 307, 308.
      • urlRewrite - must be set if the type is URLRewrite
        • hostname - (optional) - is the fully qualified domain name of a network host. This matches the RFC 1123 definition of a hostname with 1 notable exception that numeric IP addresses are not allowed.
        • path - (optional)
          • type - one of ReplaceFullPath, ReplacePrefixMatch
          • - must be set if the type is ReplaceFullPath
          • replacePrefixMatch - must be set if the type is ReplacePrefixMatch
    • backendRefs - (optional) - list of destination for request to be redirected to
      • kind - one of MeshService, MeshServiceSubset
      • name - service name
      • tags - service tags, must be specified if the kind is MeshServiceSubset
      • weight - when a request matches the route, the choice of an upstream cluster is determined by its weight. Total weight is a sum of all weights in backendRefs list.
    • set - (optional) - list of headers to set. Overrides value if the header exists.
      • name - header’s name
      • value - header’s value
    • add - (optional) - list of headers to add. Appends value if the header exists.
      • name - header’s name
      • value - header’s value
    • remove - (optional) - list of headers’ names to remove

    Here is an example of a MeshHTTPRoute that splits the traffic from frontend_kuma-demo_svc_8080 to backend_kuma-demo_svc_3001 between versions, but only on endpoints starting with /api. All other endpoints will go to version: 1.0.

    1. apiVersion: kuma.io/v1alpha1
    2. kind: MeshHTTPRoute
    3. metadata:
    4. name: http-route-1
    5. namespace: kuma-system
    6. labels:
    7. kuma.io/mesh: default
    8. spec:
    9. targetRef:
    10. kind: MeshService
    11. name: frontend_kuma-demo_svc_8080
    12. to:
    13. - targetRef:
    14. kind: MeshService
    15. name: backend_kuma-demo_svc_3001
    16. rules:
    17. - matches:
    18. - path:
    19. type: Prefix
    20. value: /api
    21. default:
    22. backendRefs:
    23. - kind: MeshServiceSubset
    24. name: backend_kuma-demo_svc_3001
    25. tags:
    26. version: "1.0"
    27. weight: 90
    28. - kind: MeshServiceSubset
    29. name: backend_kuma-demo_svc_3001
    30. tags:
    31. version: "2.0"
    32. weight: 10

    We will apply the configuration with kubectl apply -f [..].

    We will apply the configuration with kumactl apply -f [..] or via the .

    We can use MeshHTTPRoute to modify outgoing requests, by setting new path or changing request and response headers.

    1. apiVersion: kuma.io/v1alpha1
    2. kind: MeshHTTPRoute
    3. metadata:
    4. name: http-route-1
    5. namespace: kuma-system
    6. labels:
    7. kuma.io/mesh: default
    8. spec:
    9. targetRef:
    10. name: frontend_kuma-demo_svc_8080
    11. to:
    12. - targetRef:
    13. kind: MeshService
    14. name: backend_kuma-demo_svc_3001
    15. rules:
    16. - matches:
    17. - path:
    18. type: Exact
    19. value: /
    20. default:
    21. filters:
    22. - type: RequestHeaderModifier
    23. requestHeaderModifier:
    24. set:
    25. - name: x-custom-header
    26. value: xyz

    We will apply the configuration with kubectl apply -f [..].

    We will apply the configuration with kumactl apply -f [..] or via the .

    When several MeshHTTPRoute policies target the same data plane proxy they’re merged. Similar to the new policies the merging order is determined by . The difference is in spec.to[].rules. Kuma treats rules as a key-value map where matches is a key and default is a value. For example MeshHTTPRoute policies:

    1. # MeshHTTPRoute-1
    2. rules:
    3. - matches: # key-1
    4. - path:
    5. type: Exact
    6. name: /orders
    7. method: GET
    8. default: CONF_1 # value
    9. - matches: # key-2
    10. - path:
    11. type: Exact
    12. name: /payments
    13. method: POST
    14. default: CONF_2 # value
    15. ---
    16. # MeshHTTPRoute-2
    17. rules:
    18. - matches: # key-3
    19. - path:
    20. type: Exact
    21. name: /orders
    22. method: GET
    23. default: CONF_3 # value
    24. - matches: # key-4
    25. - path:
    26. type: Exact
    27. name: /payments
    28. default: CONF_4 # value

    merged in the following list of rules: