HTTPRoute resource fields
The HTTPRoute resource sets traffic routing rules for Kubernetes services (Service resources) operating as backends or redirection rules. HTTPRoute receives incoming traffic from those Gateway resources whose requirements it meets.
HTTPRoute is designed for application developers. Cluster operators should use the Gateway resource.
HTTPRoute is a Kubernetes Gateway API
HTTPRoute
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: <string>
namespace: <string>
annotations:
gateway.alb.yc.io/rules.backends.http.useHTTP2: <bool>
gateway.alb.yc.io/rules.backends.balancing.mode: <string>
gateway.alb.yc.io/rules.backends.balancing.localityAwareRouting: <string>
gateway.alb.yc.io/rules.backends.balancing.strictLocality: <bool>
gateway.alb.yc.io/rules.backends.balancing.panicThreshold: <string>
gateway.alb.yc.io/rule.<rule_name>.backends.balancing.mode: <string>
gateway.alb.yc.io/rules.backends.hc.timeout: <string>
gateway.alb.yc.io/rules.backends.hc.interval: <string>
gateway.alb.yc.io/rules.backends.hc.healthyThreshold: <string>
gateway.alb.yc.io/rules.backends.hc.unhealthyThreshold: <string>
gateway.alb.yc.io/rules.backends.hc.port: <string>
gateway.alb.yc.io/rules.backends.hc.http.path: <string>
gateway.alb.yc.io/rules.backends.hc.http.useHTTP2: <bool>
gateway.alb.yc.io/rules.backends.hc.http.host: <string>
gateway.alb.yc.io/rules.backends.hc.grpc.serviceName: "Check"
gateway.alb.yc.io/rules.backends.hc.stream.send: <string>
gateway.alb.yc.io/rules.backends.hc.stream.receive: <string>
gateway.alb.yc.io/rules.sessionAffinity.header.name: <string>
gateway.alb.yc.io/rules.sessionAffinity.cookie.name: <string>
gateway.alb.yc.io/rules.sessionAffinity.cookie.ttl: <string>
gateway.alb.yc.io/rules.sessionAffinity.sourceIP: <bool>
gateway.alb.yc.io/rules.timeout: <string>
gateway.alb.yc.io/rules.idleTimeout: <string>
gateway.alb.yc.io/rule.<rule_name>.timeout: <string>
gateway.alb.yc.io/rule.<rule_name>.idleTimeout: <string>
gateway.alb.yc.io/rules.httpUpgradeTypes: <string>
gateway.alb.yc.io/rules.securityProfileId: <string>
gateway.alb.yc.io/rules.rbac.action: <string>
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.header.name: <string>
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.header.regex: <string>
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.header.exact: <string>
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.header.prefix: <string>
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.ip.remoteIp: <string>
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.any: <bool>
gateway.alb.yc.io/hosts.securityProfileId: <string>
gateway.alb.yc.io/hosts.rbac.action: <string>
spec: <HTTPRouteSpec>
Where:
-
apiVersion:gateway.networking.k8s.io/v1 -
kind:HTTPRoute -
metadata(ObjectMeta; this is a required field)Resource metadata.
-
name(string; this is a required field)Resource name. For more information about the format, see this Kubernetes guide
.Do not mistake this name for the Application Load Balancer route name.
-
namespace(string)Namespace the resource belongs to. The default value is
default. -
annotations(map[string]string)Resource annotations.
Note
You can define the RoutePolicy resource instead of annotations. The
RoutePolicyresource parameters andHTTPRouteannotations are equivalent.-
gateway.alb.yc.io/rules.timeout(string)Timeout for HTTP connection between the load balancer and backend. The connection is maintained until the specified time expires regardless of any outgoing data transfer. After the timeout expires, the resource returns the
UNAVAILABLEstatus. -
gateway.alb.yc.io/rules.idleTimeout(string)Inactive HTTP connection timeout during which no data is transferred. After the timeout expires, the resource returns the
504 Gateway Timeoutstatus. -
gateway.alb.yc.io/rules.securityProfileId(string)Smart Web Security security profile ID for the route.
-
gateway.alb.yc.io/hosts.securityProfileId(string)Security profile ID for the host.
-
gateway.alb.yc.io/rules.backends.http.useHTTP2Use HTTP/2 for connection between the load balancer and backend.
-
gateway.alb.yc.io/rules.sessionAffinity.header.nameHTTP header name for session affinity.
-
gateway.alb.yc.io/rules.sessionAffinity.cookie.nameCookie name for session affinity.
-
gateway.alb.yc.io/rules.sessionAffinity.cookie.ttlCookie lifetime for session affinity.
-
gateway.alb.yc.io/rules.sessionAffinity.sourceIPIndicator of using a client IP address for session affinity.
-
gateway.alb.yc.io/rules.backends.balancing.modeLoad balancing mode. The possible values are
RANDOM,ROUND_ROBIN, andLEAST_REQUEST. -
gateway.alb.yc.io/rules.backends.balancing.localityAwareRoutingPercentage of traffic that goes to the
HTTPRouteresource's availability zone withhealthybackends. The remaining traffic is distributed across other availability zones. The parameter is not applied ifstrictLocality=true(see below). -
gateway.alb.yc.io/rules.backends.balancing.strictLocalityStrictly local routing of traffic to backends (only in the
HTTPRouteresource's availability zone). -
gateway.alb.yc.io/rules.backends.balancing.panicThresholdPanic mode threshold for load balancing in %.
-
gateway.alb.yc.io/rules.backends.hc.timeoutHealth check response timeout.
-
gateway.alb.yc.io/rules.backends.hc.intervalHealth check interval.
-
gateway.alb.yc.io/rules.backends.hc.healthyThresholdNumber of successful health checks for resource to get the
healthystatus. -
gateway.alb.yc.io/rules.backends.hc.unhealthyThresholdNumber of failed health checks for resource to get the
unhealthystatus. -
gateway.alb.yc.io/rules.backends.hc.portHealth check port.
-
gateway.alb.yc.io/rules.backends.hc.http.pathPath for HTTP health checks, e.g.,
/health. It is used for HTTP(S) backends. -
gateway.alb.yc.io/rules.backends.hc.http.useHTTP2Use HTTP/2 for health checks. HTTP/1.1 is used by default. It is used for HTTP(S) backends.
-
gateway.alb.yc.io/rules.backends.hc.http.hostHost address for HTTP health checks.
-
gateway.alb.yc.io/rules.backends.hc.grpc.serviceNamegRPC service name for gRPC backend health checks.
-
gateway.alb.yc.io/rules.backends.hc.stream.sendData to send for a TCP health check. It is used for backends with a TCP interface.
-
gateway.alb.yc.io/rules.backends.hc.stream.receiveExpected response in a TCP health check. It is used for backends with a TCP interface.
-
gateway.alb.yc.io/rules.timeoutTotal HTTP connection timeout between the load balancer and backend.
-
gateway.alb.yc.io/rules.idleTimeoutInactive HTTP connection timeout.
-
gateway.alb.yc.io/rules.httpUpgradeTypesSupported
HTTP Upgradevalues, e.g., websocket. -
gateway.alb.yc.io/rules.securityProfileIdSmart Web Security security profile ID for the route.
-
gateway.alb.yc.io/rules.rbac.actionAction when specified conditions (
ALLOW/DENY) match for backend access control. -
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.header.nameHeader name for RBAC condition checks.
-
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.header.regexRegular expression for checking header value to manage access to the host over RBAC.
-
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.header.exactExact header value to manage access to the host over RBAC.
-
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.header.prefixHeader value prefix to manage access to the host over RBAC.
-
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.ip.remoteIpIP address or CIDR block to manage access to the host over RBAC.
-
gateway.alb.yc.io/rules.rbac.principals.<group_name>.<principal_name>.anyAny match of specified conditions to manage access to the host over RBAC (
true/false). -
gateway.alb.yc.io/hosts.rbac.actionAction when specified conditions match (
ALLOW/DENY) to manage access to the host over RBAC. -
gateway.alb.yc.io/rule.<rule_name>.backends.balancing.modeLoad balancing mode for a given rule. The possible values are
RANDOM,ROUND_ROBIN, andLEAST_REQUEST. -
gateway.alb.yc.io/rule.<rule_name>.timeoutTimeout for a given load balancing rule.
-
gateway.alb.yc.io/rule.<rule_name>.idleTimeoutInactivity timeout for a given load balancing rule.
-
-
-
spec(HTTPRouteSpec; this is a required field)Resource specification. For more information, see below.
HTTPRouteSpec
parentRefs:
- group: <string>
kind: <string>
namespace: <string>
name: <string>
sectionName: <string>
- ...
hostnames:
- <string>
- ...
rules:
- matches:
- path:
type: <string>
value: <string>
method: <string>
- ...
filters:
- <HTTPRouteFilter>
- ...
backendRefs:
- group: <string>
kind: <string>
name: <string>
namespace: <string>
port: <int32>
weight: <int32>
filters:
- <HTTPRouteFilter>
- ...
- ...
- ...
Where:
-
parentRefs([]ParentReference; this is a required field)Gatewayresources or their listeners specified in thespec.listenersfield associated withHTTPRoute. For more information, see this reference.The route must also comply with the rules described in the
Gatewayconfiguration (spec.listeners.allowedRoutesfield).-
namespace(string)Namespace the
Gatewayresource belongs to (see themetadata.namespacefield in its metadata).By default, it matches the
HTTPRouteresource namespace (metadata.namespacefield). -
name(string; this is a required field)Name of the
Gatewayresource (see themetadata.namefield in its metadata). -
sectionName(string)Name of the listener specified in the
Gatewayresource (see thespec.listeners.namefield in its metadata).
-
-
hostnames([]string)List of domain names (values of the
Hostheader for HTTP/1.1 or the:authoritypseudo-header for HTTP/2) for the route. The system will create virtual hosts in HTTP routers for each domain name.To match all subdomains at any level, use a wildcard
*in place of the first-level domain name. Wildcard domain values must be quoted.For example,
"*.example.com"matchesfoo.example.com,foo-bar.example.com,foo.bar.example.com, andfoo.bar.baz.example.com, but notexample.com.Wildcards must replace complete domain levels; for example,
*foo.example.comis invalid. -
rules([]HTTPRouteRule)Request routing and redirection rules.
-
matches([]HTTPRouteMatch)List of conditions for the rule to apply to a request if it meets at least one of them.
For example, the conditions below allow all
POSTrequests to the/fooendpoint and any requests to the/barendpoint:matches: - path: value: /foo method: POST - path: value: /barYou can only use fields listed below. Other fields described in the Gateway API reference
, i.e.,headersandqueryParams, are not supported.-
path(HTTPPathMatch)Reference to the path in the request URI.
-
type(string)Type of reference to the path in the request URI:
Exact: Path must matchrules.matches.path.value.PathPrefix: Path must begin withrules.matches.path.value.
The selected path type will affect traffic distribution and the path replacement mechanism for redirects. For more information, see below.
-
value(string)Incoming request URI full path or its prefix, depending on whether
ExactorPathPrefixis selected, respectively.
-
-
method(HTTPMethod)Request HTTP method.
-
-
filters([]HTTPRouteFilter)Filters specifying how request headers are modified when routing a request to any backend or redirecting it. For more information, see below.
You can specify either the
RequestHeaderModifieror theRequestRedirectfilter, but not both at the same time. -
backendRefs([]HTTPBackendRef)Kubernetes services for processing requests as backends.
You can specify either the YCStorageBucket resource (Object Storage bucket) or the Service resource.
-
name(string)Name of Kubernetes service or bucket resource.
-
namespace(string)Namespace the service or bucket resource belongs to.
-
group(string)Name of the Kubernetes API group the bucket resource belongs to, e.g.,
gwin.yandex.cloud. Only for theYCStorageBucketresource.The default value is an empty string that indicates the root API group.
-
kind(string)Type of the Kubernetes resource with a bucket. Only for the
YCStorageBucketresource. TheYCStorageBucketvalue is used. -
port(int32)Service port number. Only for the
Serviceresource.This number must match one of the port numbers specified in the
spec.ports.portfields of theServiceresource. For more information, see the resource configuration.This field is designed for the Gateway API and does not match any of the Application Load Balancer resource fields.
-
weight(int32)Backend weight. Backends in a group receive traffic in proportion to their weights.
You should either specify weights for all backends in a group, or not specify them at all. If weights are not specified, traffic will be equally distributed across backends.
A backend with zero or negative weight will not be receiving traffic.
-
filters([]HTTPRouteFilter)Settings for modifying request headers when routing requests to backends. For more information, see below.
You can only specify the
RequestHeaderModifierfilter.
-
-
HTTPRouteFilter
type: <string>
requestHeaderModifier:
set:
- name: <string>
value: <string>
- ...
add:
- name: <string>
value: <string>
- ...
remove:
- <string>
- ...
requestRedirect:
scheme: <string>
hostname: <string>
path:
type: <string>
replaceFullPath: <string>
replacePrefixMatch: <string>
port: <int32>
statusCode: <int>
Where:
-
type(string)Filter type:
RequestHeaderModifier: Request header modification. Specify the required settings in therequestHeaderModifierfield.RequestRedirect: Request redirection. Specify the required settings in therequestRedirectfield.
-
requestHeaderModifier(HTTPRequestHeaderFilter)Request header modification settings for the
RequestHeaderModifierfilter type.-
set([]HTTPHeader)Headers to overwrite.
-
name(string)Header name to overwrite.
-
value(string)Value written to the header.
-
-
add([]HTTPHeader)Headers to add.
-
name(string)Name of the header to add.
-
value(string)Value of the header to add.
-
-
remove([]string)Header names to remove.
-
-
requestRedirect(HTTPRequestRedirectFilter)Note
Gateway API supports redirect settings for updating the scheme (
scheme) and domain name (hostname) starting from version0.4.31.Install the most recent Gateway API version if you need these settings.
Request redirect settings for the
RequestRedirectfilter type.-
scheme(string)New request URI scheme, either
httporhttps. By default, the scheme remains unchanged.For redirection to work, an HTTPS traffic listener must be configured for Gateway.
Below is an example of request redirection with scheme change.
-
hostname(string)New domain name in the request URI. By default, the domain name remains unchanged.
Below is an example of request redirection with domain name change.
-
path(HTTPPathModifier)Settings for replacing the path in the request URI.
-
type(string)Path replacement type:
ReplaceFullPath: Full path replacement. Specify the new path in thereplaceFullPathfield.ReplacePrefixMatch: Full path or prefix replacement based on theHTTPRoutespec.rules.matches.pathvalue:ExactorPathPrefix, respectively. Specify the new path or its prefix in thereplacePrefixMatchfield.
-
replaceFullPath(string)New path for the
ReplaceFullPathreplacement type. -
replacePrefixMatch(string)New path or its prefix for the
ReplacePrefixMatchreplacement type. See the type description above.
-
-
port(int32)New port in the request URI.
-
statusCode(int)Redirect HTTP status code.
-
Examples of manifests for HTTPRoute resources
Note
Gateway API supports redirect settings for updating the scheme (scheme) and domain name (hostname) starting from version 0.4.31.
Install the most recent Gateway API version if you need these settings.
Request redirection with scheme change
In this example, requests arriving at the http listener configured for sample-gateway are routed. For redirection to work, an HTTPS traffic listener must be configured for Gateway.
All requests to http://demo.example.com/sample will be redirected to https://demo.example.com/sample with the HTTP code 301 Moved Permanently
Manifest for HTTPRoute: Request redirection with scheme change
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: sample-scheme-redirect
namespace: sample-namespace
spec:
parentRefs:
- name: sample-gateway
sectionName: http
namespace: gateways
hostnames:
- demo.example.com
rules:
- matches:
- path:
value: /sample
filters:
- type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301
Request redirection with domain name change
In this example, requests arriving at the http listener configured for sample-gateway are routed.
All requests to http://demo.example.com/sample will be redirected to http://example.org/sample with the HTTP code 301 Moved Permanently
Manifest for HTTPRoute: Request redirection with domain name change
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: sample-hostname-redirect
namespace: sample-namespace
spec:
parentRefs:
- name: sample-gateway
sectionName: http
namespace: gateways
hostnames:
- demo.example.com
rules:
- matches:
- path:
value: /sample
filters:
- type: RequestRedirect
requestRedirect:
hostname: example.org
statusCode: 301