Traefik

From G1Joshi/Agent-Skills · View interactive version

Traefik is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Traefik edge router assistance covering dynamic configuration, Docker/Kubernetes providers, Let's Encrypt TLS, and middlewares. Use when building dynamic reverse proxies and microservice ingress routing.

How to use this skill

Skill file

Traefik

Traefik is a modern HTTP reverse proxy and load balancer designed for microservices, featuring automatic service discovery, dynamic configuration, and Kubernetes Gateway API support.

When to Use

Quick Start

labels:
  - "traefik.enable=true"
  - "traefik.http.routers.my-app.rule=Host(`example.com`)"
  - "traefik.http.routers.my-app.entrypoints=websecure"
  - "traefik.http.routers.my-app.tls.certresolver=myresolver"

Core Concepts

Docker Compose Automatic Service Discovery

Exposing containers to Traefik via container labels:

services:
  traefik:
    image: traefik:v3.1
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.myresolver.acme.tlschallenge=true"
      - "--certificatesresolvers.myresolver.acme.email=admin@example.com"
      - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "acme_data:/letsencrypt"

  billing-api:
    image: myregistry/billing-api:v2.0
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.billing.rule=Host(`billing.example.com`)"
      - "traefik.http.routers.billing.entrypoints=websecure"
      - "traefik.http.routers.billing.tls.certresolver=myresolver"
      - "traefik.http.routers.billing.middlewares=ratelimit@docker"
      # Middleware: Rate limit 100 req/s
      - "traefik.http.middlewares.ratelimit.ratelimit.average=100"
      - "traefik.http.middlewares.ratelimit.ratelimit.burst=20"
      - "traefik.http.services.billing.loadbalancer.server.port=8080"

volumes:
  acme_data:

Kubernetes IngressRoute Custom Resource (CRD)

Modern Kubernetes routing with Traefik CRDs:

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: api-ingressroute
  namespace: default
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`api.example.com`) && PathPrefix(`/v2`)
      kind: Rule
      services:
        - name: api-service
          port: 8080
      middlewares:
        - name: stripprefix-v2
  tls:
    certResolver: myresolver

Static Configuration (traefik.yml)

Core startup parameters:

entryPoints:
  web:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https

  websecure:
    address: ":443"

api:
  dashboard: true
  insecure: false

Common Patterns

Docker Labels Dynamic Routing with Rate Limiting and Automatic TLS

Problem: Manually updating reverse proxy configuration every time a container restarts or changes ports.

Solution:

Configure routing dynamically via Docker container labels:

version: "3.8"

services:
  api:
    image: myorg/api:latest
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api.rule=Host(`api.example.com`)"
      - "traefik.http.routers.api.entrypoints=websecure"
      - "traefik.http.routers.api.tls.certresolver=myresolver"
      - "traefik.http.routers.api.middlewares=api-ratelimit"
      - "traefik.http.middlewares.api-ratelimit.ratelimit.average=50"
      - "traefik.http.services.api.loadbalancer.server.port=8080"

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :------------------------------------ | :--------------------------------------------------------------------------- | :----------------------------------------------------------------------------------- |

| 404 Not Found on routed host | Host(...) rule does not match request header or router entrypoint missing. | Verify Host header and check Traefik dashboard (http://localhost:8080/dashboard/). |

| Cannot obtain ACME certificate | Port 80 not reachable from internet for Let's Encrypt HTTP challenge. | Verify DNS points to Traefik public IP and firewall allows incoming port 80. |

| Skipping container: port is missing | Multiple ports exposed in Docker image without explicit server.port label. | Add traefik.http.services.<name>.loadbalancer.server.port=<port>. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.