2022-04-15 13:44:08 +00:00
---
title: "Routing Configuration for Traefik CRD"
description: "Understand the routing configuration for the Kubernetes IngressRoute & Traefik CRD. Read the technical documentation."
---
2019-09-23 12:32:04 +00:00
# Traefik & Kubernetes
The Kubernetes Ingress Controller, The Custom Resource Way.
{: .subtitle }
2020-01-07 10:26:05 +00:00
## Configuration Examples
??? example "Configuring KubernetesCRD and Deploying/Exposing Services"
```yaml tab="Resource Definition"
# All resources definition must be declared
2021-03-03 14:32:04 +00:00
--8< -- " content / reference / dynamic-configuration / kubernetes-crd-definition-v1 . yml "
2020-01-07 10:26:05 +00:00
```
```yaml tab="RBAC"
--8< -- " content / reference / dynamic-configuration / kubernetes-crd-rbac . yml "
```
```yaml tab="Traefik"
apiVersion: v1
kind: ServiceAccount
metadata:
name: traefik-ingress-controller
---
kind: Deployment
2020-01-16 09:14:06 +00:00
apiVersion: apps/v1
2020-01-07 10:26:05 +00:00
metadata:
name: traefik
labels:
app: traefik
spec:
replicas: 1
selector:
matchLabels:
app: traefik
template:
metadata:
labels:
app: traefik
spec:
serviceAccountName: traefik-ingress-controller
containers:
- name: traefik
2021-12-20 16:02:06 +00:00
image: traefik:v2.6
2020-01-07 10:26:05 +00:00
args:
- --log.level=DEBUG
- --api
- --api.insecure
- --entrypoints.web.address=:80
2020-02-26 11:28:05 +00:00
- --entrypoints.tcpep.address=:8000
- --entrypoints.udpep.address=:9000/udp
2020-01-07 10:26:05 +00:00
- --providers.kubernetescrd
ports:
- name: web
containerPort: 80
- name: admin
containerPort: 8080
2020-02-26 11:28:05 +00:00
- name: tcpep
containerPort: 8000
- name: udpep
containerPort: 9000
2020-01-07 10:26:05 +00:00
---
apiVersion: v1
kind: Service
metadata:
name: traefik
spec:
type: LoadBalancer
selector:
app: traefik
ports:
- protocol: TCP
port: 80
name: web
targetPort: 80
- protocol: TCP
port: 8080
name: admin
targetPort: 8080
2020-02-26 11:28:05 +00:00
- protocol: TCP
port: 8000
name: tcpep
targetPort: 8000
---
apiVersion: v1
kind: Service
metadata:
name: traefikudp
spec:
type: LoadBalancer
selector:
app: traefik
ports:
- protocol: UDP
port: 9000
name: udpep
targetPort: 9000
2020-01-07 10:26:05 +00:00
```
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: myingressroute
namespace: default
2020-08-03 15:40:07 +00:00
spec:
entryPoints:
- web
routes:
- match: Host(`foo`) && PathPrefix(`/bar`)
kind: Rule
services:
- name: whoami
port: 80
2020-02-26 11:28:05 +00:00
---
apiVersion: traefik.containo.us/v1alpha1
2020-06-03 15:24:04 +00:00
kind: IngressRouteTCP
metadata:
name: ingressroute.tcp
2020-02-26 11:28:05 +00:00
namespace: default
2020-06-03 15:24:04 +00:00
2020-08-03 15:40:07 +00:00
spec:
entryPoints:
- tcpep
routes:
- match: HostSNI(`bar`)
services:
- name: whoamitcp
port: 8080
2020-06-03 15:24:04 +00:00
2020-02-26 11:28:05 +00:00
---
apiVersion: traefik.containo.us/v1alpha1
2020-06-03 15:24:04 +00:00
kind: IngressRouteUDP
metadata:
name: ingressroute.udp
namespace: default
2020-08-03 15:40:07 +00:00
spec:
entryPoints:
2021-01-15 14:54:04 +00:00
- udpep
2020-08-03 15:40:07 +00:00
routes:
2021-10-26 10:08:12 +00:00
- services:
2020-08-03 15:40:07 +00:00
- name: whoamiudp
port: 8080
2020-01-07 10:26:05 +00:00
```
2020-02-26 11:28:05 +00:00
2020-01-07 10:26:05 +00:00
```yaml tab="Whoami"
kind: Deployment
2020-01-16 09:14:06 +00:00
apiVersion: apps/v1
2020-01-07 10:26:05 +00:00
metadata:
name: whoami
namespace: default
labels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
name: whoami
spec:
replicas: 2
selector:
matchLabels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: whoami
template:
metadata:
labels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: whoami
spec:
containers:
2020-09-16 13:46:04 +00:00
- name: whoami
image: traefik/whoami
2020-01-07 10:26:05 +00:00
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: whoami
namespace: default
spec:
ports:
- name: http
port: 80
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: whoami
2020-02-26 11:28:05 +00:00
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: whoamitcp
namespace: default
labels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-02-26 11:28:05 +00:00
name: whoamitcp
spec:
replicas: 2
selector:
matchLabels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-02-26 11:28:05 +00:00
task: whoamitcp
template:
metadata:
labels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-02-26 11:28:05 +00:00
task: whoamitcp
spec:
containers:
2020-09-16 13:46:04 +00:00
- name: whoamitcp
image: traefik/whoamitcp
2020-02-26 11:28:05 +00:00
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: whoamitcp
namespace: default
spec:
ports:
- protocol: TCP
port: 8080
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-02-26 11:28:05 +00:00
task: whoamitcp
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: whoamiudp
namespace: default
labels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-02-26 11:28:05 +00:00
name: whoamiudp
spec:
replicas: 2
selector:
matchLabels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-02-26 11:28:05 +00:00
task: whoamiudp
template:
metadata:
labels:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-02-26 11:28:05 +00:00
task: whoamiudp
spec:
containers:
2020-09-16 13:46:04 +00:00
- name: whoamiudp
image: traefik/whoamiudp:latest
2020-02-26 11:28:05 +00:00
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: whoamiudp
namespace: default
spec:
ports:
- port: 8080
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-02-26 11:28:05 +00:00
task: whoamiudp
2020-01-07 10:26:05 +00:00
```
## Routing Configuration
### Custom Resource Definition (CRD)
* You can find an exhaustive list, generated from Traefik's source code, of the custom resources and their attributes in [the reference page ](../../reference/dynamic-configuration/kubernetes-crd.md ).
* Validate that [the prerequisites ](../../providers/kubernetes-crd.md#configuration-requirements ) are fulfilled before using the Traefik custom resources.
* Traefik CRDs are building blocks that you can assemble according to your needs.
You can find an excerpt of the available custom resources in the table below:
2021-03-03 15:48:04 +00:00
| Kind | Purpose | Concept Behind |
|--------------------------------------------|--------------------------------------------------------------------|----------------------------------------------------------------|
| [IngressRoute ](#kind-ingressroute ) | HTTP Routing | [HTTP router ](../routers/index.md#configuring-http-routers ) |
2021-08-19 15:00:14 +00:00
| [Middleware ](#kind-middleware ) | Tweaks the HTTP requests before they are sent to your service | [HTTP Middlewares ](../../middlewares/http/overview.md ) |
2021-03-03 15:48:04 +00:00
| [TraefikService ](#kind-traefikservice ) | Abstraction for HTTP loadbalancing/mirroring | [HTTP service ](../services/index.md#configuring-http-services ) |
| [IngressRouteTCP ](#kind-ingressroutetcp ) | TCP Routing | [TCP router ](../routers/index.md#configuring-tcp-routers ) |
2021-08-19 15:00:14 +00:00
| [MiddlewareTCP ](#kind-middlewaretcp ) | Tweaks the TCP requests before they are sent to your service | [TCP Middlewares ](../../middlewares/tcp/overview.md ) |
2021-03-03 15:48:04 +00:00
| [IngressRouteUDP ](#kind-ingressrouteudp ) | UDP Routing | [UDP router ](../routers/index.md#configuring-udp-routers ) |
| [TLSOptions ](#kind-tlsoption ) | Allows to configure some parameters of the TLS connection | [TLSOptions ](../../https/tls.md#tls-options ) |
| [TLSStores ](#kind-tlsstore ) | Allows to configure the default TLS store | [TLSStores ](../../https/tls.md#certificates-stores ) |
| [ServersTransport ](#kind-serverstransport ) | Allows to configure the transport between Traefik and the backends | [ServersTransport ](../../services/#serverstransport_1 ) |
2020-01-07 10:26:05 +00:00
### Kind: `IngressRoute`
`IngressRoute` is the CRD implementation of a [Traefik HTTP router ](../routers/index.md#configuring-http-routers ).
2020-02-26 11:28:05 +00:00
Register the `IngressRoute` [kind ](../../reference/dynamic-configuration/kubernetes-crd.md#definitions ) in the Kubernetes cluster before creating `IngressRoute` objects.
2020-01-07 10:26:05 +00:00
!!! info "IngressRoute Attributes"
```yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: foo
namespace: bar
spec:
entryPoints: # [1]
- foo
routes: # [2]
- kind: Rule
2020-03-13 21:50:05 +00:00
match: Host(`test.example.com`) # [3]
2020-01-07 10:26:05 +00:00
priority: 10 # [4]
middlewares: # [5]
- name: middleware1 # [6]
namespace: default # [7]
services: # [8]
- kind: Service
name: foo
namespace: default
passHostHeader: true
2021-01-15 14:54:04 +00:00
port: 80 # [9]
2020-01-07 10:26:05 +00:00
responseForwarding:
flushInterval: 1ms
scheme: https
2021-09-16 13:12:13 +00:00
serversTransport: transport # [10]
2020-01-07 10:26:05 +00:00
sticky:
cookie:
httpOnly: true
name: cookie
secure: true
2020-03-23 10:24:05 +00:00
sameSite: none
2020-01-07 10:26:05 +00:00
strategy: RoundRobin
weight: 10
2021-09-16 13:12:13 +00:00
tls: # [11]
secretName: supersecret # [12]
options: # [13]
name: opt # [14]
namespace: default # [15]
certResolver: foo # [16]
domains: # [17]
- main: example.net # [18]
sans: # [19]
2020-03-13 21:50:05 +00:00
- a.example.net
- b.example.net
2020-01-07 10:26:05 +00:00
```
2021-09-16 13:12:13 +00:00
| Ref | Attribute | Purpose |
|------|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [1] | `entryPoints` | List of [entry points ](../routers/index.md#entrypoints ) names |
| [2] | `routes` | List of routes |
| [3] | `routes[n].match` | Defines the [rule ](../routers/index.md#rule ) corresponding to an underlying router. |
| [4] | `routes[n].priority` | [Disambiguate ](../routers/index.md#priority ) rules of the same length, for route matching |
| [5] | `routes[n].middlewares` | List of reference to [Middleware ](#kind-middleware ) |
| [6] | `middlewares[n].name` | Defines the [Middleware ](#kind-middleware ) name |
| [7] | `middlewares[n].namespace` | Defines the [Middleware ](#kind-middleware ) namespace |
| [8] | `routes[n].services` | List of any combination of [TraefikService ](#kind-traefikservice ) and reference to a [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ) (See below for `ExternalName Service` setup) |
| [9] | `services[n].port` | Defines the port of a [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ). This can be a reference to a named port. |
| [10] | `services[n].serversTransport` | Defines the reference to a [ServersTransport ](#kind-serverstransport ). The ServersTransport namespace is assumed to be the [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ) namespace (see [ServersTransport reference ](#serverstransport-reference )). |
| [11] | `tls` | Defines [TLS ](../routers/index.md#tls ) certificate configuration |
| [12] | `tls.secretName` | Defines the [secret ](https://kubernetes.io/docs/concepts/configuration/secret/ ) name used to store the certificate (in the `IngressRoute` namespace) |
| [13] | `tls.options` | Defines the reference to a [TLSOption ](#kind-tlsoption ) |
| [14] | `options.name` | Defines the [TLSOption ](#kind-tlsoption ) name |
| [15] | `options.namespace` | Defines the [TLSOption ](#kind-tlsoption ) namespace |
| [16] | `tls.certResolver` | Defines the reference to a [CertResolver ](../routers/index.md#certresolver ) |
| [17] | `tls.domains` | List of [domains ](../routers/index.md#domains ) |
| [18] | `domains[n].main` | Defines the main domain name |
| [19] | `domains[n].sans` | List of SANs (alternative domains) |
2020-01-07 10:26:05 +00:00
??? example "Declaring an IngressRoute"
```yaml tab="IngressRoute"
# All resources definition must be declared
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
2021-06-24 09:28:05 +00:00
name: test-name
2020-01-07 10:26:05 +00:00
namespace: default
spec:
entryPoints:
- web
routes:
- kind: Rule
2020-03-13 21:50:05 +00:00
match: Host(`test.example.com`)
2020-01-07 10:26:05 +00:00
middlewares:
- name: middleware1
namespace: default
priority: 10
services:
- kind: Service
name: foo
namespace: default
passHostHeader: true
port: 80
responseForwarding:
flushInterval: 1ms
scheme: https
sticky:
cookie:
httpOnly: true
name: cookie
secure: true
strategy: RoundRobin
weight: 10
tls:
certResolver: foo
domains:
2020-03-13 21:50:05 +00:00
- main: example.net
2020-01-07 10:26:05 +00:00
sans:
2020-03-13 21:50:05 +00:00
- a.example.net
- b.example.net
2020-01-07 10:26:05 +00:00
options:
name: opt
namespace: default
secretName: supersecret
```
```yaml tab="Middlewares"
# All resources definition must be declared
# Prefixing with /foo
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: middleware1
namespace: default
spec:
addPrefix:
prefix: /foo
```
```yaml tab="TLSOption"
apiVersion: traefik.containo.us/v1alpha1
kind: TLSOption
metadata:
name: opt
namespace: default
spec:
minVersion: VersionTLS12
```
```yaml tab="Secret"
apiVersion: v1
kind: Secret
metadata:
name: supersecret
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
tls.key: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0=
```
2020-02-25 09:12:04 +00:00
!!! important "Configuring Backend Protocol"
There are 3 ways to configure the backend protocol for communication between Traefik and your pods:
- Setting the scheme explicitly (http/https/h2c)
- Configuring the name of the kubernetes service port to start with https (https)
- Setting the kubernetes service port to use port 443 (https)
If you do not configure the above, Traefik will assume an http connection.
2020-03-10 11:46:05 +00:00
!!! important "Using Kubernetes ExternalName Service"
2021-09-21 14:28:11 +00:00
Traefik backends creation needs a port to be set, however Kubernetes [ExternalName Service ](https://kubernetes.io/docs/concepts/services-networking/service/#externalname ) could be defined without any port.
2020-03-10 11:46:05 +00:00
Accordingly, Traefik supports defining a port in two ways:
- only on `IngressRoute` service
- on both sides, you'll be warned if the ports don't match, and the `IngressRoute` service port is used
Thus, in case of two sides port definition, Traefik expects a match between ports.
??? example "Examples"
```yaml tab="IngressRoute"
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.net`)
2020-03-10 11:46:05 +00:00
kind: Rule
services:
- name: external-svc
port: 80
---
apiVersion: v1
kind: Service
metadata:
name: external-svc
namespace: default
spec:
externalName: external.domain
type: ExternalName
```
```yaml tab="ExternalName Service"
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.net`)
2020-03-10 11:46:05 +00:00
kind: Rule
services:
- name: external-svc
---
apiVersion: v1
kind: Service
metadata:
name: external-svc
namespace: default
spec:
externalName: external.domain
type: ExternalName
ports:
- port: 80
```
```yaml tab="Both sides"
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.net`)
2020-03-10 11:46:05 +00:00
kind: Rule
services:
- name: external-svc
port: 80
---
apiVersion: v1
kind: Service
metadata:
name: external-svc
namespace: default
spec:
externalName: external.domain
type: ExternalName
ports:
- port: 80
```
2020-02-25 09:12:04 +00:00
2020-01-07 10:26:05 +00:00
### Kind: `Middleware`
2021-08-19 15:00:14 +00:00
`Middleware` is the CRD implementation of a [Traefik middleware ](../../middlewares/http/overview.md ).
2020-01-07 10:26:05 +00:00
2020-02-26 11:28:05 +00:00
Register the `Middleware` [kind ](../../reference/dynamic-configuration/kubernetes-crd.md#definitions ) in the Kubernetes cluster before creating `Middleware` objects or referencing middlewares in the [`IngressRoute` ](#kind-ingressroute ) objects.
2020-01-07 10:26:05 +00:00
??? "Declaring and Referencing a Middleware"
```yaml tab="Middleware"
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: stripprefix
2019-09-23 12:32:04 +00:00
namespace: foo
2020-01-07 10:26:05 +00:00
spec:
stripPrefix:
prefixes:
- /stripit
```
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutebar
spec:
entryPoints:
- web
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.com`) && PathPrefix(`/stripit`)
2020-01-07 10:26:05 +00:00
kind: Rule
services:
- name: whoami
port: 80
middlewares:
- name: stripprefix
namespace: foo
```
2019-09-23 12:32:04 +00:00
!!! important "Cross-provider namespace"
2020-04-27 09:32:05 +00:00
As Kubernetes also has its own notion of namespace, one should not confuse the kubernetes namespace of a resource
2020-10-27 11:46:04 +00:00
(in the reference to the middleware) with the [provider namespace ](../../providers/overview.md#provider-namespace ),
2020-04-27 09:32:05 +00:00
when the definition of the middleware comes from another provider.
In this context, specifying a namespace when referring to the resource does not make any sense, and will be ignored.
Additionally, when you want to reference a Middleware from the CRD Provider,
you have to append the namespace of the resource in the resource-name as Traefik appends the namespace internally automatically.
2019-09-23 12:32:04 +00:00
2021-08-19 15:00:14 +00:00
More information about available middlewares in the dedicated [middlewares section ](../../middlewares/http/overview.md ).
2019-09-23 12:32:04 +00:00
2020-01-07 10:26:05 +00:00
### Kind: `TraefikService`
`TraefikService` is the CRD implementation of a ["Traefik Service" ](../services/index.md ).
2020-02-26 11:28:05 +00:00
Register the `TraefikService` [kind ](../../reference/dynamic-configuration/kubernetes-crd.md#definitions ) in the Kubernetes cluster before creating `TraefikService` objects,
referencing services in the [`IngressRoute` ](#kind-ingressroute ) objects, or recursively in others `TraefikService` objects.
2020-01-07 10:26:05 +00:00
!!! info "Disambiguate Traefik and Kubernetes Services "
As the field `name` can reference different types of objects, use the field `kind` to avoid any ambiguity.
The field `kind` allows the following values:
* `Service` (default value): to reference a [Kubernetes Service ](https://kubernetes.io/docs/concepts/services-networking/service/ )
* `TraefikService` : to reference another [Traefik Service ](../services/index.md )
`TraefikService` object allows to use any (valid) combinations of:
* servers [load balancing ](#server-load-balancing ).
* services [Weighted Round Robin ](#weighted-round-robin ) load balancing.
* services [mirroring ](#mirroring ).
2019-11-14 18:28:04 +00:00
2020-01-07 10:26:05 +00:00
#### Server Load Balancing
More information in the dedicated server [load balancing ](../services/index.md#load-balancing ) section.
??? "Declaring and Using Server Load Balancing"
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutebar
namespace: default
spec:
entryPoints:
- web
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.com`) && PathPrefix(`/foo`)
2020-01-07 10:26:05 +00:00
kind: Rule
services:
- name: svc1
namespace: default
- name: svc2
namespace: default
```
```yaml tab="K8s Service"
apiVersion: v1
kind: Service
metadata:
name: svc1
namespace: default
spec:
ports:
- name: http
port: 80
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: app1
---
apiVersion: v1
kind: Service
metadata:
name: svc2
namespace: default
spec:
ports:
- name: http
port: 80
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: app2
```
#### Weighted Round Robin
More information in the dedicated [Weighted Round Robin ](../services/index.md#weighted-round-robin-service ) service load balancing section.
??? "Declaring and Using Weighted Round Robin"
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutebar
namespace: default
spec:
entryPoints:
- web
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.com`) && PathPrefix(`/foo`)
2020-01-07 10:26:05 +00:00
kind: Rule
services:
- name: wrr1
namespace: default
kind: TraefikService
```
```yaml tab="Weighted Round Robin"
apiVersion: traefik.containo.us/v1alpha1
2019-11-14 18:28:04 +00:00
kind: TraefikService
2020-01-07 10:26:05 +00:00
metadata:
name: wrr1
namespace: default
spec:
weighted:
services:
- name: svc1
port: 80
weight: 1
- name: wrr2
kind: TraefikService
weight: 1
- name: mirror1
kind: TraefikService
weight: 1
---
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
name: wrr2
namespace: default
spec:
weighted:
services:
- name: svc2
port: 80
weight: 1
- name: svc3
port: 80
weight: 1
```
```yaml tab="K8s Service"
apiVersion: v1
kind: Service
metadata:
name: svc1
namespace: default
spec:
ports:
- name: http
port: 80
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: app1
---
apiVersion: v1
kind: Service
metadata:
name: svc2
namespace: default
spec:
ports:
- name: http
port: 80
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: app2
---
apiVersion: v1
kind: Service
metadata:
name: svc3
namespace: default
spec:
ports:
- name: http
port: 80
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: app3
```
#### Mirroring
More information in the dedicated [mirroring ](../services/index.md#mirroring-service ) service section.
??? "Declaring and Using Mirroring"
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutebar
namespace: default
spec:
entryPoints:
- web
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.com`) && PathPrefix(`/foo`)
2020-01-07 10:26:05 +00:00
kind: Rule
services:
- name: mirror1
namespace: default
kind: TraefikService
```
```yaml tab="Mirroring k8s Service"
# Mirroring from a k8s Service
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
name: mirror1
namespace: default
spec:
mirroring:
name: svc1
2019-11-14 18:28:04 +00:00
port: 80
2020-01-07 10:26:05 +00:00
mirrors:
- name: svc2
port: 80
percent: 20
- name: svc3
kind: TraefikService
percent: 20
```
```yaml tab="Mirroring Traefik Service"
# Mirroring from a Traefik Service
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
name: mirror1
2019-11-14 18:28:04 +00:00
namespace: default
2020-01-07 10:26:05 +00:00
spec:
mirroring:
name: wrr1
kind: TraefikService
mirrors:
- name: svc2
port: 80
percent: 20
- name: svc3
kind: TraefikService
percent: 20
```
```yaml tab="K8s Service"
apiVersion: v1
kind: Service
metadata:
name: svc1
namespace: default
spec:
ports:
- name: http
port: 80
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: app1
---
apiVersion: v1
kind: Service
metadata:
name: svc2
namespace: default
spec:
ports:
- name: http
port: 80
selector:
2020-09-16 13:46:04 +00:00
app: traefiklabs
2020-01-07 10:26:05 +00:00
task: app2
```
2019-11-14 18:28:04 +00:00
!!! important "References and namespaces"
If the optional `namespace` attribute is not set, the configuration will be applied with the namespace of the current resource.
Additionally, when the definition of the `TraefikService` is from another provider,
2020-01-07 10:26:05 +00:00
the cross-provider syntax (`service@provider`) should be used to refer to the `TraefikService` , just as in the middleware case.
2019-11-14 18:28:04 +00:00
Specifying a namespace attribute in this case would not make any sense, and will be ignored (except if the provider is `kubernetescrd` ).
2020-03-17 11:34:04 +00:00
#### Stickiness and load-balancing
As explained in the section about [Sticky sessions ](../../services/#sticky-sessions ), for stickiness to work all the way,
it must be specified at each load-balancing level.
For instance, in the example below, there is a first level of load-balancing because there is a (Weighted Round Robin) load-balancing of the two `whoami` services,
and there is a second level because each whoami service is a `replicaset` and is thus handled as a load-balancer of servers.
??? "Stickiness on two load-balancing levels"
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutebar
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`example.com`) && PathPrefix(`/foo`)
kind: Rule
services:
- name: wrr1
namespace: default
kind: TraefikService
```
```yaml tab="Weighted Round Robin"
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
name: wrr1
namespace: default
spec:
weighted:
services:
- name: whoami1
kind: Service
port: 80
weight: 1
sticky:
cookie:
name: lvl2
- name: whoami2
kind: Service
weight: 1
port: 80
sticky:
cookie:
name: lvl2
sticky:
cookie:
name: lvl1
```
```yaml tab="K8s Service"
apiVersion: v1
kind: Service
metadata:
name: whoami1
spec:
ports:
- protocol: TCP
name: web
port: 80
selector:
app: whoami1
---
apiVersion: v1
kind: Service
metadata:
name: whoami2
spec:
ports:
- protocol: TCP
name: web
port: 80
selector:
app: whoami2
```
```yaml tab="Deployment (to illustrate replicas)"
kind: Deployment
apiVersion: apps/v1
metadata:
namespace: default
name: whoami1
labels:
app: whoami1
spec:
replicas: 2
selector:
matchLabels:
app: whoami1
template:
metadata:
labels:
app: whoami1
spec:
containers:
- name: whoami1
2020-09-16 13:46:04 +00:00
image: traefik/whoami
2020-03-17 11:34:04 +00:00
ports:
- name: web
containerPort: 80
---
kind: Deployment
apiVersion: apps/v1
metadata:
namespace: default
name: whoami2
labels:
app: whoami2
spec:
replicas: 2
selector:
matchLabels:
app: whoami2
template:
metadata:
labels:
app: whoami2
spec:
containers:
- name: whoami2
2020-09-16 13:46:04 +00:00
image: traefik/whoami
2020-03-17 11:34:04 +00:00
ports:
- name: web
containerPort: 80
```
To keep a session open with the same server, the client would then need to specify the two levels within the cookie for each request, e.g. with curl:
```bash
curl -H Host:example.com -b "lvl1=default-whoami1-80; lvl2=http://10.42.0.6:80" http://localhost:8000/foo
```
assuming `10.42.0.6` is the IP address of one of the replicas (a pod then) of the `whoami1` service.
2020-01-07 10:26:05 +00:00
### Kind `IngressRouteTCP`
`IngressRouteTCP` is the CRD implementation of a [Traefik TCP router ](../routers/index.md#configuring-tcp-routers ).
2020-02-26 11:28:05 +00:00
Register the `IngressRouteTCP` [kind ](../../reference/dynamic-configuration/kubernetes-crd.md#definitions ) in the Kubernetes cluster before creating `IngressRouteTCP` objects.
2020-01-07 10:26:05 +00:00
!!! info "IngressRouteTCP Attributes"
```yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: ingressroutetcpfoo
spec:
entryPoints: # [1]
- footcp
routes: # [2]
- match: HostSNI(`*`) # [3]
2021-08-19 15:00:14 +00:00
middlewares:
- name: middleware1 # [4]
namespace: default # [5]
services: # [6]
- name: foo # [7]
port: 8080 # [8]
weight: 10 # [9]
terminationDelay: 400 # [10]
proxyProtocol: # [11]
version: 1 # [12]
tls: # [13]
secretName: supersecret # [14]
options: # [15]
name: opt # [16]
namespace: default # [17]
certResolver: foo # [18]
domains: # [19]
- main: example.net # [20]
sans: # [21]
2020-03-13 21:50:05 +00:00
- a.example.net
- b.example.net
2021-08-19 15:00:14 +00:00
passthrough: false # [22]
2020-01-07 10:26:05 +00:00
```
2020-11-17 12:04:04 +00:00
| Ref | Attribute | Purpose |
|------|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [1] | `entryPoints` | List of [entrypoints ](../routers/index.md#entrypoints_1 ) names |
| [2] | `routes` | List of routes |
| [3] | `routes[n].match` | Defines the [rule ](../routers/index.md#rule_1 ) corresponding to an underlying router |
2021-08-19 15:00:14 +00:00
| [4] | `middlewares[n].name` | Defines the [MiddlewareTCP ](#kind-middlewaretcp ) name |
| [5] | `middlewares[n].namespace` | Defines the [MiddlewareTCP ](#kind-middlewaretcp ) namespace |
| [6] | `routes[n].services` | List of [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ) definitions (See below for `ExternalName Service` setup) |
| [7] | `services[n].name` | Defines the name of a [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ) |
| [8] | `services[n].port` | Defines the port of a [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ). This can be a reference to a named port. |
| [9] | `services[n].weight` | Defines the weight to apply to the server load balancing |
| [10] | `services[n].terminationDelay` | corresponds to the deadline that the proxy sets, after one of its connected peers indicates it has closed the writing capability of its connection, to close the reading capability as well, hence fully terminating the connection. It is a duration in milliseconds, defaulting to 100. A negative value means an infinite deadline (i.e. the reading capability is never closed). |
| [11] | `proxyProtocol` | Defines the [PROXY protocol ](../services/index.md#proxy-protocol ) configuration |
| [12] | `version` | Defines the [PROXY protocol ](../services/index.md#proxy-protocol ) version |
| [13] | `tls` | Defines [TLS ](../routers/index.md#tls_1 ) certificate configuration |
| [14] | `tls.secretName` | Defines the [secret ](https://kubernetes.io/docs/concepts/configuration/secret/ ) name used to store the certificate (in the `IngressRoute` namespace) |
| [15] | `tls.options` | Defines the reference to a [TLSOption ](#kind-tlsoption ) |
| [16] | `options.name` | Defines the [TLSOption ](#kind-tlsoption ) name |
| [17] | `options.namespace` | Defines the [TLSOption ](#kind-tlsoption ) namespace |
| [18] | `tls.certResolver` | Defines the reference to a [CertResolver ](../routers/index.md#certresolver_1 ) |
| [19] | `tls.domains` | List of [domains ](../routers/index.md#domains_1 ) |
| [20] | `domains[n].main` | Defines the main domain name |
| [21] | `domains[n].sans` | List of SANs (alternative domains) |
| [22] | `tls.passthrough` | If `true` , delegates the TLS termination to the backend |
2020-01-07 10:26:05 +00:00
??? example "Declaring an IngressRouteTCP"
```yaml tab="IngressRouteTCP"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: ingressroutetcpfoo
spec:
entryPoints:
- footcp
routes:
# Match is the rule corresponding to an underlying router.
- match: HostSNI(`*`)
services:
- name: foo
port: 8080
2020-03-23 10:48:04 +00:00
terminationDelay: 400
2020-01-07 10:26:05 +00:00
weight: 10
- name: bar
port: 8081
2020-03-23 10:48:04 +00:00
terminationDelay: 500
2020-01-07 10:26:05 +00:00
weight: 10
tls:
certResolver: foo
domains:
2020-03-13 21:50:05 +00:00
- main: example.net
2020-01-07 10:26:05 +00:00
sans:
2020-03-13 21:50:05 +00:00
- a.example.net
- b.example.net
2020-01-07 10:26:05 +00:00
options:
name: opt
namespace: default
secretName: supersecret
passthrough: false
```
```yaml tab="TLSOption"
apiVersion: traefik.containo.us/v1alpha1
kind: TLSOption
metadata:
name: opt
2019-09-23 12:32:04 +00:00
namespace: default
2020-01-07 10:26:05 +00:00
spec:
minVersion: VersionTLS12
```
```yaml tab="Secret"
apiVersion: v1
kind: Secret
metadata:
name: supersecret
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
tls.key: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0=
```
2020-03-10 11:46:05 +00:00
!!! important "Using Kubernetes ExternalName Service"
2021-09-21 14:28:11 +00:00
Traefik backends creation needs a port to be set, however Kubernetes [ExternalName Service ](https://kubernetes.io/docs/concepts/services-networking/service/#externalname ) could be defined without any port.
2020-03-10 11:46:05 +00:00
Accordingly, Traefik supports defining a port in two ways:
- only on `IngressRouteTCP` service
- on both sides, you'll be warned if the ports don't match, and the `IngressRouteTCP` service port is used
Thus, in case of two sides port definition, Traefik expects a match between ports.
??? example "Examples"
2021-05-06 10:04:08 +00:00
```yaml tab="Only on IngressRouteTCP"
2020-03-10 11:46:05 +00:00
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
- match: HostSNI(`*`)
services:
- name: external-svc
port: 80
---
apiVersion: v1
kind: Service
metadata:
name: external-svc
namespace: default
spec:
externalName: external.domain
type: ExternalName
```
2021-05-06 10:04:08 +00:00
```yaml tab="On both sides"
2020-03-10 11:46:05 +00:00
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
- match: HostSNI(`*`)
services:
- name: external-svc
port: 80
---
apiVersion: v1
kind: Service
metadata:
name: external-svc
namespace: default
spec:
externalName: external.domain
type: ExternalName
ports:
- port: 80
```
2021-08-19 15:00:14 +00:00
### Kind: `MiddlewareTCP`
`MiddlewareTCP` is the CRD implementation of a [Traefik TCP middleware ](../../middlewares/tcp/overview.md ).
Register the `MiddlewareTCP` [kind ](../../reference/dynamic-configuration/kubernetes-crd.md#definitions ) in the Kubernetes cluster before creating `MiddlewareTCP` objects or referencing TCP middlewares in the [`IngressRouteTCP` ](#kind-ingressroutetcp ) objects.
??? "Declaring and Referencing a MiddlewareTCP "
```yaml tab="Middleware"
apiVersion: traefik.containo.us/v1alpha1
kind: MiddlewareTCP
metadata:
name: ipwhitelist
spec:
ipWhiteList:
sourceRange:
- 127.0.0.1/32
- 192.168.1.7
```
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutebar
spec:
entryPoints:
- web
routes:
- match: Host(`example.com`) && PathPrefix(`/whitelist`)
kind: Rule
services:
- name: whoami
port: 80
middlewares:
- name: ipwhitelist
namespace: foo
```
!!! important "Cross-provider namespace"
As Kubernetes also has its own notion of namespace, one should not confuse the kubernetes namespace of a resource
(in the reference to the middleware) with the [provider namespace ](../../providers/overview.md#provider-namespace ),
when the definition of the TCP middleware comes from another provider.
In this context, specifying a namespace when referring to the resource does not make any sense, and will be ignored.
Additionally, when you want to reference a MiddlewareTCP from the CRD Provider,
you have to append the namespace of the resource in the resource-name as Traefik appends the namespace internally automatically.
More information about available TCP middlewares in the dedicated [middlewares section ](../../middlewares/tcp/overview.md ).
2020-02-26 11:28:05 +00:00
### Kind `IngressRouteUDP`
`IngressRouteUDP` is the CRD implementation of a [Traefik UDP router ](../routers/index.md#configuring-udp-routers ).
Register the `IngressRouteUDP` [kind ](../../reference/dynamic-configuration/kubernetes-crd.md#definitions ) in the Kubernetes cluster before creating `IngressRouteUDP` objects.
!!! info "IngressRouteUDP Attributes"
```yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteUDP
metadata:
name: ingressrouteudpfoo
spec:
entryPoints: # [1]
- fooudp
routes: # [2]
- services: # [3]
- name: foo # [4]
port: 8080 # [5]
weight: 10 # [6]
```
| Ref | Attribute | Purpose |
|------|--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [1] | `entryPoints` | List of [entrypoints ](../routers/index.md#entrypoints_1 ) names |
| [2] | `routes` | List of routes |
2021-01-19 08:30:05 +00:00
| [3] | `routes[n].services` | List of [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ) definitions (See below for `ExternalName Service` setup) |
2020-02-26 11:28:05 +00:00
| [4] | `services[n].name` | Defines the name of a [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ) |
2021-01-15 14:54:04 +00:00
| [6] | `services[n].port` | Defines the port of a [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ). This can be a reference to a named port. |
2020-02-26 11:28:05 +00:00
| [7] | `services[n].weight` | Defines the weight to apply to the server load balancing |
??? example "Declaring an IngressRouteUDP"
```yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteUDP
metadata:
name: ingressrouteudpfoo
spec:
entryPoints:
- fooudp
routes:
- services:
- name: foo
port: 8080
weight: 10
- name: bar
port: 8081
weight: 10
```
2020-03-17 11:34:04 +00:00
2021-01-19 08:30:05 +00:00
!!! important "Using Kubernetes ExternalName Service"
2021-09-21 14:28:11 +00:00
Traefik backends creation needs a port to be set, however Kubernetes [ExternalName Service ](https://kubernetes.io/docs/concepts/services-networking/service/#externalname ) could be defined without any port.
2021-01-19 08:30:05 +00:00
Accordingly, Traefik supports defining a port in two ways:
- only on `IngressRouteUDP` service
- on both sides, you'll be warned if the ports don't match, and the `IngressRouteUDP` service port is used
Thus, in case of two sides port definition, Traefik expects a match between ports.
??? example "Examples"
```yaml tab="IngressRouteUDP"
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteUDP
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
- services:
- name: external-svc
port: 80
---
apiVersion: v1
kind: Service
metadata:
name: external-svc
namespace: default
spec:
externalName: external.domain
type: ExternalName
```
```yaml tab="ExternalName Service"
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteUDP
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
- services:
- name: external-svc
---
apiVersion: v1
kind: Service
metadata:
name: external-svc
namespace: default
spec:
externalName: external.domain
type: ExternalName
ports:
- port: 80
```
```yaml tab="Both sides"
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteUDP
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
- services:
- name: external-svc
port: 80
---
apiVersion: v1
kind: Service
metadata:
name: external-svc
namespace: default
spec:
externalName: external.domain
type: ExternalName
ports:
- port: 80
```
2020-01-07 10:26:05 +00:00
### Kind: `TLSOption`
2019-09-23 12:32:04 +00:00
2020-01-07 10:26:05 +00:00
`TLSOption` is the CRD implementation of a [Traefik "TLS Option" ](../../https/tls.md#tls-options ).
2020-02-26 11:28:05 +00:00
Register the `TLSOption` [kind ](../../reference/dynamic-configuration/kubernetes-crd.md#definitions ) in the Kubernetes cluster before creating `TLSOption` objects
2020-01-07 10:26:05 +00:00
or referencing TLS options in the [`IngressRoute` ](#kind-ingressroute ) / [`IngressRouteTCP` ](#kind-ingressroutetcp ) objects.
!!! info "TLSOption Attributes"
```yaml tab="TLSOption"
apiVersion: traefik.containo.us/v1alpha1
kind: TLSOption
metadata:
2022-03-03 19:18:07 +00:00
name: mytlsoption # [1]
2020-01-07 10:26:05 +00:00
namespace: default
spec:
2022-03-03 19:18:07 +00:00
minVersion: VersionTLS12 # [2]
maxVersion: VersionTLS13 # [3]
curvePreferences: # [4]
2020-01-07 10:26:05 +00:00
- CurveP521
- CurveP384
2022-03-03 19:18:07 +00:00
cipherSuites: # [5]
2020-01-07 10:26:05 +00:00
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- TLS_RSA_WITH_AES_256_GCM_SHA384
2022-03-03 19:18:07 +00:00
clientAuth: # [6]
secretNames: # [7]
2021-06-24 09:28:05 +00:00
- secret-ca1
- secret-ca2
2022-03-03 19:18:07 +00:00
clientAuthType: VerifyClientCertIfGiven # [8]
sniStrict: true # [9]
alpnProtocols: # [10]
2021-08-20 16:20:06 +00:00
- foobar
2020-01-07 10:26:05 +00:00
```
2022-03-03 19:18:07 +00:00
| Ref | Attribute | Purpose |
|------|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [1] | `name` | Defines the name of the TLSOption resource. One can use `default` as name to redefine the [default TLSOption ](../../https/tls.md#tls-options ). |
| [2] | `minVersion` | Defines the [minimum TLS version ](../../https/tls.md#minimum-tls-version ) that is acceptable. |
| [3] | `maxVersion` | Defines the [maximum TLS version ](../../https/tls.md#maximum-tls-version ) that is acceptable. |
| [4] | `cipherSuites` | list of supported [cipher suites ](../../https/tls.md#cipher-suites ) for TLS versions up to TLS 1.2. |
| [5] | `curvePreferences` | List of the [elliptic curves references ](../../https/tls.md#curve-preferences ) that will be used in an ECDHE handshake, in preference order. |
| [6] | `clientAuth` | determines the server's policy for TLS [Client Authentication ](../../https/tls.md#client-authentication-mtls ). |
| [7] | `clientAuth.secretNames` | list of names of the referenced Kubernetes [Secrets ](https://kubernetes.io/docs/concepts/configuration/secret/ ) (in TLSOption namespace). The secret must contain a certificate under either a `tls.ca` or a `ca.crt` key. |
| [8] | `clientAuth.clientAuthType` | defines the client authentication type to apply. The available values are: `NoClientCert` , `RequestClientCert` , `VerifyClientCertIfGiven` and `RequireAndVerifyClientCert` . |
| [9] | `sniStrict` | if `true` , Traefik won't allow connections from clients connections that do not specify a server_name extension. |
| [10] | `alpnProtocols` | List of supported [application level protocols ](../../https/tls.md#alpn-protocols ) for the TLS handshake, in order of preference. |
2021-06-14 16:06:10 +00:00
!!! info "CA Secret"
The CA secret must contain a base64 encoded certificate under either a `tls.ca` or a `ca.crt` key.
2020-01-07 10:26:05 +00:00
??? example "Declaring and referencing a TLSOption"
```yaml tab="TLSOption"
apiVersion: traefik.containo.us/v1alpha1
kind: TLSOption
metadata:
name: mytlsoption
namespace: default
spec:
minVersion: VersionTLS12
sniStrict: true
cipherSuites:
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- TLS_RSA_WITH_AES_256_GCM_SHA384
clientAuth:
secretNames:
2021-06-24 09:28:05 +00:00
- secret-ca1
- secret-ca2
2020-01-07 10:26:05 +00:00
clientAuthType: VerifyClientCertIfGiven
```
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutebar
spec:
entryPoints:
- web
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.com`) && PathPrefix(`/stripit`)
2020-01-07 10:26:05 +00:00
kind: Rule
services:
- name: whoami
port: 80
tls:
options:
name: mytlsoption
namespace: default
```
```yaml tab="Secrets"
apiVersion: v1
kind: Secret
metadata:
2021-06-24 09:28:05 +00:00
name: secret-ca1
2020-01-07 10:26:05 +00:00
namespace: default
data:
2021-06-14 16:06:10 +00:00
# Must contain a certificate under either a `tls.ca` or a `ca.crt` key.
2020-01-07 10:26:05 +00:00
tls.ca: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
---
apiVersion: v1
kind: Secret
metadata:
2021-06-24 09:28:05 +00:00
name: secret-ca2
2020-01-07 10:26:05 +00:00
namespace: default
data:
2021-06-14 16:06:10 +00:00
# Must contain a certificate under either a `tls.ca` or a `ca.crt` key.
2020-01-07 10:26:05 +00:00
tls.ca: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
```
2019-09-23 12:32:04 +00:00
!!! important "References and namespaces"
If the optional `namespace` attribute is not set, the configuration will be applied with the namespace of the IngressRoute.
Additionally, when the definition of the TLS option is from another provider,
2020-10-27 11:46:04 +00:00
the cross-provider [syntax ](../../providers/overview.md#provider-namespace ) (`middlewarename@provider`) should be used to refer to the TLS option.
2019-09-23 16:58:03 +00:00
Specifying a namespace attribute in this case would not make any sense, and will be ignored.
2019-09-23 12:32:04 +00:00
2020-02-24 16:14:06 +00:00
### Kind: `TLSStore`
`TLSStore` is the CRD implementation of a [Traefik "TLS Store" ](../../https/tls.md#certificates-stores ).
Register the `TLSStore` kind in the Kubernetes cluster before creating `TLSStore` objects
or referencing TLS stores in the [`IngressRoute` ](#kind-ingressroute ) / [`IngressRouteTCP` ](#kind-ingressroutetcp ) objects.
!!! important "Default TLS Store"
Traefik currently only uses the [TLS Store named "default" ](../../https/tls.md#certificates-stores ).
This means that if you have two stores that are named default in different kubernetes namespaces,
they may be randomly chosen.
For the time being, please only configure one TLSSTore named default.
!!! info "TLSStore Attributes"
```yaml tab="TLSStore"
apiVersion: traefik.containo.us/v1alpha1
kind: TLSStore
metadata:
name: default
namespace: default
spec:
defaultCertificate:
2021-06-24 09:28:05 +00:00
secretName: my-secret # [1]
2020-02-24 16:14:06 +00:00
```
2020-09-11 13:40:03 +00:00
| Ref | Attribute | Purpose |
|-----|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [1] | `secretName` | The name of the referenced Kubernetes [Secret ](https://kubernetes.io/docs/concepts/configuration/secret/ ) that holds the default certificate for the store. |
2020-02-24 16:14:06 +00:00
??? example "Declaring and referencing a TLSStore"
```yaml tab="TLSStore"
apiVersion: traefik.containo.us/v1alpha1
kind: TLSStore
metadata:
name: default
namespace: default
spec:
defaultCertificate:
secretName: supersecret
```
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutebar
spec:
entryPoints:
- web
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`example.com`) && PathPrefix(`/stripit`)
2020-02-24 16:14:06 +00:00
kind: Rule
services:
- name: whoami
port: 80
tls:
store:
name: default
```
```yaml tab="Secret"
apiVersion: v1
kind: Secret
metadata:
name: supersecret
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
tls.key: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0=
```
2020-03-17 11:34:04 +00:00
2020-09-11 13:40:03 +00:00
### Kind: `ServersTransport`
`ServersTransport` is the CRD implementation of a [ServersTransport ](../services/index.md#serverstransport ).
!!! important "Default serversTransport"
If no `serversTransport` is specified, the `default@internal` will be used.
The `default@internal` serversTransport is created from the [static configuration ](../overview.md#transport-configuration ).
!!! info "ServersTransport Attributes"
2021-09-16 13:12:13 +00:00
```yaml tab="ServersTransport"
2020-09-11 13:40:03 +00:00
apiVersion: traefik.containo.us/v1alpha1
kind: ServersTransport
metadata:
name: mytransport
namespace: default
spec:
serverName: foobar # [1]
insecureSkipVerify: true # [2]
rootCAsSecrets: # [3]
- foobar
- foobar
certificatesSecrets: # [4]
- foobar
- foobar
maxIdleConnsPerHost: 1 # [5]
forwardingTimeouts: # [6]
dialTimeout: 42s # [7]
responseHeaderTimeout: 42s # [8]
idleConnTimeout: 42s # [9]
2021-07-15 12:02:11 +00:00
peerCertURI: foobar # [10]
2021-09-16 10:18:08 +00:00
disableHTTP2: true # [11]
2020-09-11 13:40:03 +00:00
```
2021-09-17 06:56:07 +00:00
| Ref | Attribute | Purpose |
|------|-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [1] | `serverName` | ServerName used to contact the server. |
| [2] | `insecureSkipVerify` | Controls whether the server's certificate chain and host name is verified. |
| [3] | `rootCAsSecrets` | Defines the set of root certificate authorities to use when verifying server certificates. The secret must contain a certificate under either a tls.ca or a ca.crt key. |
| [4] | `certificatesSecrets` | Certificates to present to the server for mTLS. |
| [5] | `maxIdleConnsPerHost` | Controls the maximum idle (keep-alive) connections to keep per-host. If zero, `defaultMaxIdleConnsPerHost` is used. |
| [6] | `forwardingTimeouts` | Timeouts for requests forwarded to the servers. |
| [7] | `dialTimeout` | The amount of time to wait until a connection to a server can be established. If zero, no timeout exists. |
| [8] | `responseHeaderTimeout` | The amount of time to wait for a server's response headers after fully writing the request (including its body, if any). If zero, no timeout exists. |
| [9] | `idleConnTimeout` | The maximum amount of time an idle (keep-alive) connection will remain idle before closing itself. If zero, no timeout exists. |
| [10] | `peerCertURI` | URI used to match against SAN URIs during the server's certificate verification. |
| [11] | `disableHTTP2` | Disables HTTP/2 for connections with servers. |
2020-09-11 13:40:03 +00:00
2021-06-14 16:06:10 +00:00
!!! info "CA Secret"
The CA secret must contain a base64 encoded certificate under either a `tls.ca` or a `ca.crt` key.
2020-09-11 13:40:03 +00:00
??? example "Declaring and referencing a ServersTransport"
```yaml tab="ServersTransport"
apiVersion: traefik.containo.us/v1alpha1
kind: ServersTransport
metadata:
name: mytransport
namespace: default
spec:
serverName: example.org
insecureSkipVerify: true
```
```yaml tab="IngressRoute"
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: testroute
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`example.com`)
kind: Rule
services:
- name: whoami
port: 80
serversTransport: mytransport
```
2021-09-16 13:12:13 +00:00
#### ServersTransport reference
By default, the referenced ServersTransport CRD must be defined in the same [Kubernetes service ](https://kubernetes.io/docs/concepts/services-networking/service/ ) namespace.
To reference a ServersTransport CRD from another namespace,
the value must be of form `namespace-name@kubernetescrd` ,
and the [cross-namespace ](../../../providers/kubernetes-crd/#allowcrossnamespace ) option must be enabled.
If the ServersTransport CRD is defined in another provider the cross-provider format `name@provider` should be used.
2019-09-23 12:32:04 +00:00
## Further
Also see the [full example ](../../user-guides/crd-acme/index.md ) with Let's Encrypt.