github.com/projectcontour/contour@v1.28.2/site/content/docs/main/config/gateway-api.md (about) 1 # Gateway API 2 3 ## Introduction 4 5 [Gateway API][1] is an open source project managed by the SIG Network community. 6 It is a collection of resources that model service networking in Kubernetes. 7 These resources - GatewayClass, Gateway, HTTPRoute, TCPRoute, Service, etc - aim to evolve Kubernetes service networking through expressive, extensible, and role-oriented interfaces that are implemented by many vendors and have broad industry support. 8 9 Contour implements Gateway API in addition to supporting HTTPProxy and Ingress. 10 In particular, Contour aims to support all [core and extended features][2] in Gateway API. 11 12 Gateway API has a comprehensive [website and docs][1], so this document focuses primarily on unique aspects of Contour's Gateway API implementation, rather than attempting to reproduce all of the content available on the Gateway API website. 13 The reader is suggested to familiarize themselves with the basics of Gateway API before continuing with this doc. 14 15 In Contour's Gateway API implementation, a Gateway corresponds 1:1 with a single deployment of Contour + Envoy. 16 In other words, each Gateway has its own control plane (Contour) and data plane (Envoy). 17 18 The remainder of this document delves into more detail regarding configuration options when using Contour with Gateway API. 19 If you are looking for a way to get started with Gateway API and Contour, see the [Gateway API guide][12], a step-by-step tutorial on getting Contour installed with Gateway API and using it to route traffic to a service. 20 21 ## Enabling Gateway API in Contour 22 23 There are two ways to deploy Contour with Gateway API support: **static** provisioning and **dynamic** provisioning. 24 25 In **static** provisioning, the platform operator defines a `Gateway` resource, and then manually deploys a Contour instance corresponding to that `Gateway` resource. 26 It is up to the platform operator to ensure that all configuration matches between the `Gateway` and the Contour/Envoy resources. 27 With static provisioning, Contour can be configured with either a [controller name][8], or a specific gateway (see the [API documentation][7].) 28 If configured with a controller name, Contour will process the oldest `GatewayClass`, its oldest `Gateway`, and that `Gateway's` routes, for the given controller name. 29 If configured with a specific gateway, Contour will process that `Gateway` and its routes. 30 31 **Note:** configuring Contour with a controller name is deprecated and will be removed in a future release. Use a specific gateway reference or dynamic provisioning instead. 32 33 In **dynamic** provisioning, the platform operator first deploys Contour's Gateway provisioner. Then, the platform operator defines a `Gateway` resource, and the provisioner automatically deploys a Contour instance that corresponds to the `Gateway's` configuration and will process that `Gateway` and its routes. 34 35 Static provisioning makes sense for users who: 36 - prefer the traditional model of deploying Contour 37 - have only a single Gateway 38 - want to use just the standard listener ports (80/443) 39 - have highly customized YAML for deploying Contour. 40 41 Dynamic provisioning makes sense for users who: 42 - have many Gateways 43 - want to use additional listener ports 44 - prefer a simple declarative API for provisioning Contour instances 45 - want a fully conformant Gateway API implementation 46 47 ### Static Provisioning 48 49 To statically provision Contour with Gateway API enabled: 50 51 1. Install the [Gateway API experimental channel][3]. 52 1. Create a GatewayClass, with a controller name of `projectcontour.io/gateway-controller`. 53 1. Create a Gateway using the above GatewayClass. 54 1. In the Contour config file, add a reference to the above Gateway via `gateway.gatewayRef` (see https://projectcontour.io/docs/1.25/configuration/#gateway-configuration) 55 1. Install Contour using the above config file. 56 57 Contour provides an example manifest for this at https://projectcontour.io/quickstart/contour-gateway.yaml. 58 59 ### Dynamic Provisioning 60 61 To dynamically provision Contour with Gateway API enabled: 62 63 1. Install the [Contour Gateway Provisioner][9], which includes the Gateway API experimental channel. 64 1. Create a GatewayClass, with a controller name of `projectcontour.io/gateway-controller`. 65 1. Create a Gateway using the above GatewayClass. 66 67 The Contour Gateway Provisioner will deploy an instance of Contour in the Gateway's namespace implementing the Gateway spec. 68 69 **Note:** Gateway names must be 63 characters or shorter, to avoid issues when generating dependent resources. See [projectcontour/contour#5970][13] and [kubernetes-sigs/gateway-api#2592][14] for more information. 70 71 ## Gateway Listeners 72 73 Each unique Gateway Listener port requires the Envoy service to expose that port, and to map it to an underlying port in the Envoy daemonset/deployment that Envoy is configured to listen on. 74 For example, the following Gateway Listener configuration (abridged) requires service ports of 80 and 443, mapped to underlying container ports 8080 and 8443: 75 76 ```yaml 77 listeners: 78 - name: http 79 protocol: HTTP 80 port: 80 81 - name: https 82 protocol: HTTPS 83 port: 443 84 ``` 85 86 In dynamic provisioning, the Contour Gateway Provisioner will continuously ensure that the Envoy service and daemonset/deployment are kept in sync with the Gateway Listener configuration. 87 In static provisioning, it is up to the platform operator to keep the Envoy resources in sync with the Gateway Listeners. 88 89 To get from the Gateway Listener port to the port that Envoy will be configured to listen on, i.e. the container port: 90 - add 8000 to the Listener port number 91 - if the result is greater than 65535, subtract 65535 92 - if the result is less than or equal to 1023, add 1023. 93 94 Note that, in rare corner cases, it's possible to have port conflicts. 95 Check the Gateway status to ensure that Listeners have been properly provisioned. 96 97 ## Routing 98 99 Gateway API defines multiple route types. 100 Each route type is appropriate for a different type of traffic being proxied to a backend service. 101 Contour implements `HTTPRoute`, `TLSRoute`, `GRPCRoute` and `TCPRoute`. 102 The details of each of these route types are covered in extensive detail on the Gateway API website; the [route resources overview][11] is a good place to start learning about them. 103 104 ### Routing with HTTPProxy or Ingress 105 106 When Gateway API is enabled in Contour, it's still possible to use HTTPProxy or Ingress to define routes, with some limitations. 107 This is useful for users who: 108 - are in the process of migrating to Gateway API 109 - want to use the Contour Gateway Provisioner for dynamic provisioning, but need the advanced features of HTTPProxy 110 111 To use HTTPProxy or Ingress with Gateway API, define a Gateway with the following Listeners: 112 113 ```yaml 114 listeners: 115 - name: http 116 protocol: HTTP 117 port: 80 118 allowedRoutes: 119 namespaces: 120 from: All 121 - name: https 122 protocol: projectcontour.io/https 123 port: 443 124 allowedRoutes: 125 namespaces: 126 from: All 127 ``` 128 129 Note that for the second Listener, a Contour-specific protocol is used, and no TLS details are specified. 130 Instead, TLS details continue to be configured on the HTTPProxy or Ingress resource. 131 132 This is an area of active development and further work will be done in upcoming releases to better support migrations and mixed modes of operation. 133 134 ## Contour Gateway Provisioner 135 136 ### Customizing a GatewayClass 137 138 Gateway API [supports attaching parameters to a GatewayClass][5], which can customize the Gateways that are provisioned for that GatewayClass. 139 140 Contour defines a CRD called `ContourDeployment`, which can be used as `GatewayClass` parameters. 141 142 A simple example of a parameterized Contour GatewayClass that provisions Envoy as a Deployment instead of the default DaemonSet looks like: 143 144 ```yaml 145 kind: GatewayClass 146 apiVersion: gateway.networking.k8s.io/v1 147 metadata: 148 name: contour-with-envoy-deployment 149 spec: 150 controllerName: projectcontour.io/gateway-controller 151 parametersRef: 152 kind: ContourDeployment 153 group: projectcontour.io 154 name: contour-with-envoy-deployment-params 155 namespace: projectcontour 156 --- 157 kind: ContourDeployment 158 apiVersion: projectcontour.io/v1alpha1 159 metadata: 160 namespace: projectcontour 161 name: contour-with-envoy-deployment-params 162 spec: 163 envoy: 164 workloadType: Deployment 165 ``` 166 167 All Gateways provisioned using the `contour-with-envoy-deployment` GatewayClass would get an Envoy Deployment. 168 169 See [the API documentation][6] for all `ContourDeployment` options. 170 171 It's important to note that, per the [GatewayClass spec][10]: 172 173 > It is recommended that [GatewayClass] be used as a template for Gateways. 174 > This means that a Gateway is based on the state of the GatewayClass at the time it was created and changes to the GatewayClass or associated parameters are not propagated down to existing Gateways. 175 > This recommendation is intended to limit the blast radius of changes to GatewayClass or associated parameters. 176 > If implementations choose to propagate GatewayClass changes to existing Gateways, that MUST be clearly documented by the implementation. 177 178 Contour follows the recommended behavior, meaning changes to a GatewayClass and its parameters are not propagated down to existing Gateways. 179 180 ### Upgrades 181 182 When the Contour Gateway Provisioner is upgraded to a new version, it will upgrade all Gateways it controls (both the control plane and the data plane). 183 184 ## Disabling Experimental Resources 185 186 Some users may want to use Contour with the [Gateway API standard channel][4] instead of the experimental channel, to avoid installing alpha resources into their clusters. 187 To do this, Contour must be told to disable informers for the experimental resources. 188 In the Contour (control plane) deployment, use the `--disable-feature` flag for `contour serve` to disable informers for the experimental resources: 189 190 ```yaml 191 containers: 192 - name: contour 193 image: ghcr.io/projectcontour/contour:<version> 194 command: ["contour"] 195 args: 196 - serve 197 - --incluster 198 - --xds-address=0.0.0.0 199 - --xds-port=8001 200 - --contour-cafile=/certs/ca.crt 201 - --contour-cert-file=/certs/tls.crt 202 - --contour-key-file=/certs/tls.key 203 - --config-path=/config/contour.yaml 204 - --disable-feature=tlsroutes 205 - --disable-feature=grpcroutes 206 ``` 207 208 [1]: https://gateway-api.sigs.k8s.io/ 209 [2]: https://gateway-api.sigs.k8s.io/concepts/conformance/#2-support-levels 210 [3]: https://gateway-api.sigs.k8s.io/guides/#install-experimental-channel 211 [4]: https://gateway-api.sigs.k8s.io/guides/#install-standard-channel 212 [5]: https://gateway-api.sigs.k8s.io/api-types/gatewayclass/#gatewayclass-parameters 213 [6]: https://projectcontour.io/docs/main/config/api/#projectcontour.io/v1alpha1.ContourDeployment 214 [7]: https://projectcontour.io/docs/main/config/api/#projectcontour.io/v1alpha1.GatewayConfig 215 [8]: https://gateway-api.sigs.k8s.io/api-types/gatewayclass/#gatewayclass-controller-selection 216 [9]: https://projectcontour.io/quickstart/contour-gateway-provisioner.yaml 217 [10]: https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1.GatewayClass 218 [11]: https://gateway-api.sigs.k8s.io/concepts/api-overview/#route-resources 219 [12]: /docs/{{< param version >}}/guides/gateway-api 220 [13]: https://github.com/projectcontour/contour/issues/5970 221 [14]: https://github.com/kubernetes-sigs/gateway-api/issues/2592