sigs.k8s.io/gateway-api@v1.0.0/site-src/api-types/httproute.md (about) 1 # HTTPRoute 2 3 ??? success "Standard Channel in v0.5.0+" 4 5 The `HTTPRoute` resource is Beta and part of the Standard Channel in `v0.5.0+`. 6 7 [HTTPRoute][httproute] is a Gateway API type for specifying routing behavior 8 of HTTP requests from a Gateway listener to an API object, i.e. Service. 9 10 ## Spec 11 12 The specification of an HTTPRoute consists of: 13 14 - [ParentRefs][parentRef]- Define which Gateways this Route wants to be attached 15 to. 16 - [Hostnames][hostname] (optional)- Define a list of hostnames to use for 17 matching the Host header of HTTP requests. 18 - [Rules][httprouterule]- Define a list of rules to perform actions against 19 matching HTTP requests. Each rule consists of [matches][matches], 20 [filters][filters] (optional), and [backendRefs][backendRef] (optional) 21 fields. 22 23 The following illustrates an HTTPRoute that sends all traffic to one Service: 24  25 26 ### Attaching to Gateways 27 28 Each Route includes a way to reference the parent resources it wants to attach 29 to. In most cases, that's going to be Gateways, but there is some flexibility 30 here for implementations to support other types of parent resources. 31 32 The following example shows how a Route would attach to the `acme-lb` Gateway: 33 ```yaml 34 apiVersion: gateway.networking.k8s.io/v1beta1 35 kind: HTTPRoute 36 metadata: 37 name: httproute-example 38 spec: 39 parentRefs: 40 - name: acme-lb 41 ``` 42 43 Note that the target Gateway needs to allow HTTPRoutes from the route's 44 namespace to be attached for the attachment to be successful. 45 46 ### Hostnames 47 48 Hostnames define a list of hostnames to match against the Host header of the 49 HTTP request. When a match occurs, the HTTPRoute is selected to perform request 50 routing based on rules and filters (optional). A hostname is the fully qualified 51 domain name of a network host, as defined by [RFC 3986][rfc-3986]. Note the 52 following deviations from the “host” part of the URI as defined in the RFC: 53 54 - IPs are not allowed. 55 - The : delimiter is not respected because ports are not allowed. 56 57 Incoming requests are matched against hostnames before the HTTPRoute rules are 58 evaluated. If no hostname is specified, traffic is routed based on HTTPRoute 59 rules and filters (optional). 60 61 The following example defines hostname "my.example.com": 62 ```yaml 63 apiVersion: gateway.networking.k8s.io/v1beta1 64 kind: HTTPRoute 65 metadata: 66 name: httproute-example 67 spec: 68 hostnames: 69 - my.example.com 70 ``` 71 72 ### Rules 73 74 Rules define semantics for matching an HTTP request based on conditions, 75 optionally executing additional processing steps, and optionally forwarding 76 the request to an API object. 77 78 #### Matches 79 80 Matches define conditions used for matching an HTTP request. Each match is 81 independent, i.e. this rule will be matched if any single match is satisfied. 82 83 Take the following matches configuration as an example: 84 ```yaml 85 apiVersion: gateway.networking.k8s.io/v1beta1 86 kind: HTTPRoute 87 ... 88 spec: 89 rules: 90 - matches: 91 - path: 92 value: "/foo" 93 headers: 94 - name: "version" 95 value: "2" 96 - path: 97 value: "/v2/foo" 98 ``` 99 100 For a request to match against this rule, it must satisfy EITHER of the 101 following conditions: 102 103 - A path prefixed with /foo **AND** contains the header "version: 2" 104 - A path prefix of /v2/foo 105 106 If no matches are specified, the default is a prefix path match on “/”, 107 which has the effect of matching every HTTP request. 108 109 #### Filters (optional) 110 111 Filters define processing steps that must be completed during the request or 112 response lifecycle. Filters act as an extension point to express additional 113 processing that may be performed in Gateway implementations. Some examples 114 include request or response modification, implementing authentication 115 strategies, rate-limiting, and traffic shaping. 116 117 The following example adds header "my-header: foo" to HTTP requests with Host 118 header "my.filter.com". 119 ```yaml 120 {% include 'standard/http-filter.yaml' %} 121 ``` 122 123 API conformance is defined based on the filter type. The effects of ordering 124 multiple behaviors is currently unspecified. This may change in the future 125 based on feedback during the alpha stage. 126 127 Conformance levels are defined by the filter type: 128 129 - All "core" filters MUST be supported by implementations. 130 - Implementers are encouraged to support "extended" filters. 131 - "Implementation-specific" filters have no API guarantees across implementations. 132 133 Specifying a core filter multiple times has unspecified or 134 implementation-specific conformance. 135 136 All filters are expected to be compatible with each other except for the 137 URLRewrite and RequestRedirect filters, which may not be combined. If an 138 implementation can not support other combinations of filters, they must clearly 139 document that limitation. In cases where incompatible or unsupported 140 filters are specified and cause the `Accepted` condition to be set to status 141 `False`, implementations may use the `IncompatibleFilters` reason to specify 142 this configuration error. 143 144 #### BackendRefs (optional) 145 146 BackendRefs defines API objects where matching requests should be sent. If 147 unspecified, the rule performs no forwarding. If unspecified and no filters 148 are specified that would result in a response being sent, a 404 error code 149 is returned. 150 151 The following example forwards HTTP requests for prefix `/bar` to service 152 "my-service1" on port `8080` and HTTP requests for prefix `/some/thing` with 153 header `magic: foo` to service "my-service2" on port `8080`: 154 ```yaml 155 {% include 'standard/basic-http.yaml' %} 156 ``` 157 158 The following example uses the `weight` field to forward 90% of HTTP requests to 159 `foo.example.com` to the "foo-v1" Service and the other 10% to the "foo-v2" 160 Service: 161 ```yaml 162 {% include 'standard/traffic-splitting/traffic-split-2.yaml' %} 163 ``` 164 165 Reference the [backendRef][backendRef] API documentation for additional details 166 on `weight` and other fields. 167 168 ## Status 169 170 Status defines the observed state of HTTPRoute. 171 172 ### RouteStatus 173 174 RouteStatus defines the observed state that is required across all route types. 175 176 #### Parents 177 178 Parents define a list of the Gateways (or other parent resources) that are 179 associated with the HTTPRoute, and the status of the HTTPRoute with respect to 180 each of these Gateways. When a HTTPRoute adds a reference to a Gateway in 181 parentRefs, the controller that manages the Gateway should add an entry to this 182 list when the controller first sees the route and should update the entry as 183 appropriate when the route is modified. 184 185 The following example indicates HTTPRoute "http-example" has been accepted by 186 Gateway "gw-example" in namespace "gw-example-ns": 187 ```yaml 188 apiVersion: gateway.networking.k8s.io/v1beta1 189 kind: HTTPRoute 190 metadata: 191 name: http-example 192 ... 193 status: 194 parents: 195 - parentRefs: 196 name: gw-example 197 namespace: gw-example-ns 198 conditions: 199 - type: Accepted 200 status: "True" 201 ``` 202 203 ## Merging 204 Multiple HTTPRoutes can be attached to a single Gateway resource. Importantly, 205 only one Route rule may match each request. For more information on how conflict 206 resolution applies to merging, refer to the [API specification][httprouterule]. 207 208 209 [httproute]: /reference/spec/#gateway.networking.k8s.io/v1beta1.HTTPRoute 210 [httprouterule]: /reference/spec/#gateway.networking.k8s.io/v1beta1.HTTPRouteRule 211 [hostname]: /reference/spec/#gateway.networking.k8s.io/v1beta1.Hostname 212 [rfc-3986]: https://tools.ietf.org/html/rfc3986 213 [matches]: /reference/spec/#gateway.networking.k8s.io/v1beta1.HTTPRouteMatch 214 [filters]: /reference/spec/#gateway.networking.k8s.io/v1beta1.HTTPRouteFilter 215 [backendRef]: /reference/spec/#gateway.networking.k8s.io/v1beta1.HTTPBackendRef 216 [parentRef]: /reference/spec/#gateway.networking.k8s.io/v1beta1.ParentRef 217