2022-04-15 13:44:08 +00:00
---
title: "Traefik Kubernetes Gateway API Documentation"
description: "Learn how to use the Kubernetes Gateway API as a provider for configuration discovery in Traefik Proxy. Read the technical documentation."
---
2020-12-15 15:40:05 +00:00
# Traefik & Kubernetes with Gateway API
The Kubernetes Gateway API, The Experimental Way.
{: .subtitle }
2021-02-11 18:04:03 +00:00
Gateway API is the evolution of Kubernetes APIs that relate to `Services` , such as `Ingress` .
2020-12-15 15:40:05 +00:00
The Gateway API project is part of Kubernetes, working under SIG-NETWORK.
2021-02-19 16:16:03 +00:00
The Kubernetes Gateway provider is a Traefik implementation of the [Gateway API ](https://gateway-api.sigs.k8s.io/ )
2021-02-11 18:04:03 +00:00
specifications from the Kubernetes Special Interest Groups (SIGs).
2020-12-15 15:40:05 +00:00
2021-11-09 10:34:06 +00:00
This provider is proposed as an experimental feature and partially supports the Gateway API [v0.4.0 ](https://github.com/kubernetes-sigs/gateway-api/releases/tag/v0.4.0 ) specification.
2020-12-15 15:40:05 +00:00
!!! warning "Enabling The Experimental Kubernetes Gateway Provider"
2021-02-11 18:04:03 +00:00
Since this provider is still experimental, it needs to be activated in the experimental section of the static configuration.
2020-12-15 15:40:05 +00:00
```yaml tab="File (YAML)"
experimental:
kubernetesGateway: true
2021-02-11 18:04:03 +00:00
2020-12-15 15:40:05 +00:00
providers:
kubernetesGateway: {}
#...
```
2021-02-11 18:04:03 +00:00
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[experimental]
kubernetesGateway = true
[providers.kubernetesGateway]
#...
```
2020-12-15 15:40:05 +00:00
```bash tab="CLI"
--experimental.kubernetesgateway=true --providers.kubernetesgateway=true #...
```
## Configuration Requirements
!!! tip "All Steps for a Successful Deployment"
2021-02-11 18:04:03 +00:00
2020-12-15 15:40:05 +00:00
* Add/update the Kubernetes Gateway API [definitions ](../reference/dynamic-configuration/kubernetes-gateway.md#definitions ).
2021-11-09 10:34:06 +00:00
* Add/update the [RBAC ](../reference/dynamic-configuration/kubernetes-gateway.md#rbac ) for the Traefik custom resources.
2020-12-15 15:40:05 +00:00
* Add all needed Kubernetes Gateway API [resources ](../reference/dynamic-configuration/kubernetes-gateway.md#resources ).
## Examples
??? example "Kubernetes Gateway Provider Basic Example"
```yaml tab="Gateway API"
--8< -- " content / reference / dynamic-configuration / kubernetes-gateway-simple-https . yml "
```
```yaml tab="Whoami Service"
--8< -- " content / reference / dynamic-configuration / kubernetes-whoami-svc . yml "
```
2021-02-11 18:04:03 +00:00
2020-12-15 15:40:05 +00:00
```yaml tab="Traefik Service"
--8< -- " content / reference / dynamic-configuration / kubernetes-gateway-traefik-lb-svc . yml "
```
2021-02-11 18:04:03 +00:00
2020-12-15 15:40:05 +00:00
```yaml tab="Gateway API CRDs"
# All resources definition must be declared
2021-11-09 10:34:06 +00:00
--8< -- " content / reference / dynamic-configuration / gateway . networking . k8s . io_gatewayclasses . yaml "
--8< -- " content / reference / dynamic-configuration / gateway . networking . k8s . io_gateways . yaml "
--8< -- " content / reference / dynamic-configuration / gateway . networking . k8s . io_httproutes . yaml "
2020-12-15 15:40:05 +00:00
```
```yaml tab="RBAC"
--8< -- " content / reference / dynamic-configuration / kubernetes-gateway-rbac . yml "
```
2021-04-21 08:28:03 +00:00
The Kubernetes Gateway API project provides several guides on how to use the APIs.
2021-02-11 18:04:03 +00:00
These guides can help you to go further than the example above.
2022-10-17 08:52:08 +00:00
The [getting started guide ](https://gateway-api.sigs.k8s.io/v1alpha2/guides/ ) details how to install the CRDs from their repository.
2021-02-11 18:04:03 +00:00
!!! note ""
2021-11-09 10:34:06 +00:00
Keep in mind that the Traefik Gateway provider only supports the `v0.4.0` (v1alpha2).
2021-02-11 18:04:03 +00:00
For now, the Traefik Gateway Provider can be used while following the below guides:
2020-12-15 15:40:05 +00:00
2021-11-09 10:34:06 +00:00
* [Simple Gateway ](https://gateway-api.sigs.k8s.io/v1alpha2/guides/simple-gateway/ )
* [HTTP routing ](https://gateway-api.sigs.k8s.io/v1alpha2/guides/http-routing/ )
* [TLS ](https://gateway-api.sigs.k8s.io/v1alpha2/guides/tls/ )
2020-12-15 15:40:05 +00:00
## Resource Configuration
2021-02-11 18:04:03 +00:00
When using Kubernetes Gateway API as a provider, Traefik uses Kubernetes
[Custom Resource Definitions ](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/ )
2020-12-15 15:40:05 +00:00
to retrieve its routing configuration.
2021-04-13 16:26:03 +00:00
All concepts can be found in the official API concepts [documentation ](https://gateway-api.sigs.k8s.io/concepts/api-overview/ ).
2020-12-15 15:40:05 +00:00
Traefik implements the following resources:
* `GatewayClass` defines a set of Gateways that share a common configuration and behaviour.
* `Gateway` describes how traffic can be translated to Services within the cluster.
2021-05-20 09:50:12 +00:00
* `HTTPRoute` defines HTTP rules for mapping requests from a Gateway to Kubernetes Services.
* `TCPRoute` defines TCP rules for mapping requests from a Gateway to Kubernetes Services.
* `TLSRoute` defines TLS rules for mapping requests from a Gateway to Kubernetes Services.
2020-12-15 15:40:05 +00:00
2021-02-11 18:04:03 +00:00
## Provider Configuration
2020-12-15 15:40:05 +00:00
### `endpoint`
2021-02-11 18:04:03 +00:00
_Optional, Default=""_
The Kubernetes server endpoint URL.
When deployed into Kubernetes, Traefik reads the environment variables `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` or `KUBECONFIG` to construct the endpoint.
The access token is looked up in `/var/run/secrets/kubernetes.io/serviceaccount/token` and the SSL CA certificate in `/var/run/secrets/kubernetes.io/serviceaccount/ca.crt` .
Both are mounted automatically when deployed inside Kubernetes.
The endpoint may be specified to override the environment variable values inside a cluster.
When the environment variables are not found, Traefik tries to connect to the Kubernetes API server with an external-cluster client.
In this case, the endpoint is required.
Specifically, it may be set to the URL used by `kubectl proxy` to connect to a Kubernetes cluster using the granted authentication and authorization of the associated kubeconfig.
2020-12-15 15:40:05 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesGateway:
endpoint: "http://localhost:8080"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesGateway]
endpoint = "http://localhost:8080"
# ...
```
2020-12-15 15:40:05 +00:00
```bash tab="CLI"
--providers.kubernetesgateway.endpoint=http://localhost:8080
```
### `token`
2021-02-11 18:04:03 +00:00
_Optional, Default=""_
Bearer token used for the Kubernetes client configuration.
2020-12-15 15:40:05 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesGateway:
2021-01-22 08:02:04 +00:00
token: "mytoken"
2020-12-15 15:40:05 +00:00
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesGateway]
token = "mytoken"
# ...
```
2020-12-15 15:40:05 +00:00
```bash tab="CLI"
--providers.kubernetesgateway.token=mytoken
```
### `certAuthFilePath`
2021-02-11 18:04:03 +00:00
_Optional, Default=""_
Path to the certificate authority file.
Used for the Kubernetes client configuration.
2020-12-15 15:40:05 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesGateway:
certAuthFilePath: "/my/ca.crt"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesGateway]
certAuthFilePath = "/my/ca.crt"
# ...
```
2020-12-15 15:40:05 +00:00
```bash tab="CLI"
--providers.kubernetesgateway.certauthfilepath=/my/ca.crt
```
### `namespaces`
2021-02-11 18:04:03 +00:00
_Optional, Default: []_
Array of namespaces to watch.
2022-08-01 08:10:07 +00:00
If left empty, Traefik watches all namespaces.
2020-12-15 15:40:05 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesGateway:
namespaces:
- "default"
- "production"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesGateway]
namespaces = ["default", "production"]
# ...
```
2020-12-15 15:40:05 +00:00
```bash tab="CLI"
--providers.kubernetesgateway.namespaces=default,production
```
### `labelselector`
2021-02-11 18:04:03 +00:00
_Optional, Default: ""_
A label selector can be defined to filter on specific GatewayClass objects only.
If left empty, Traefik processes all GatewayClass objects in the configured namespaces.
See [label-selectors ](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors ) for details.
2020-12-15 15:40:05 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesGateway:
labelselector: "app=traefik"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesGateway]
labelselector = "app=traefik"
# ...
```
2020-12-15 15:40:05 +00:00
```bash tab="CLI"
--providers.kubernetesgateway.labelselector="app=traefik"
```
2021-02-11 18:04:03 +00:00
### `throttleDuration`
2020-12-15 15:40:05 +00:00
2021-02-11 18:04:03 +00:00
_Optional, Default: 0_
2020-12-15 15:40:05 +00:00
2021-02-11 18:04:03 +00:00
The `throttleDuration` option defines how often the provider is allowed to handle events from Kubernetes. This prevents
a Kubernetes cluster that updates many times per second from continuously changing your Traefik configuration.
If left empty, the provider does not apply any throttling and does not drop any Kubernetes events.
2020-12-15 15:40:05 +00:00
2021-02-11 18:04:03 +00:00
The value of `throttleDuration` should be provided in seconds or as a valid duration format,
see [time.ParseDuration ](https://golang.org/pkg/time/#ParseDuration ).
2020-12-15 15:40:05 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesGateway:
throttleDuration: "10s"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesGateway]
throttleDuration = "10s"
# ...
```
2020-12-15 15:40:05 +00:00
```bash tab="CLI"
--providers.kubernetesgateway.throttleDuration=10s
```
2023-06-09 07:18:05 +00:00
2023-09-13 16:38:05 +00:00
{!traefik-for-business-applications.md!}