Skip to main content
Version: 1.10

Using the Traefik Ingress Controller

Rancher Desktop uses K3s under the hood, which in turn uses Traefik as the default Ingress controller for your Kubernetes cluster. As an example, the below steps outline creating simple services that can be routed by the Ingress object.

Example Steps: Traefik Ingress Controller

  1. Open a bash session and set the node IP to your localhost address:

    IP=127.0.0.1
  2. Create a namespace called demo:

    kubectl create ns demo
  3. Create a whoami example with basic deployment, service, and Ingress objects defined:

    note

    Some Linux distributions don't allow listening to priviliged ports by default, please see the documentation on Traefik port binding access to authorize ports if necessary.

    cat << EOF | kubectl apply -n demo -f -
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    labels:
    app: whoami
    name: whoami
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: whoami
    template:
    metadata:
    labels:
    app: whoami
    spec:
    containers:
    - image: traefik/whoami:latest
    name: whoami
    ports:
    - containerPort: 80
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: whoami-svc
    spec:
    type: ClusterIP
    selector:
    app: whoami
    ports:
    - port: 80
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
    name: whoami-http
    annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: web
    spec:
    rules:
    - host: whoami.$IP.nip.io
    http:
    paths:
    - path: /
    pathType: Prefix
    backend:
    service:
    name: whoami-svc
    port:
    number: 80
    EOF
  4. Verify the ingress works by calling curl:

    curl whoami.$IP.nip.io
    Hostname: whoami-6ff6dcfdc8-74mwq
    IP: 127.0.0.1
    IP: ::1
    IP: 10.42.0.42
    IP: fe80::e804:41ff:feac:7eef
    RemoteAddr: 10.42.0.45:35392
    GET / HTTP/1.1
    Host: whoami.127.0.0.1.nip.io
    User-Agent: curl/7.64.1
    Accept: */*
    Accept-Encoding: gzip
    X-Forwarded-For: 10.42.0.1
    X-Forwarded-Host: whoami.127.0.0.1.nip.io
    X-Forwarded-Port: 80
    X-Forwarded-Proto: http
    X-Forwarded-Server: traefik-d497b4cb6-4vkg9
    X-Real-Ip: 10.42.0.1
  5. Delete the resources:

    kubectl delete all,ingress --all -n demo