github.com/projectcontour/contour@v1.28.2/site/content/docs/1.27/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 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. 32 33 Static provisioning makes sense for users who: 34 - prefer the traditional model of deploying Contour 35 - have only a single Gateway 36 - want to use just the standard listener ports (80/443) 37 - have highly customized YAML for deploying Contour. 38 39 Dynamic provisioning makes sense for users who: 40 - have many Gateways 41 - want to use additional listener ports 42 - prefer a simple declarative API for provisioning Contour instances 43 - want a fully conformant Gateway API implementation 44 45 ### Static Provisioning 46 47 To statically provision Contour with Gateway API enabled: 48 49 1. Install the [Gateway API experimental channel][3]. 50 1. Create a GatewayClass, with a controller name of `projectcontour.io/gateway-controller`. 51 1. Create a Gateway using the above GatewayClass. 52 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) 53 1. Install Contour using the above config file. 54 55 Contour provides an example manifest for this at https://projectcontour.io/quickstart/contour-gateway.yaml. 56 57 ### Dynamic Provisioning 58 59 To dynamically provision Contour with Gateway API enabled: 60 61 1. Install the [Contour Gateway Provisioner][9], which includes the Gateway API experimental channel. 62 1. Create a GatewayClass, with a controller name of `projectcontour.io/gateway-controller`. 63 1. Create a Gateway using the above GatewayClass. 64 65 The Contour Gateway Provisioner will deploy an instance of Contour in the Gateway's namespace implementing the Gateway spec. 66 67 **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. 68 69 ## Gateway Listeners 70 71 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. 72 For example, the following Gateway Listener configuration (abridged) requires service ports of 80 and 443, mapped to underlying container ports 8080 and 8443: 73 74 ```yaml 75 listeners: 76 - name: http 77 protocol: HTTP 78 port: 80 79 - name: https 80 protocol: HTTPS 81 port: 443 82 ``` 83 84 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. 85 In static provisioning, it is up to the platform operator to keep the Envoy resources in sync with the Gateway Listeners. 86 87 To get from the Gateway Listener port to the port that Envoy will be configured to listen on, i.e. the container port: 88 - add 8000 to the Listener port number 89 - if the result is greater than 65535, subtract 65535 90 - if the result is less than or equal to 1023, add 1023. 91 92 Note that, in rare corner cases, it's possible to have port conflicts. 93 Check the Gateway status to ensure that Listeners have been properly provisioned. 94 95 ## Routing 96 97 Gateway API defines multiple route types. 98 Each route type is appropriate for a different type of traffic being proxied to a backend service. 99 Contour implements `HTTPRoute`, `TLSRoute`, `GRPCRoute` and `TCPRoute`. 100 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. 101 102 ### Routing with HTTPProxy or Ingress 103 104 When Gateway API is enabled in Contour, it's still possible to use HTTPProxy or Ingress to define routes, with some limitations. 105 This is useful for users who: 106 - are in the process of migrating to Gateway API 107 - want to use the Contour Gateway Provisioner for dynamic provisioning, but need the advanced features of HTTPProxy 108 109 To use HTTPProxy or Ingress with Gateway API, define a Gateway with the following Listeners: 110 111 ```yaml 112 listeners: 113 - name: http 114 protocol: HTTP 115 port: 80 116 allowedRoutes: 117 namespaces: 118 from: All 119 - name: https 120 protocol: projectcontour.io/https 121 port: 443 122 allowedRoutes: 123 namespaces: 124 from: All 125 ``` 126 127 Note that for the second Listener, a Contour-specific protocol is used, and no TLS details are specified. 128 Instead, TLS details continue to be configured on the HTTPProxy or Ingress resource. 129 130 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. 131 132 ## Contour Gateway Provisioner 133 134 ### Customizing a GatewayClass 135 136 Gateway API [supports attaching parameters to a GatewayClass][5], which can customize the Gateways that are provisioned for that GatewayClass. 137 138 Contour defines a CRD called `ContourDeployment`, which can be used as `GatewayClass` parameters. 139 140 A simple example of a parameterized Contour GatewayClass that provisions Envoy as a Deployment instead of the default DaemonSet looks like: 141 142 ```yaml 143 kind: GatewayClass 144 apiVersion: gateway.networking.k8s.io/v1beta1 145 metadata: 146 name: contour-with-envoy-deployment 147 spec: 148 controllerName: projectcontour.io/gateway-controller 149 parametersRef: 150 kind: ContourDeployment 151 group: projectcontour.io 152 name: contour-with-envoy-deployment-params 153 namespace: projectcontour 154 --- 155 kind: ContourDeployment 156 apiVersion: projectcontour.io/v1alpha1 157 metadata: 158 namespace: projectcontour 159 name: contour-with-envoy-deployment-params 160 spec: 161 envoy: 162 workloadType: Deployment 163 ``` 164 165 All Gateways provisioned using the `contour-with-envoy-deployment` GatewayClass would get an Envoy Deployment. 166 167 See [the API documentation][6] for all `ContourDeployment` options. 168 169 It's important to note that, per the [GatewayClass spec][10]: 170 171 > It is recommended that [GatewayClass] be used as a template for Gateways. 172 > 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. 173 > This recommendation is intended to limit the blast radius of changes to GatewayClass or associated parameters. 174 > If implementations choose to propagate GatewayClass changes to existing Gateways, that MUST be clearly documented by the implementation. 175 176 Contour follows the recommended behavior, meaning changes to a GatewayClass and its parameters are not propagated down to existing Gateways. 177 178 ### Upgrades 179 180 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). 181 182 ## Disabling Experimental Resources 183 184 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. 185 To do this, Contour must be told to disable informers for the experimental resources. 186 In the Contour (control plane) deployment, use the `--disable-feature` flag for `contour serve` to disable informers for the experimental resources: 187 188 ```yaml 189 containers: 190 - name: contour 191 image: ghcr.io/projectcontour/contour:<version> 192 command: ["contour"] 193 args: 194 - serve 195 - --incluster 196 - --xds-address=0.0.0.0 197 - --xds-port=8001 198 - --contour-cafile=/certs/ca.crt 199 - --contour-cert-file=/certs/tls.crt 200 - --contour-key-file=/certs/tls.key 201 - --config-path=/config/contour.yaml 202 - --disable-feature=tlsroutes 203 - --disable-feature=grpcroutes 204 ``` 205 206 [1]: https://gateway-api.sigs.k8s.io/ 207 [2]: https://gateway-api.sigs.k8s.io/concepts/conformance/#2-support-levels 208 [3]: https://gateway-api.sigs.k8s.io/guides/#install-experimental-channel 209 [4]: https://gateway-api.sigs.k8s.io/guides/#install-standard-channel 210 [5]: https://gateway-api.sigs.k8s.io/api-types/gatewayclass/#gatewayclass-parameters 211 [6]: https://projectcontour.io/docs/main/config/api/#projectcontour.io/v1alpha1.ContourDeployment 212 [7]: https://projectcontour.io/docs/main/config/api/#projectcontour.io/v1alpha1.GatewayConfig 213 [8]: https://gateway-api.sigs.k8s.io/api-types/gatewayclass/#gatewayclass-controller-selection 214 [9]: https://projectcontour.io/quickstart/contour-gateway-provisioner.yaml 215 [10]: https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.GatewayClass 216 [11]: https://gateway-api.sigs.k8s.io/concepts/api-overview/#route-resources 217 [12]: /docs/{{< param version >}}/guides/gateway-api 218 [13]: https://github.com/projectcontour/contour/issues/5970 219 [14]: https://github.com/kubernetes-sigs/gateway-api/issues/2592