DEV Community

Cover image for Kubernetes Ingress in k3s: Routing That Actually Works in Production
Shuvo Halder
Shuvo Halder

Posted on

Kubernetes Ingress in k3s: Routing That Actually Works in Production

Kubernetes Ingress in k3s: Routing That Actually Works in Production

A Service gets your pods talking to each other. An Ingress gets the internet talking to your Services — with one IP, one TLS story, and host-based routing instead of a NodePort per app. I have seen teams run twenty NodePorts and a spreadsheet of ports, then wonder why nothing is reachable after a node restart.

k3s ships with Traefik as its default Ingress controller, which is a gift and a trap: it works out of the box, so nobody learns how it works — until routing breaks at the worst moment. This is the setup I run in production, and the one I would defend in a DevOps interview.

Ingress, Service, and Controller — Know Which One You Are Debugging

Three pieces, three failure modes:

  • Ingress resource: a YAML object that says "host app.example.com, path /api, goes to Service api on port 80". It does nothing on its own.
  • Ingress controller: the actual proxy (Traefik in k3s, or NGINX Ingress) that watches Ingress resources and configures itself. No controller, no routing — your Ingress is just a wish.
  • Service: the stable ClusterIP that the controller forwards to. The controller never talks to pods directly.

When routing fails, ask in order: does the Ingress exist, is a controller running, does the controller see it, and can the controller reach the Service? Most "Ingress is broken" tickets die at step two.

Traefik in k3s: What Ships by Default

k3s installs Traefik as a DaemonSet-ish Deployment in kube-system, fronted by a Service of type LoadBalancer. On a bare-metal or single-node cluster, that LoadBalancer never gets an external IP — so you reach Traefik through the node's IP on ports 80 and 443, or through a MetalLB address if you installed it.

kubectl -n kube-system get pods -l app.kubernetes.io/name=traefik
kubectl get svc -n kube-system traefik
kubectl get ingressclass
Enter fullscreen mode Exit fullscreen mode

Check the IngressClass first. k3s names Traefik's class traefik, and it is the default — an Ingress without ingressClassName still lands on Traefik. The moment you install a second controller, that default decides where traffic goes, so set the class explicitly in every Ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web
  namespace: apps
spec:
  ingressClassName: traefik
  rules:
  - host: app.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web
            port:
              number: 80
Enter fullscreen mode Exit fullscreen mode

A Real Ingress: Host, Path, and TLS

Path routing is where beginners get bitten. pathType: Prefix on /api also matches /apiv2 — use /api/ with a trailing slash, or an Exact rule for the root. Keep one Ingress per host where you can; a single 200-line Ingress shared by five teams is a merge-conflict machine.

TLS in k3s is cert-manager plus an Ingress annotation, not a manual secret:

metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
  - hosts:
    - app.example.com
    secretName: app-tls
Enter fullscreen mode Exit fullscreen mode

cert-manager creates the secret, Traefik reads it, and renewal happens without you. The failure I see most: the ClusterIssuer is misconfigured and the certificate stays pending — check kubectl get certificate -A before blaming the Ingress. If you manage certificates by hand, you are back to the expired-cert outage from the Certbot post.

Traefik vs NGINX Ingress: Picking One

Both are fine. The differences that matter in production:

  • Traefik (k3s default): zero config to start, great dashboard, native Let's Encrypt support, middleware CRDs for auth and rate limiting. Its annotation style differs from NGINX, so Stack Overflow answers for one do not transfer to the other.
  • NGINX Ingress: the annotation ecosystem everyone has blogged about, familiar rewrite rules, and a huge community. Needs a separate install in k3s, and you must disable or replace Traefik first or they fight over the default class.

My rule: on k3s, stay with Traefik unless you have a concrete NGINX-only feature you need. Two controllers in one cluster is a routing incident waiting for a deploy. If you do switch, set --disable=traefik at install time or uninstall it cleanly — a half-removed controller still answers traffic.

Annotations and Middleware That Earn Their Keep

Traefik Middleware is the clean way to add behaviour without touching the app:

apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: strip-prefix
spec:
  stripPrefix:
    prefixes:
      - /api
Enter fullscreen mode Exit fullscreen mode

Attach it with traefik.ingress.kubernetes.io/router.middlewares: apps-strip-prefix@kubernetescrd. The classics: redirect HTTP to HTTPS, strip a path prefix, add security headers, basic auth for an internal tool, and rate limiting for a public API. Keep middleware in the same namespace as the Ingress — a cross-namespace reference that silently does not apply is a debugging nightmare.

Troubleshooting: The Five Checks

When a route returns 404 or never reaches the app:

  1. DNS first. nslookup app.example.com — is the host even pointing at the cluster? Half of all Ingress tickets are DNS.
  2. Ingress status. kubectl get ingress -A — does it have an ADDRESS? No address means no controller picked it up. Check ingressClassName and the controller logs.
  3. Controller logs. kubectl -n kube-system logs -l app.kubernetes.io/name=traefik — Traefik logs every route it builds and every config error it rejects.
  4. Service reachability. kubectl port-forward svc/web 8080:80 — if the Service itself is broken, the Ingress cannot fix it. Check the Endpoints object: empty endpoints means the selector does not match any pod.
  5. TLS. openssl s_client -connect app.example.com:443 -servername app.example.com — a certificate for the wrong host, or an expired one, looks like an Ingress failure to the browser.

Debug in that order. Jumping to step five when DNS is wrong wastes an hour.

Production Pitfalls Checklist

The failures I actually see, in order of frequency:

  1. No IngressClass set, two controllers installed. Traffic goes to the wrong proxy.
  2. PathType Prefix surprises. /api matching /apiv2, or / swallowing everything.
  3. TLS secret in the wrong namespace. The Ingress and its secret must live together.
  4. cert-manager not installed, certificates hand-managed. Renewal is a human again, and humans forget.
  5. No resource limits on the controller. Traefik OOM-killed under load takes every route down at once.
  6. Health checks hitting the app through the Ingress. A bad Ingress rule makes the load balancer think the app is down.
  7. Middleware referenced but not created. Traefik ignores the route silently instead of erroring loudly.
  8. NodePort habit. Exposing apps on NodePorts "temporarily" and leaving them open to the internet forever.

What Hiring Managers Actually Ask

If you are targeting remote DevOps or platform roles, this topic comes up because it reveals how you think about traffic:

  • "A user gets 404 on one path but not another — walk me through it." (Answer: DNS, Ingress status, controller logs, pathType, then the Service and Endpoints.)
  • "How do you expose twenty services on one cluster?" (Answer: one Ingress controller, one public IP, host-based routing, TLS at the edge, and one Ingress per team or host — never twenty NodePorts.)
  • "How do you do zero-downtime deploys behind Ingress?" (Answer: readiness probes that actually gate traffic, rolling updates, and a controller that drains connections — the Ingress only routes to ready pods.)

The answer they want is never "I created an Ingress once." It is the system around it: one controller, explicit classes, TLS automation, and a debugging order you can run under pressure.

The Monthly Ingress Routine

My monthly routine takes ten minutes:

  1. kubectl get ingress -A — every Ingress has an address, every host resolves.
  2. kubectl get certificate -A — nothing expiring in the next 30 days.
  3. Controller pods healthy, resource usage sane, logs free of config errors.
  4. One test request per critical host — from outside the cluster, not from a pod.
  5. Review middleware and annotations — anything stale, anything referencing a deleted object?

Do that, and Ingress stops being the mysterious layer that breaks on Friday night. Routing is infrastructure: boring, automated, monitored, and never a 2 AM surprise.


Your turn: What Ingress controller do you run — Traefik, NGINX, or something else? What broke for you the first time? Tell me in the comments.

Top comments (0)