Traefik & Kubernetes

The Kubernetes Ingress Controller.

The Traefik Kubernetes Ingress provider is a Kubernetes Ingress controller; that is to say,it manages access to a cluster services by supporting the Ingress specification.

Enabling and using the provider

As usual, the provider is enabled through the static configuration:

  1. [providers.kubernetesIngress]
  1. providers:
  2. kubernetesIngress: {}
  1. --providers.kubernetesingress=true

The provider then watches for incoming ingresses events, such as the example below, and derives the corresponding dynamic configuration from it, which in turn will create the resulting routers, services, handlers, etc.

  1. kind: Ingress
  2. apiVersion: extensions/v1beta1
  3. metadata:
  4. name: "foo"
  5. namespace: production
  6. spec:
  7. rules:
  8. - host: foo.com
  9. http:
  10. paths:
  11. - path: /bar
  12. backend:
  13. serviceName: service1
  14. servicePort: 80
  15. - path: /foo
  16. backend:
  17. serviceName: service1
  18. servicePort: 80

Provider Configuration Options

Browse the Reference

If you're in a hurry, maybe you'd rather go through the static configuration reference.

endpoint

Optional, Default=empty

  1. [providers.kubernetesIngress]
  2. endpoint = "http://localhost:8080"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. endpoint = "http://localhost:8080"
  4. # ...
  1. --providers.kubernetesingress.endpoint="http://localhost:8080"

The Kubernetes server endpoint as URL, which is only used when the behavior based on environment variables described below does not apply.

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.They are both provided automatically as mounts in the pod where Traefik is deployed.

When the environment variables are not found, Traefik tries to connect to the Kubernetes API server with an external-cluster client.In which 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.

token

Optional, Default=empty

  1. [providers.kubernetesIngress]
  2. token = "mytoken"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. token = "mytoken"
  4. # ...
  1. --providers.kubernetesingress.token="mytoken"

Bearer token used for the Kubernetes client configuration.

certAuthFilePath

Optional, Default=empty

  1. [providers.kubernetesIngress]
  2. certAuthFilePath = "/my/ca.crt"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. certAuthFilePath: "/my/ca.crt"
  4. # ...
  1. --providers.kubernetesingress.certauthfilepath="/my/ca.crt"

Path to the certificate authority file.Used for the Kubernetes client configuration.

disablePassHostHeaders

Optional, Default=false

  1. [providers.kubernetesIngress]
  2. disablePassHostHeaders = true
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. disablePassHostHeaders: true
  4. # ...
  1. --providers.kubernetesingress.disablepasshostheaders=true

Whether to disable PassHost Headers.

namespaces

Optional, Default: all namespaces (empty array)

  1. [providers.kubernetesIngress]
  2. namespaces = ["default", "production"]
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. namespaces:
  4. - "default"
  5. - "production"
  6. # ...
  1. --providers.kubernetesingress.namespaces="default,production"

Array of namespaces to watch.

labelSelector

Optional,Default: empty (process all Ingresses)

  1. [providers.kubernetesIngress]
  2. labelSelector = "A and not B"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. labelselector: "A and not B"
  4. # ...
  1. --providers.kubernetesingress.labelselector="A and not B"

By default, Traefik processes all Ingress objects in the configured namespaces.A label selector can be defined to filter on specific Ingress objects only.

See label-selectors for details.

ingressClass

Optional, Default: empty

  1. [providers.kubernetesIngress]
  2. ingressClass = "traefik-internal"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. ingressClass: "traefik-internal"
  4. # ...
  1. --providers.kubernetesingress.ingressclass="traefik-internal"

Value of kubernetes.io/ingress.class annotation that identifies Ingress objects to be processed.

If the parameter is non-empty, only Ingresses containing an annotation with the same value are processed.Otherwise, Ingresses missing the annotation, having an empty value, or with the value traefik are processed.

ingressEndpoint

hostname

Optional, Default: empty

  1. [providers.kubernetesIngress.ingressEndpoint]
  2. hostname = "foo.com"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. ingressEndpoint:
  4. hostname: "foo.com"
  5. # ...
  1. --providers.kubernetesingress.ingressendpoint.hostname="foo.com"

Hostname used for Kubernetes Ingress endpoints.

ip

Optional, Default: empty

  1. [providers.kubernetesIngress.ingressEndpoint]
  2. ip = "1.2.3.4"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. ingressEndpoint:
  4. ip: "1.2.3.4"
  5. # ...
  1. --providers.kubernetesingress.ingressendpoint.ip="1.2.3.4"

IP used for Kubernetes Ingress endpoints.

publishedService

Optional, Default: empty

  1. [providers.kubernetesIngress.ingressEndpoint]
  2. publishedService = "foo-service"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. ingressEndpoint:
  4. publishedService: "foo-service"
  5. # ...
  1. --providers.kubernetesingress.ingressendpoint.publishedservice="foo-service"

Published Kubernetes Service to copy status from.

throttleDuration

Optional, Default: 0 (no throttling)

  1. [providers.kubernetesIngress]
  2. throttleDuration = "10s"
  3. # ...
  1. providers:
  2. kubernetesIngress:
  3. throttleDuration: "10s"
  4. # ...
  1. --providers.kubernetesingress.throttleDuration="10s"

Further

If one wants to know more about the various aspects of the Ingress spec that Traefik supports, many examples of Ingresses definitions are located in the tests data of the Traefik repository.