Skip to content

Instantly share code, notes, and snippets.

@prayagsingh
Last active February 20, 2020 13:42
Show Gist options
  • Save prayagsingh/7603d65c48a641d333b535b8935f63e6 to your computer and use it in GitHub Desktop.
Save prayagsingh/7603d65c48a641d333b535b8935f63e6 to your computer and use it in GitHub Desktop.
Traefik with go application server
# Providers :- discover the services that live on your infrastructure (their IP, health, ...)
# Entrypoints :- listen for incoming traffic (ports, ...)
# Routers :- analyse the requests (host, path, headers, SSL, ...). A router is in charge of connecting incoming requests to the services that can handle them.
# Services :- forward the request to your services (load balancing, ...). The Services are responsible for configuring how to reach the actual services that will eventually handle the incoming requests.
# Middlewares :- may update the request or make decisions based on the request (authentication, rate limiting, headers, ...)
version: "3.7"
networks:
test-network:
external: true
name: test-network
services:
traefik:
deploy:
replicas: 1
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 5
placement:
constraints:
- node.hostname == gcloud1
- node.role == manager
labels:
- "traefik.enable=true"
# here router is api and in proxy-config.toml file router is myrouter
#- "traefik.http.routers.api.rule=Host(`traefik.example.com`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
#- "traefik.http.routers.api.service=api@internal" # Let the dashboard access the traefik api
#- "traefik.http.routers.api.tls.certresolver=le"
#- "traefik.http.routers.traefik.entrypoints=web"
#- "traefik.http.routers.traefik.middlewares=dashboard-auth" # put your middleware name here separated by comma
# All middlewares here
#- "traefik.http.middlewares.dashboard-auth.basicauth.users=test:XXX" # using double $ to skip single $ else not accepted
hostname: traefik
image: "traefik:v2.1"
#user: "${UID}:${GID}"
command:
- --providers.file.filename=/etc/traefik/proxy-config.toml # Using file for reading the config
- --entrypoints.web.address=:5050
- --entrypoints.websecure.address=:443
#- --api.insecure # enabling dashboard on insecure connection
- --api=true
- --api.dashboard=true
- --api.debug=true
- --log.level=DEBUG
volumes:
- ./proxy-config.toml:/etc/traefik/proxy-config.toml:ro
- ./letsencrypt/acme.json:/etc/traefik/acme/acme.json:rw
ports:
- target: 5050
published: 5050
#protocol: tcp
mode: host
- target: 443
published: 443
#protocol: tcp
mode: host
- target: 8080
published: 8080
#protocol: tcp
mode: ingress # traefik dashboard
networks:
- test-network
[http.routers]
[http.routers.myrouter]
rule = "Host(`bchain.mydomain.in`)"
middlewares = ["auth"]
service = "goserver"
entryPoints = ["web"]
[http.routers.api]
rule = "Host(`traefik.mydomain.in`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
middlewares = ["auth"]
service = "api@internal"
entryPoints = ["websecure"] # <-- changed to `websecure` for https else move it back to `web`
# will route TLS requests (and ignore non tls requests)
[http.routers.api.tls]
certResolver = "myresolver"
# https://docs.traefik.io/routing/routers/#domains
[[http.routers.api.tls.domains]]
main = "traefik.mydomain.in"
[http.middlewares]
[http.middlewares.auth.basicAuth]
users = ["test:XX"]
[http.services]
[http.services.goserver.loadBalancer]
[[http.services.goserver.loadBalancer.servers]]
url = "http://priv_ip:8001"
#LetsEncrypt
[certificatesResolvers]
[certificatesResolvers.myresolver]
[certificatesResolvers.myresolver.acme]
email = "[email protected]"
storage = "/etc/traefik/acme/acme.json"
caServer = "https://acme-staging-v02.api.letsencrypt.org/directory"
#keyType = "EC384"
# tls challenge
[certificatesResolvers.myresolver.acme.tlsChallenge]
Orgignal domain changed to `example`
private_ip changed to `PRIVATEIP`
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=info msg="Configuration loaded from flags."
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=info msg="Traefik version 2.1.4 built on 2020-02-06T17:10:06Z"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Static configuration loaded {\"global\":{\"checkNewVersion\":true},\"serversTransport\":{\"maxIdleConnsPerHost\":200},\"entryPoints\":{\"web\":{\"address\":\":5050\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":10000000000},\"respondingTimeouts\":{\"idleTimeout\":180000000000}},\"forwardedHeaders\":{}},\"websecure\":{\"address\":\":443\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":10000000000},\"respondingTimeouts\":{\"idleTimeout\":180000000000}},\"forwardedHeaders\":{}}},\"providers\":{\"providersThrottleDuration\":2000000000,\"file\":{\"watch\":true,\"filename\":\"/etc/traefik/proxy-config.toml\"}},\"api\":{\"dashboard\":true,\"debug\":true},\"log\":{\"level\":\"DEBUG\",\"format\":\"common\"}}"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://docs.traefik.io/v2.0/contributing/data-collection/\n"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=info msg="Starting provider aggregator.ProviderAggregator {}"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Start TCP Server" entryPointName=web
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Start TCP Server" entryPointName=websecure
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=info msg="Starting provider *file.Provider {\"watch\":true,\"filename\":\"/etc/traefik/proxy-config.toml\"}"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=info msg="Starting provider *traefik.Provider {}"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Configuration received from provider file: {\"http\":{\"routers\":{\"api\":{\"entryPoints\":[\"websecure\"],\"middlewares\":[\"auth\"],\"service\":\"api@internal\",\"rule\":\"Host(`traefik.example.in`) \\u0026\\u0026 (PathPrefix(`/api`) || PathPrefix(`/dashboard`))\",\"tls\":{\"certResolver\":\"myresolver\",\"domains\":[{\"main\":\"traefik.example.in\"}]}},\"myrouter\":{\"entryPoints\":[\"web\"],\"middlewares\":[\"auth\"],\"service\":\"goserver\",\"rule\":\"Host(`bchain.example.in`)\"}},\"middlewares\":{\"auth\":{\"basicAuth\":{\"users\":[\"prayag:$apr1$dH.NJJK4$2.UTMIf8Etzu9.iTzOrME/\"]}}},\"services\":{\"goserver\":{\"loadBalancer\":{\"servers\":[{\"url\":\"http://PRIVATEIP:8001\"}],\"passHostHeader\":null}}}},\"tcp\":{},\"tls\":{}}" providerName=file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Configuration received from provider internal: {\"http\":{\"services\":{\"api\":{},\"dashboard\":{}}},\"tcp\":{},\"tls\":{}}" providerName=internal
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" serviceName=goserver middlewareName=pipelining middlewareType=Pipelining entryPointName=web routerName=myrouter@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating load-balancer" routerName=myrouter@file serviceName=goserver entryPointName=web
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating server 0 http://PRIVATEIP:8001" serviceName=goserver entryPointName=web routerName=myrouter@file serverName=0 traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Added outgoing tracing middleware goserver" entryPointName=web routerName=myrouter@file middlewareName=tracing middlewareType=TracingForwarder
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" entryPointName=web routerName=myrouter@file middlewareName=auth@file middlewareType=BasicAuth
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Adding tracing to middleware" entryPointName=web routerName=myrouter@file middlewareName=auth@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" entryPointName=web middlewareName=traefik-internal-recovery middlewareType=Recovery
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Added outgoing tracing middleware api@internal" middlewareName=tracing entryPointName=websecure routerName=api@file middlewareType=TracingForwarder
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" middlewareType=BasicAuth entryPointName=websecure routerName=api@file middlewareName=auth@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Adding tracing to middleware" middlewareName=auth@file routerName=api@file entryPointName=websecure
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" entryPointName=websecure middlewareName=traefik-internal-recovery middlewareType=Recovery
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="No default certificate, generating one"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=error msg="the router api@file uses a non-existent resolver: myresolver"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" entryPointName=web routerName=myrouter@file serviceName=goserver middlewareName=pipelining middlewareType=Pipelining
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating load-balancer" serviceName=goserver entryPointName=web routerName=myrouter@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating server 0 http://PRIVATEIP:8001" serverName=0 routerName=myrouter@file serviceName=goserver entryPointName=web traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Added outgoing tracing middleware goserver" routerName=myrouter@file middlewareName=tracing middlewareType=TracingForwarder entryPointName=web
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" entryPointName=web routerName=myrouter@file middlewareName=auth@file middlewareType=BasicAuth
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Adding tracing to middleware" entryPointName=web routerName=myrouter@file middlewareName=auth@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" entryPointName=web middlewareName=traefik-internal-recovery middlewareType=Recovery
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Added outgoing tracing middleware api@internal" routerName=api@file middlewareName=tracing middlewareType=TracingForwarder entryPointName=websecure
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" middlewareType=BasicAuth entryPointName=websecure routerName=api@file middlewareName=auth@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Adding tracing to middleware" middlewareName=auth@file entryPointName=websecure routerName=api@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="Creating middleware" middlewareName=traefik-internal-recovery middlewareType=Recovery entryPointName=websecure
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=debug msg="No default certificate, generating one"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:07Z" level=error msg="the router api@file uses a non-existent resolver: myresolver"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:59Z" level=debug msg="Serving default certificate for request: \"traefik.example.in\""
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:59Z" level=debug msg="http: TLS handshake error from 45.118.159.166:59367: remote error: tls: unknown certificate"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:59Z" level=debug msg="Serving default certificate for request: \"traefik.example.in\""
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:00:59Z" level=debug msg="http: TLS handshake error from 45.118.159.166:59368: remote error: tls: unknown certificate"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:01:01Z" level=debug msg="Serving default certificate for request: \"traefik.example.in\""
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:01:01Z" level=debug msg="http: TLS handshake error from 45.118.159.166:59369: remote error: tls: unknown certificate"
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:01:01Z" level=debug msg="Serving default certificate for request: \"traefik.example.in\""
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:01:01Z" level=debug msg="Authentication succeeded" middlewareType=BasicAuth middlewareName=auth@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:01:01Z" level=debug msg="Authentication succeeded" middlewareType=BasicAuth middlewareName=auth@file
traefik_traefik.1.wnc3u38hjtif@gcloud1 | time="2020-02-20T13:01:01Z" level=debug msg="Authentication succeeded" middlewareName=auth@file middlewareType=BasicAuth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment