sigs.k8s.io/gateway-api@v1.0.0/site-src/concepts/api-overview.md (about) 1 # API Overview 2 3 This document provides an overview of Gateway API. 4 5 ## Roles and personas 6 7 There are 3 primary roles in Gateway API, as described in [roles and personas]: 8 9 - **Ian** (he/him): Infrastructure Provider 10 - **Chihiro** (they/them): Cluster Operator 11 - **Ana** (she/her): Application Developer 12 13 [roles and personas]:/concepts/roles-and-personas 14 15 ## Resource model 16 17 !!! note 18 Gateway API resources are in the `gateway.networking.k8s.io` API group as 19 Custom Resource Definitions (CRDs). Unqualified resource names below will 20 implicitly be in this API group. 21 22 There are three main types of objects in our resource model: 23 24 *GatewayClass* defines a set of gateways with a common configuration and 25 behavior. 26 27 *Gateway* requests a point where traffic can be translated to Services within 28 the cluster. 29 30 *Routes* describe how traffic coming via the Gateway maps to the Services. 31 32 ### GatewayClass 33 34 GatewayClass defines a set of Gateways that share a common configuration and 35 behaviour. Each GatewayClass will be handled by a single controller, although 36 controllers may handle more than one GatewayClass. 37 38 GatewayClass is a cluster-scoped resource. There must be at least one 39 GatewayClass defined in order to be able to have functional Gateways. A 40 controller that implements the Gateway API does so by providing an associated 41 GatewayClass resource that the user can reference from their Gateway(s). 42 43 This is similar to 44 [IngressClass](https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class) 45 for Ingress and 46 [StorageClass](https://kubernetes.io/docs/concepts/storage/storage-classes/) for 47 PersistentVolumes. In Ingress v1beta1, the closest analog to GatewayClass is the 48 `ingress-class` annotation, and in IngressV1, the closest analog is the 49 IngressClass object. 50 51 ### Gateway 52 53 A Gateway describes how traffic can be translated to Services within the 54 cluster. That is, it defines a request for a way to translate traffic from 55 somewhere that does not know about Kubernetes to somewhere that does. For 56 example, traffic sent to a Kubernetes Service by a cloud load balancer, an 57 in-cluster proxy, or an external hardware load balancer. While many use cases 58 have client traffic originating “outside” the cluster, this is not a 59 requirement. 60 61 It defines a request for a specific load balancer config that implements the 62 GatewayClass’ configuration and behaviour contract. The resource may be created 63 by an operator directly, or may be created by a controller handling a 64 GatewayClass. 65 66 As the Gateway spec captures user intent, it may not contain a complete 67 specification for all attributes in the spec. For example, the user may omit 68 fields such as addresses, TLS settings. This allows the controller 69 managing the GatewayClass to provide these settings for the user, resulting in a 70 more portable spec. This behaviour will be made clear using the GatewayClass 71 Status object. 72 73 A Gateway may be attached to one or more *Route references* which serve to direct 74 traffic for a subset of traffic *to a specific service.* 75 76 ### Route Resources 77 78 Route resources define protocol-specific rules for mapping requests from a Gateway 79 to Kubernetes Services. 80 81 As of v1alpha2, four Route resource types are included with the API. Custom Route types 82 that are implementation-specific are encouraged for other protocols. New route 83 types may be added to the API in future. 84 85 #### HTTPRoute 86 87 HTTPRoute is for multiplexing HTTP or terminated HTTPS connections. It's intended 88 for use in cases where you want to inspect the HTTP stream and use HTTP request data 89 for either routing or modification, for example using HTTP Headers for routing, or 90 modifying them in-flight. 91 92 #### TLSRoute 93 94 !!! info "Experimental Channel" 95 96 The `TLSRoute` resource described below is currently only included in the 97 "Experimental" channel of Gateway API. For more information on release 98 channels, refer to the [related documentation](https://gateway-api.sigs.k8s.io/concepts/versioning). 99 100 TLSRoute is for multiplexing TLS connections, discriminated via SNI. It's intended 101 for where you want to use the SNI as the main routing method, and are not interested 102 in properties of the higher-level protocols like HTTP. The byte stream of the 103 connection is proxied without any inspection to the backend. 104 105 #### TCPRoute and UDPRoute 106 107 !!! info "Experimental Channel" 108 109 The `TCPRoute` and `UDPRoute` resources described below are currently only included in the 110 "Experimental" channel of Gateway API. For more information on release 111 channels, refer to the [related documentation](https://gateway-api.sigs.k8s.io/concepts/versioning). 112 113 TCPRoute (and UDPRoute) are intended for use for mapping one or more ports 114 to a single backend. In this case, there is no discriminator you can 115 use to choose different backends on the same port, so each TCPRoute really needs a 116 different port on the listener (in general, anyway). You can terminate TLS in 117 which case the unencrypted byte stream is passed through to the backend. 118 You can choose to not terminate TLS, in which case the encrypted byte stream 119 is passed through to the backend. 120 121 #### GRPCRoute 122 123 !!! info "Experimental Channel" 124 125 The `GRPCRoute` resource described below is currently only included in the 126 "Experimental" channel of Gateway API. For more information on release 127 channels, refer to the [related documentation](https://gateway-api.sigs.k8s.io/concepts/versioning). 128 129 GRPCRoute is for idiomatically routing gRPC traffic. Gateways supporting 130 GRPCRoute are required to support HTTP/2 without an initial upgrade from HTTP/1, 131 so gRPC traffic is guaranteed to flow properly. 132 133 #### Route summary table 134 135 The "Routing Discriminator" column below refers to what information can be used 136 to allow multiple Routes to share ports on the Listener. 137 138 |Object|OSI Layer|Routing Discriminator|TLS Support|Purpose| 139 |------|---------|---------------------|-----------|-------| 140 |HTTPRoute| Layer 7 | Anything in the HTTP Protocol | Terminated only | HTTP and HTTPS Routing| 141 |TLSRoute| Somewhere between layer 4 and 7| SNI or other TLS properties| Passthrough or Terminated | Routing of TLS protocols including HTTPS where inspection of the HTTP stream is not required.| 142 |TCPRoute| Layer 4| destination port | Passthrough or Terminated | Allows for forwarding of a TCP stream from the Listener to the Backends | 143 |UDPRoute| Layer 4| destination port | None | Allows for forwarding of a UDP stream from the Listener to the Backends. | 144 |GRPCRoute| Layer 7 | Anything in the gRPC Protocol | Terminated only | gRPC Routing over HTTP/2 and HTTP/2 cleartext| 145 146 Note that traffic routed via HTTPRoute and TCPRoute can be encrypted between the 147 Gateway and backend (commonly referred to as reencryption). It is not possible 148 to configure that with existing Gateway API resources, but implementations may 149 provide custom configuration for this until there is a standardized approach 150 defined by Gateway API. 151 152 ## Attaching Routes to Gateways 153 154 !!! note 155 This section has changed significantly between v1alpha1 and v1alpha2. This 156 section describes the v1alpha2 approach. 157 158 When a Route attaches to a Gateway, it represents configuration that is applied 159 on the Gateway that configures the underlying load balancer or proxy. How and 160 which Routes attach to Gateways is controlled by the resources themselves. Route 161 and Gateway resources have built-in controls to permit or constrain how they are 162 attached. Together with Kubernetes RBAC, these allow organizations to enforce 163 policies for how Routes are exposed and on which Gateways. 164 165 There is a lot of flexibility in how Routes can attach to Gateways to achieve 166 different organizational policies and scopes of responsibility. These are 167 different relationships that Gateways and Routes can have: 168 169 - **One-to-one** - A Gateway and Route may be deployed and used by a single 170 owner and have a one-to-one relationship. 171 - **One-to-many** - A Gateway can have many Routes bound to it that are owned by 172 different teams from across different Namespaces. 173 - **Many-to-one** - Routes can also be bound to more than one Gateway, allowing 174 a single Route to control application exposure simultaneously across different 175 IPs, load balancers, or networks. 176 177 ### Example 178 179 [Chihiro] has deployed a Gateway `shared-gw` in the `infra` Namespace to be 180 used by different application teams for exposing their applications outside 181 the cluster. Teams A and B (in Namespaces `A` and `B` respectively) attach 182 their Routes to this Gateway. They are unaware of each other and as long as 183 their Route rules do not conflict with each other they can continue operating 184 in isolation. Team C has special networking needs (perhaps performance, 185 security, or criticality) and they need a dedicated Gateway to proxy their 186 application to the outside world. Team C deploys their own Gateway 187 `dedicated-gw` in the `C` Namespace that can only be used by apps in the `C` 188 Namespace. 189 190 <!-- source: https://docs.google.com/presentation/d/1neBkFDTZ__vRoDXIWvAcxk2Pb7-evdBT6ykw_frf9QQ/edit?usp=sharing --> 191  192 193 [Chihiro]:/concepts/roles-and-personas#Chihiro 194 195 ### How it Works 196 197 The following is required for a Route to be attached to a Gateway: 198 199 1. The Route needs an entry in its `parentRefs` field referencing the Gateway. 200 2. At least one listener on the Gateway needs to allow this attachment. 201 202 #### Referencing Gateways 203 204 !!! info "Experimental Channel" 205 206 The `Port` field described below is currently only included in the 207 "Experimental" channel of Gateway API. For more information on release 208 channels, refer to the [related documentation](https://gateway-api.sigs.k8s.io/concepts/versioning/#adding-experimental-fields). 209 210 A Route can reference a Gateway by specifying the namespace (optional if the 211 Route and the Gateway are in the same namespace) and name of the Gateway in 212 a `parentRef`. A Route can further select a subset of listeners under the 213 Gateway using the following fields in `parentRef`: 214 215 1. **SectionName** When `sectionName` is set, the Route selects the listener 216 with the specified name. 217 2. **Port** When `port` is set, the Route selects all listeners listening on 218 the specified port and with protocol compatible with this kind of Route. 219 220 When multiple fields in `parentRef` are set, the Route selects listeners that 221 satisfy all conditions specified in those fields. For example, when both 222 `sectionName` and `port` are set, the Route selects listeners with the specified 223 name AND listening on the specified port. 224 225 #### Restricting Route Attachment 226 227 Each Gateway listener can restrict which Routes can be attached with the 228 following mechanisms: 229 230 1. **Hostname:** When the `hostname` field on a listener is set, attached Routes 231 that specify a `hostnames` field must have at least one overlapping value. 232 2. **Namespaces:** The `allowedRoutes.namespaces` field on a listener can be 233 used to restrict where Routes may be attached from. The `namespaces.from` 234 field supports the following values: 235 * `Same` is the default option. Only Routes in the same namespace 236 as this Gateway may be attached. 237 * `All` will allow Routes from all Namespaces to be attached. 238 * `Selector` means that Routes from a subset of Namespaces selected by a 239 Namespace label selector may be attached to this Gateway. When `Selector` 240 is used, the `namespaces.selector` field must be used to specify label 241 selectors. This field is not supported with `All` or `Same`. 242 3. **Kinds:** The `allowedRoutes.kinds` field on a listener can be used to 243 restrict the kinds of Routes that may be attached. 244 245 If none of the above are specified, a Gateway listener will trust Routes 246 attached from the same namespace that support the listener protocol. 247 248 #### Further Gateway - Route attachment examples 249 250 The following `my-route` Route wants to attach to the `foo-gateway` in the 251 `gateway-api-example-ns1` and will not attach to any other Gateways. Note that 252 `foo-gateway` is in a different Namespace. The `foo-gateway` must allow 253 attachment from HTTPRoutes in the namespace `gateway-api-example-ns2`. 254 255 ```yaml 256 {% include 'standard/http-route-attachment/httproute.yaml' %} 257 ``` 258 259 This `foo-gateway` allows the `my-route` HTTPRoute to attach. 260 261 ```yaml 262 {% include 'standard/http-route-attachment/gateway-strict.yaml' %} 263 ``` 264 265 For a more permissive example, the below Gateway will allow all HTTPRoute resources 266 to attach from Namespaces with the "expose-apps: true" label. 267 268 ```yaml 269 {% include 'standard/http-route-attachment/gateway-namespaces.yaml' %} 270 ``` 271 272 ### Combined types 273 274 The combination of `GatewayClass`, `Gateway`, `xRoute` and `Service`(s) 275 defines an implementable load-balancer. The diagram below illustrates the 276 relationships between the different resources: 277 278 <!-- source: https://docs.google.com/document/d/1BxYbDovMwnEqe8lj8JwHo8YxHAt3oC7ezhlFsG_tyag/edit#heading=h.8du598fded3c --> 279  280 281 ### Request flow 282 283 A typical [north/south] API request flow for a gateway implemented using a 284 reverse proxy is: 285 286 1. A client makes a request to <http://foo.example.com>. 287 2. DNS resolves the name to a `Gateway` address. 288 3. The reverse proxy receives the request on a `Listener` and uses the [Host 289 header](https://tools.ietf.org/html/rfc7230#section-5.4) to match an 290 `HTTPRoute`. 291 4. Optionally, the reverse proxy can perform request header and/or path 292 matching based on `match` rules of the `HTTPRoute`. 293 5. Optionally, the reverse proxy can modify the request, i.e. add/remove 294 headers, based on `filter` rules of the `HTTPRoute`. 295 6. Lastly, the reverse proxy forwards the request to one or more objects, i.e. 296 `Service`, in the cluster based on `backendRefs` rules of the `HTTPRoute`. 297 298 [north/south]:/concepts/glossary#northsouth-traffic 299 300 ### TLS Configuration 301 302 TLS is configured on Gateway listeners, and may be referred to across namespaces. 303 304 Please refer to the [TLS details](/guides/tls) guide for a deep dive on TLS. 305 306 ## Attaching Routes to Services 307 308 !!! danger "Experimental in v0.8.0" 309 310 The [GAMMA initiative][gamma] work for supporting service mesh use cases 311 is _experimental_ in `v0.8.0`. It is possible that it will change; we do 312 not recommend it in production at this point. 313 314 In particular, binding Routes directly to Services seems to be the current 315 best choice for configuring mesh routing, but it is still **experimental** 316 and thus **subject to change**. 317 318 When using the Gateway API to configure a [service mesh], the Route will 319 attach directly to a Service, representing configuration meant to be applied 320 to any traffic directed to the Service. How and which Routes attach to a given 321 Service is controlled by the Routes themselves (working with Kubernetes RBAC), 322 as covered in the [GAMMA routing documentation]. 323 324 [GAMMA]:/concepts/gamma 325 [GAMMA routing documentation]:/concepts/gamma#gateway-api-for-mesh 326 [service mesh]:/concepts/glossary#service-mesh 327 328 ## Extension points 329 330 A number of extension points are provided in the API to provide flexibility in 331 addressing the large number of use-cases that cannot be addressed by a general 332 purpose API. 333 334 Here is a summary of extension points in the API: 335 336 - **BackendRefs**: This extension point should be used for forwarding 337 traffic to network endpoints other than core Kubernetes Service resource. 338 Examples include an S3 bucket, Lambda function, a file-server, etc. 339 - **HTTPRouteFilter**: This API type in HTTPRoute provides a way to hook into 340 the request/response lifecycle of an HTTP request. 341 - **Custom Routes**: If none of the above extensions points suffice for a use 342 case, Implementers can choose to create custom Route resources for protocols 343 that are not currently supported in the API. Custom Route types need to share 344 the same fields that core Route types do. These are contained within 345 CommonRouteSpec and RouteStatus. 346 347 Whenever you are using an extension point without any prior art, please let 348 the community know. As we learn more about usage of extension points, we would 349 like to find the common denominators and promote the features to core/extended 350 API conformance.