traefik/docs/content/operations/include-api-examples.md

84 lines
2.4 KiB
Markdown
Raw Normal View History

2023-05-10 13:28:05 +00:00
```yaml tab="Docker & Swarm"
2019-11-12 14:40:05 +00:00
# Dynamic Configuration
labels:
2020-03-13 21:50:05 +00:00
- "traefik.http.routers.api.rule=Host(`traefik.example.com`)"
2019-11-12 14:40:05 +00:00
- "traefik.http.routers.api.service=api@internal"
- "traefik.http.routers.api.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
```
```yaml tab="Docker (Swarm)"
# Dynamic Configuration
deploy:
labels:
2020-03-13 21:50:05 +00:00
- "traefik.http.routers.api.rule=Host(`traefik.example.com`)"
2019-11-12 14:40:05 +00:00
- "traefik.http.routers.api.service=api@internal"
- "traefik.http.routers.api.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
# Dummy service for Swarm port detection. The port can be any valid integer value.
- "traefik.http.services.dummy-svc.loadbalancer.server.port=9999"
```
```yaml tab="Kubernetes CRD"
2023-03-20 14:38:08 +00:00
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: traefik-dashboard
spec:
routes:
2020-03-13 21:50:05 +00:00
- match: Host(`traefik.example.com`)
kind: Rule
services:
- name: api@internal
kind: TraefikService
2020-02-17 16:20:05 +00:00
middlewares:
- name: auth
---
2023-03-20 14:38:08 +00:00
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: auth
spec:
basicAuth:
secret: secretName # Kubernetes secret named "secretName"
```
2019-11-15 12:34:41 +00:00
```yaml tab="Consul Catalog"
# Dynamic Configuration
2020-03-13 21:50:05 +00:00
- "traefik.http.routers.api.rule=Host(`traefik.example.com`)"
2019-11-15 12:34:41 +00:00
- "traefik.http.routers.api.service=api@internal"
- "traefik.http.routers.api.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
```
2019-11-12 14:40:05 +00:00
```yaml tab="File (YAML)"
# Dynamic Configuration
http:
routers:
api:
2020-03-13 21:50:05 +00:00
rule: Host(`traefik.example.com`)
2019-11-12 14:40:05 +00:00
service: api@internal
middlewares:
- auth
middlewares:
auth:
basicAuth:
users:
- "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"
- "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"
```
```toml tab="File (TOML)"
# Dynamic Configuration
[http.routers.my-api]
rule = "Host(`traefik.example.com`)"
service = "api@internal"
middlewares = ["auth"]
[http.middlewares.auth.basicAuth]
users = [
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
"test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
]
```