traefik-pro
Traefik guidance — dynamic routing, providers, middleware chains, Let's Encrypt, and production edge config.
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- traefik-pro
- category
- development
- description
- Traefik guidance — dynamic routing, providers, middleware chains, Let's Encrypt, and production edge config.
03 SKILL.md 正文
Overview
Traefik is the cloud-native edge router: it discovers services automatically from providers (Docker, Kubernetes, Consul) and configures routing dynamically — no config reloads when containers come and go. Labels on containers become routers, services, and middleware. For Docker and Kubernetes environments, it's the lowest-friction way to get routing, TLS, and middleware.
Traefik's model (entrypoints → routers → middleware → services) is elegant once internalized, and its dashboard makes the dynamic config visible. This skill covers the core model, provider configuration, middleware chains, automatic TLS, and production hardening.
When to use
- Routing to Docker containers or Kubernetes services dynamically.
- Getting automatic HTTPS with Let's Encrypt.
- Adding middleware (auth, rate limiting, headers, redirects).
- Choosing between Traefik, nginx, Caddy, or HAProxy.
- Debugging routing (dashboard, logs, whoami).
- Running Traefik in production (HA, dashboard security, observability).
- Migrating from static nginx configs to dynamic routing.
Core concepts
- The routing chain. Entrypoints (ports) → Routers (match rules: Host, PathPrefix) → Middleware (transform/filter) → Services (load-balance to backends). Every request flows through this chain; debug by walking it.
- Providers. Docker (labels), Kubernetes Ingress/CRD, Consul, file, and more — Traefik watches providers and rebuilds routing dynamically. The provider is where services are discovered; labels/annotations are where routing is declared.
- Docker labels. Routing declared on containers:
traefik.http.routers.api.rule=Host("api.example.com"), service ports, middleware attachments. Labels are the config — keep them organized and versioned in Compose files. - Kubernetes providers. Ingress (standard, limited) vs IngressRoute CRDs (full Traefik features: middleware, TCP, TLS options). CRDs unlock the real power; Ingress is the portable subset.
- Middleware. Reusable request processors: stripPrefix, basicAuth/forwardAuth, rateLimit, headers (security headers), redirect, compress, circuitBreaker, retry. Chain them on routers; define once, attach many times.
- TLS. Automatic Let's Encrypt via ACME (HTTP-01 or DNS-01 challenge);
tls.certresolveron routers; wildcard certs need DNS-01. Store certs inacme.json(persist it!) — losing it means reissuing under rate limits. - ACME challenges. HTTP-01 (simple, needs port 80 reachable); DNS-01 (wildcard-capable, needs DNS provider credentials); TLS-ALPN-01 (port 443). Choose per environment; staging CA for testing to avoid rate limits.
- Dashboard and API. The dashboard shows live routers/services/middleware — the primary debugging tool. Secure it (auth middleware, internal-only) — it exposes your routing topology.
- Observability. Access logs (structured JSON), metrics (Prometheus), tracing (OpenTelemetry). Enable from the start; debugging routing without logs is guesswork.
- High availability. Multiple Traefik replicas behind a load balancer; shared ACME storage for Let's Encrypt (KV store or shared file); sticky sessions only when the app requires them.
- TCP and UDP. Beyond HTTP: TCP routers (databases, custom protocols) with SNI routing, UDP for DNS-like traffic. TLS passthrough for end-to-end encryption.
- Plugins. Community middleware plugins (crowdsec, custom auth) via the plugin catalog — vet them like any dependency.
- Pilot (deprecated awareness). Traefik Pilot/Hup was discontinued — don't build on it; use native metrics/logs and your own observability.
- Configuration split. Static config (entrypoints, providers, ACME — startup only) vs dynamic config (routers, services, middleware — hot-reloaded). Knowing which is which explains "why didn't my change apply."
Practical workflow
- Define static config. Entrypoints (web:80, websecure:443), providers (docker/kubernetes), ACME resolver, logging/metrics. This changes rarely — get it right once.
# traefik.yml (static) entryPoints: { web: { address: ":80" }, websecure: { address: ":443" } } providers: { docker: { exposedByDefault: false } } certificatesResolvers: le: { acme: { email: ops@example.com, storage: /acme.json, httpChallenge: { entryPoint: web } } } - Label services. Routers with Host rules, TLS resolver, middleware chains — declared on the container/service:
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=le" - "traefik.http.routers.api.middlewares=sec-headers,api-ratelimit" - Build middleware chains. Security headers, rate limits, auth, compression as named middleware; attach per router. Test each middleware in isolation before chaining.
# dynamic file provider: middlewares.yml http: middlewares: sec-headers: headers: stsSeconds: 31536000 contentTypeNosniff: true frameDeny: true api-ratelimit: rateLimit: { average: 100, burst: 50 } - Set up ACME carefully.
acme.jsonpersisted (chmod 600, backed up); staging CA first; DNS-01 for wildcards; monitor certificate expiry even with automation. - Secure the dashboard. Basic auth or forwardAuth + IP allowlist; never expose it publicly unauthenticated.
- Enable observability. JSON access logs, Prometheus metrics, tracing; dashboards for router error rates and TLS cert expiry.
- Test routing. The
whoamicontainer for verifying rules; dashboard to confirm router/service wiring;curl -H "Host: ..."for Host-rule testing. - Run HA. Multiple replicas, shared acme.json storage, health checks; rolling updates without dropping the edge.
Common pitfalls
exposedByDefaultleft true — every container getting a route; set false and enable explicitly.- Lost
acme.json— reissuing under Let's Encrypt rate limits; persist and back it up (chmod 600). - Testing ACME against production — rate-limit lockout; use the staging CA first.
- Static vs dynamic confusion — changing entrypoints expecting hot-reload; static config needs restarts.
- Dashboard exposed — unauthenticated topology disclosure; auth + internal-only.
- Missing middleware order awareness — chain order matters (auth before rate limit, etc.); think through the sequence.
- No health checks on services — traffic to dead backends; configure service health checks.
- HTTP-01 behind another proxy — challenge unreachable; use DNS-01 or ensure port 80 routes correctly.
- Wildcard without DNS-01 — HTTP-01 can't issue wildcards; DNS challenge required.
- Ignoring access logs — debugging routing blind; structured logs from day one.
- Sticky sessions by default — unnecessary statefulness; only when the app truly needs it.
- Plugin sprawl — unvetted community plugins; treat as dependencies with risk.
- Single replica as SPOF — edge downtime on updates; run HA with shared cert storage.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).