Traefik Ingress

k3s includes the Traefik ingress controller so you can expose HTTP services by hostname and path.

An Ingress routes outside HTTP and HTTPS traffic to Services inside the cluster based on the hostname or URL path. k3s installs the Traefik ingress controller for you at startup.

How traffic flows

A request hits Traefik, which reads your Ingress rules and forwards it to the matching Service. The Service then load-balances across the healthy Pods behind it.

Traefik routes external traffic to a Service and its PodsUser / BrowserTraefik IngressService(ClusterIP)PodPodPod
Traefik → Service → Pods: the Service load-balances across all matching Pods.

Example

Example · yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-ingress
spec:
  rules:
    - host: myapp.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web-service
                port:
                  number: 80

When to use it

  • A developer exposes an internal REST API via an Ingress resource so requests to api.example.com are routed to the correct Kubernetes service.
  • An operator enables the Traefik dashboard in k3s to monitor live HTTP routing rules and middleware configurations in the cluster.
  • A team configures TLS termination in Traefik by adding a cert-manager Certificate resource, letting Traefik serve HTTPS for all Ingress hosts.

More examples

Create an Ingress for a service

Defines an Ingress that routes all traffic for app.example.com to the my-app-svc service via Traefik.

Example · yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app
spec:
  rules:
  - host: app.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-app-svc
            port:
              number: 80

Verify Traefik is running

Confirms Traefik is deployed and checks which ports it listens on for HTTP and HTTPS traffic.

Example · bash
kubectl get pods -n kube-system -l app.kubernetes.io/name=traefik
kubectl get svc -n kube-system traefik

Disable Traefik at install time

Installs k3s without the built-in Traefik so you can substitute your own ingress controller such as NGINX.

Example · bash
curl -sfL https://get.k3s.io | \
  INSTALL_K3S_EXEC='--disable traefik' sh -
# Then install a custom ingress controller:

Discussion

  • Be the first to comment on this lesson.