2022-04-15 13:44:08 +00:00
---
title: "Traefik Kubernetes Ingress Documentation"
description: "Understand the requirements, routing configuration, and how to set up Traefik Proxy as your Kubernetes Ingress Controller. Read the technical documentation."
---
2019-03-19 15:44:06 +00:00
# Traefik & Kubernetes
2019-07-19 07:50:04 +00:00
The Kubernetes Ingress Controller.
2019-03-19 15:44:06 +00:00
{: .subtitle }
2019-07-19 07:50:04 +00:00
The Traefik Kubernetes Ingress provider is a Kubernetes Ingress controller; that is to say,
2020-11-19 09:04:04 +00:00
it manages access to cluster services by supporting the [Ingress ](https://kubernetes.io/docs/concepts/services-networking/ingress/ ) specification.
2019-07-19 07:50:04 +00:00
2021-03-15 10:16:04 +00:00
## Requirements
Traefik supports `1.14+` Kubernetes clusters.
2020-01-14 14:48:06 +00:00
## Routing Configuration
See the dedicated section in [routing ](../routing/providers/kubernetes-ingress.md ).
## Enabling and Using the Provider
2019-07-19 07:50:04 +00:00
2021-02-11 18:04:03 +00:00
You can enable the provider in the static configuration:
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress: {}
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2019-07-22 07:58:04 +00:00
--providers.kubernetesingress=true
2019-07-19 07:50:04 +00:00
```
2020-01-14 14:48:06 +00:00
The provider then watches for incoming ingresses events, such as the example below,
and derives the corresponding dynamic configuration from it,
2021-02-11 18:04:03 +00:00
which in turn creates the resulting routers, services, handlers, etc.
2019-12-09 09:16:05 +00:00
2021-03-15 10:16:04 +00:00
```yaml tab="Ingress"
2021-10-21 07:44:12 +00:00
apiVersion: networking.k8s.io/v1
2019-07-19 07:50:04 +00:00
kind: Ingress
metadata:
2021-10-21 07:44:12 +00:00
name: foo
2019-07-19 07:50:04 +00:00
namespace: production
spec:
rules:
2020-03-13 21:50:05 +00:00
- host: example.net
2019-09-23 15:00:06 +00:00
http:
paths:
- path: /bar
2021-10-21 07:44:12 +00:00
pathType: Exact
2019-09-23 15:00:06 +00:00
backend:
2021-10-21 07:44:12 +00:00
service:
name: service1
port:
number: 80
2019-09-23 15:00:06 +00:00
- path: /foo
2021-10-21 07:44:12 +00:00
pathType: Exact
2019-09-23 15:00:06 +00:00
backend:
2021-10-21 07:44:12 +00:00
service:
name: service1
port:
number: 80
2019-07-19 07:50:04 +00:00
```
2021-10-21 07:44:12 +00:00
```yaml tab="Ingress v1beta1 (deprecated)"
apiVersion: networking.k8s.io/v1beta1
2021-03-15 10:16:04 +00:00
kind: Ingress
metadata:
2021-10-21 07:44:12 +00:00
name: foo
2021-03-15 10:16:04 +00:00
namespace: production
spec:
rules:
- host: example.net
http:
paths:
- path: /bar
backend:
2021-10-21 07:44:12 +00:00
serviceName: service1
servicePort: 80
2021-03-15 10:16:04 +00:00
- path: /foo
backend:
2021-10-21 07:44:12 +00:00
serviceName: service1
servicePort: 80
2021-03-15 10:16:04 +00:00
```
2019-12-09 09:16:05 +00:00
## LetsEncrypt Support with the Ingress Provider
2020-02-17 10:04:04 +00:00
By design, Traefik is a stateless application,
meaning that it only derives its configuration from the environment it runs in,
without additional configuration.
For this reason, users can run multiple instances of Traefik at the same time to achieve HA,
as is a common pattern in the kubernetes ecosystem.
2019-12-09 09:16:05 +00:00
2021-02-11 18:04:03 +00:00
When using a single instance of Traefik Proxy with Let's Encrypt, you should encounter no issues.
However, this could be a single point of failure.
Unfortunately, it is not possible to run multiple instances of Traefik 2.0 with Let's Encrypt enabled,
because there is no way to ensure that the correct instance of Traefik receives the challenge request, and subsequent responses.
2020-09-23 08:20:04 +00:00
Previous versions of Traefik used a [KV store ](https://doc.traefik.io/traefik/v1.7/configuration/acme/#storage ) to attempt to achieve this,
2021-02-11 18:04:03 +00:00
but due to sub-optimal performance that feature was dropped in 2.0.
2019-12-09 09:16:05 +00:00
2021-02-11 18:04:03 +00:00
If you need Let's Encrypt with high availability in a Kubernetes environment,
we recommend using [Traefik Enterprise ](https://traefik.io/traefik-enterprise/ ) which includes distributed Let's Encrypt as a supported feature.
2019-12-09 09:16:05 +00:00
2021-02-11 18:04:03 +00:00
If you want to keep using Traefik Proxy,
2021-11-03 16:38:07 +00:00
LetsEncrypt HA can be achieved by using a Certificate Controller such as [Cert-Manager ](https://cert-manager.io/docs/ ).
2020-02-17 10:04:04 +00:00
When using Cert-Manager to manage certificates,
2021-02-11 18:04:03 +00:00
it creates secrets in your namespaces that can be referenced as TLS secrets in your [ingress objects ](https://kubernetes.io/docs/concepts/services-networking/ingress/#tls ).
2019-12-09 09:16:05 +00:00
2019-09-23 12:32:04 +00:00
## Provider Configuration
2019-07-19 07:50:04 +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.
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
2020-09-23 09:38:03 +00:00
endpoint: "http://localhost:8080"
2019-07-19 07:50:04 +00:00
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
endpoint = "http://localhost:8080"
# ...
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2019-11-19 09:18:05 +00:00
--providers.kubernetesingress.endpoint=http://localhost:8080
2019-07-19 07:50:04 +00:00
```
### `token`
2021-02-11 18:04:03 +00:00
_Optional, Default=""_
Bearer token used for the Kubernetes client configuration.
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
2020-09-23 09:38:03 +00:00
token: "mytoken"
2019-07-19 07:50:04 +00:00
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
token = "mytoken"
# ...
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2019-11-19 09:18:05 +00:00
--providers.kubernetesingress.token=mytoken
2019-07-19 07:50:04 +00:00
```
### `certAuthFilePath`
2021-02-11 18:04:03 +00:00
_Optional, Default=""_
Path to the certificate authority file.
Used for the Kubernetes client configuration.
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
certAuthFilePath: "/my/ca.crt"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
certAuthFilePath = "/my/ca.crt"
# ...
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2019-11-19 09:18:05 +00:00
--providers.kubernetesingress.certauthfilepath=/my/ca.crt
2019-07-19 07:50:04 +00:00
```
### `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.
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
namespaces:
2019-09-23 15:00:06 +00:00
- "default"
- "production"
2019-07-19 07:50:04 +00:00
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
namespaces = ["default", "production"]
# ...
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2019-11-19 09:18:05 +00:00
--providers.kubernetesingress.namespaces=default,production
2019-07-19 07:50:04 +00:00
```
### `labelSelector`
2021-02-11 18:04:03 +00:00
_Optional, Default: ""_
A label selector can be defined to filter on specific Ingress objects only.
If left empty, Traefik processes all Ingress objects in the configured namespaces.
See [label-selectors ](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors ) for details.
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
2022-01-06 10:58:07 +00:00
labelSelector: "app=traefik"
2019-07-19 07:50:04 +00:00
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
labelSelector = "app=traefik"
# ...
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2020-11-19 23:18:04 +00:00
--providers.kubernetesingress.labelselector="app=traefik"
2019-07-19 07:50:04 +00:00
```
### `ingressClass`
2021-02-11 18:04:03 +00:00
_Optional, Default: ""_
2019-07-19 07:50:04 +00:00
Value of `kubernetes.io/ingress.class` annotation that identifies Ingress objects to be processed.
2021-02-11 18:04:03 +00:00
If the parameter is set, only Ingresses containing an annotation with the same value are processed.
Otherwise, Ingresses missing the annotation, having an empty value, or the value `traefik` are processed.
2019-07-19 07:50:04 +00:00
2021-03-15 10:16:04 +00:00
??? info "Kubernetes 1.18+"
2020-07-15 17:18:03 +00:00
2020-07-28 15:50:04 +00:00
If the Kubernetes cluster version is 1.18+,
the new `IngressClass` resource can be leveraged to identify Ingress objects that should be processed.
2021-03-04 08:24:03 +00:00
In that case, Traefik will look for an `IngressClass` in the cluster with the controller value equal to *traefik.io/ingress-controller* .
In addition to the controller value matching mechanism, the property `ingressClass` (if set) will be used to select IngressClasses by applying a strict matching on their name.
2021-02-11 18:04:03 +00:00
2020-09-01 08:18:03 +00:00
Please see [this article ](https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/ ) for more information or the example below.
```yaml tab="IngressClass"
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
2021-02-11 18:04:03 +00:00
metadata:
2020-09-01 08:18:03 +00:00
name: traefik-lb
2021-02-11 18:04:03 +00:00
spec:
2020-09-01 08:18:03 +00:00
controller: traefik.io/ingress-controller
```
2021-02-11 18:04:03 +00:00
2020-09-01 08:18:03 +00:00
```yaml tab="Ingress"
2021-10-21 07:44:12 +00:00
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
2020-09-01 08:18:03 +00:00
metadata:
2021-10-21 07:44:12 +00:00
name: example-ingress
2020-09-01 08:18:03 +00:00
spec:
2021-10-21 07:44:12 +00:00
ingressClassName: traefik-lb
2020-09-01 08:18:03 +00:00
rules:
- host: "*.example.com"
http:
paths:
2021-10-21 07:44:12 +00:00
- path: /example
2020-09-01 08:18:03 +00:00
backend:
2021-10-21 07:44:12 +00:00
serviceName: example-service
2020-09-01 08:18:03 +00:00
servicePort: 80
```
2020-07-15 17:18:03 +00:00
2021-03-15 10:16:04 +00:00
??? info "Kubernetes 1.19+"
If the Kubernetes cluster version is 1.19+,
prefer using the `networking.k8s.io/v1` [apiVersion ](https://v1-19.docs.kubernetes.io/docs/setup/release/notes/#api-change ) of `Ingress` and `IngressClass` .
```yaml tab="IngressClass"
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: traefik-lb
spec:
controller: traefik.io/ingress-controller
```
```yaml tab="Ingress"
2021-10-21 07:44:12 +00:00
apiVersion: networking.k8s.io/v1
kind: Ingress
2021-03-15 10:16:04 +00:00
metadata:
2021-10-21 07:44:12 +00:00
name: example-ingress
2021-03-15 10:16:04 +00:00
spec:
2021-10-21 07:44:12 +00:00
ingressClassName: traefik-lb
2021-03-15 10:16:04 +00:00
rules:
- host: "*.example.com"
http:
paths:
2021-10-21 07:44:12 +00:00
- path: /example
2021-09-02 08:20:12 +00:00
pathType: Exact
2021-03-15 10:16:04 +00:00
backend:
service:
2021-10-21 07:44:12 +00:00
name: example-service
2021-03-15 10:16:04 +00:00
port:
number: 80
```
2021-02-11 18:04:03 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
ingressClass: "traefik-internal"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
ingressClass = "traefik-internal"
# ...
```
2021-02-11 18:04:03 +00:00
```bash tab="CLI"
--providers.kubernetesingress.ingressclass=traefik-internal
```
2019-07-19 07:50:04 +00:00
### `ingressEndpoint`
#### `hostname`
2021-02-11 18:04:03 +00:00
_Optional, Default: ""_
Hostname used for Kubernetes Ingress endpoints.
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
ingressEndpoint:
2020-03-13 21:50:05 +00:00
hostname: "example.net"
2019-07-19 07:50:04 +00:00
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress.ingressEndpoint]
hostname = "example.net"
# ...
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2020-03-13 21:50:05 +00:00
--providers.kubernetesingress.ingressendpoint.hostname=example.net
2019-07-19 07:50:04 +00:00
```
#### `ip`
2021-02-11 18:04:03 +00:00
_Optional, Default: ""_
2022-09-29 08:14:08 +00:00
This IP will get copied to Ingress `status.loadbalancer.ip` , and currently only supports one IP value (IPv4 or IPv6).
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
ingressEndpoint:
ip: "1.2.3.4"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress.ingressEndpoint]
ip = "1.2.3.4"
# ...
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2019-11-19 09:18:05 +00:00
--providers.kubernetesingress.ingressendpoint.ip=1.2.3.4
2019-07-19 07:50:04 +00:00
```
#### `publishedService`
2021-02-11 18:04:03 +00:00
_Optional, Default: ""_
2022-09-29 08:14:08 +00:00
The Kubernetes service to copy status from.
When using third parties tools like External-DNS, this option can be used to copy the service `loadbalancer.status` (containing the service's endpoints IPs) to the ingresses.
2021-02-11 18:04:03 +00:00
Format: `namespace/servicename` .
2019-07-19 07:50:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
ingressEndpoint:
2020-02-17 16:30:06 +00:00
publishedService: "namespace/foo-service"
2019-07-19 07:50:04 +00:00
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress.ingressEndpoint]
publishedService = "namespace/foo-service"
# ...
```
2019-07-19 07:50:04 +00:00
```bash tab="CLI"
2020-02-17 16:30:06 +00:00
--providers.kubernetesingress.ingressendpoint.publishedservice=namespace/foo-service
2019-07-19 07:50:04 +00:00
```
2019-08-30 10:16:04 +00:00
### `throttleDuration`
2021-02-11 18:04:03 +00:00
_Optional, Default: 0_
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.
The value of `throttleDuration` should be provided in seconds or as a valid duration format,
see [time.ParseDuration ](https://golang.org/pkg/time/#ParseDuration ).
2019-08-30 10:16:04 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
throttleDuration: "10s"
# ...
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
throttleDuration = "10s"
# ...
```
2019-08-30 10:16:04 +00:00
```bash tab="CLI"
2019-11-19 09:18:05 +00:00
--providers.kubernetesingress.throttleDuration=10s
2019-08-30 10:16:04 +00:00
```
2021-05-06 16:12:10 +00:00
### `allowEmptyServices`
2022-03-07 10:08:07 +00:00
_Optional, Default: false_
If the parameter is set to `true` ,
it allows the creation of an empty [servers load balancer ](../routing/services/index.md#servers-load-balancer ) if the targeted Kubernetes service has no endpoints available.
This results in `503` HTTP responses instead of `404` ones.
2021-05-06 16:12:10 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
allowEmptyServices: true
# ...
```
2021-06-22 12:05:57 +00:00
```toml tab="File (TOML)"
[providers.kubernetesIngress]
allowEmptyServices = true
# ...
```
2021-05-06 16:12:10 +00:00
```bash tab="CLI"
--providers.kubernetesingress.allowEmptyServices=true
```
2021-07-13 10:54:09 +00:00
### `allowExternalNameServices`
_Optional, Default: false_
2022-03-07 10:08:07 +00:00
If the parameter is set to `true` ,
Ingresses are able to reference ExternalName services.
2021-07-13 10:54:09 +00:00
```yaml tab="File (YAML)"
providers:
kubernetesIngress:
allowExternalNameServices: true
# ...
```
```toml tab="File (TOML)"
[providers.kubernetesIngress]
allowExternalNameServices = true
# ...
```
```bash tab="CLI"
--providers.kubernetesingress.allowexternalnameservices=true
```
2020-01-14 14:48:06 +00:00
### Further
2019-07-19 07:50:04 +00:00
2021-02-11 18:04:03 +00:00
To learn more about the various aspects of the Ingress specification that Traefik supports,
2023-03-22 10:06:05 +00:00
many examples of Ingresses definitions are located in the test [examples ](https://github.com/traefik/traefik/tree/v2.10/pkg/provider/kubernetes/ingress/fixtures ) of the Traefik repository.
2022-07-05 08:02:09 +00:00
2022-09-09 15:17:53 +00:00
{!traefik-for-business-applications.md!}