Skip to content

Commit 570f36e

Browse files
committed
Testing traefik v2 configs
Signed-off-by: Pascal Andy <pascal@firepress.org>
1 parent bcc493b commit 570f36e

File tree

9 files changed

+615
-2
lines changed

9 files changed

+615
-2
lines changed

traefik_stack6/README-tmp.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
wip
2+
3+
4+
5+
6+
### List routers
7+
8+
```
9+
curl -s --user myuser:changemeplease http://localhost:8080/api/http/routers | jq
10+
```
11+
12+
### webapps
13+
14+
add an old Apache httpd
15+
16+
17+
### basic auth
18+
19+
Execute:
20+
21+
```
22+
USER=myuser
23+
PW=changemeplease
24+
25+
docker run ctr.run/github.com/firepress-org/alpine:master \
26+
sh -c "htpasswd -nbB ${USER} ${PW}" | sed -e 's/\$/\$\$/g'
27+
```
28+
29+
Will output:
30+
31+
```
32+
myuser:$$2y$$05$$jxN.6f/TMXWaf1ftsC9u2O4il1vPd5CHGW9Mi7kc3u30fpHYs57Ni
33+
```
34+
35+
We use **sed** in order to duplicate the $ sign. Else, bash would interpret single $ as a variable.
36+
37+
### Generate acme.json
38+
39+
```bash
40+
mkdir -pv ./configs && \
41+
touch ./configs/acme.json && \
42+
chmod 600 acme.json;
43+
```
44+
45+
### Sources
46+
47+
- https://moritzvd.com/upgrade-traefik-2/
48+
- https://containo.us/blog/traefik-2-0-docker-101-fc2893944b9d/

traefik_stack6/README.md

Lines changed: 172 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,172 @@
1-
wip
1+
## What is this?
2+
3+
Using a **one-liner**, this docker stack will run many services (Traefik (with auth), Socat, Portainer, Nginx, Caddy, Whoami) in a straightforward copy-paste command.
4+
5+
You may also refer the [README](https://github.com/pascalandy/docker-stack-this/blob/master/README.md) at the root of this repo.
6+
7+
## Start here
8+
1. Go to http://labs.play-with-docker.com/
9+
2. Create **one** instance
10+
3. Copy-paste this one-liner:
11+
12+
#### Stable setup (recommended)
13+
14+
```
15+
ENV_BRANCH="master"
16+
ENV_MONOREPO="traefik_stack5"
17+
18+
# On play-with-docker, install common apps
19+
apk update && apk upgrade && apk add --no-cache \
20+
nano bash git curl wget unzip openssl tar ca-certificates && \
21+
rm -rf /var/cache/apk/* /tmp* && \
22+
docker swarm init --advertise-addr $(hostname -i) && \
23+
git clone https://github.com/pascalandy/docker-stack-this.git && \
24+
cd docker-stack-this && \
25+
git checkout ${ENV_BRANCH} && \
26+
cd ${ENV_MONOREPO} && \
27+
./runup.sh;
28+
```
29+
30+
#### Edge setup (NOT recommended)
31+
32+
```
33+
ENV_BRANCH="edge"
34+
ENV_MONOREPO="traefik_stack6"
35+
36+
# On play-with-docker, install common apps
37+
apk update && apk upgrade && apk add --no-cache \
38+
nano bash git curl wget unzip openssl tar ca-certificates && \
39+
rm -rf /var/cache/apk/* /tmp* && \
40+
docker swarm init --advertise-addr $(hostname -i) && \
41+
git clone https://github.com/pascalandy/docker-stack-this.git && \
42+
cd docker-stack-this && \
43+
git checkout ${ENV_BRANCH} && \
44+
cd ${ENV_MONOREPO} && \
45+
./runup.sh;
46+
```
47+
48+
These scripts will do the hard of deploying the stacks for us.
49+
50+
#### example
51+
52+
![2019-08-01_16h56](https://user-images.githubusercontent.com/6694151/62326965-5ca8f880-b47d-11e9-9416-2139d514fc64.gif)
53+
54+
## See your stacks
55+
56+
```
57+
$ docker stack ls
58+
59+
NAME SERVICES ORCHESTRATOR
60+
toolgui 2 Swarm
61+
toolproxy 2 Swarm
62+
toolwebapp 4 Swarm
63+
```
64+
65+
66+
## See your services
67+
68+
```
69+
$ docker service ls
70+
71+
ID NAME MODE REPLICAS IMAGE PORTS
72+
xjdsq3gxd59y toolgui_agent global 1/1 portainer/agent:latest
73+
0h375hmmnelo toolgui_portainer replicated 1/1 portainer/portainer:latest
74+
xim07ahqctsp toolproxy_socat replicated 1/1 devmtl/socatproxy:1.2
75+
y249kaecel8e toolproxy_traefik replicated 1/1 traefik:1.7.12 *:80->80/tcp, *:443->443/tcp, *:8080->8080/tcp
76+
s0061fdhvv6o toolwebapp_home replicated 1/1 abiosoft/caddy:1.0.1-no-stats
77+
ocpk5l6yg2gt toolwebapp_who1 replicated 1/1 nginx:1.15-alpine
78+
raq5czrlhrmb toolwebapp_who2 replicated 1/1 emilevauge/whoami:latest
79+
66b1rduru5k9 toolwebapp_who3 replicated 1/1 emilevauge/whoami:latest
80+
```
81+
82+
## Confirm that your services (containers) are running
83+
84+
1. When you see that all services are deployed, click on `80` to see the static landing page.
85+
2. From the same URL generated by play-with-docker, in the address bar of your browser, add `/who1` or `/who2` or `/who3` or `/portainer` to access other services.
86+
87+
88+
#### Full URL example
89+
90+
```
91+
http://pwd10-0-7-3-80.host1.labs.play-with-docker.com/
92+
http://pwd10-0-7-3-80.host1.labs.play-with-docker.com/who1
93+
http://pwd10-0-7-3-80.host1.labs.play-with-docker.com/who2
94+
http://pwd10-0-7-3-80.host1.labs.play-with-docker.com/who3
95+
http://pwd10-0-7-3-80.host1.labs.play-with-docker.com/portainer
96+
```
97+
98+
The container for the first URL is named `home`.
99+
100+
101+
#### Web apps details:
102+
- **/** = [caddy](https://github.com/pascalandy/caddy-securityheader)
103+
- **/who1** = [caddy](https://github.com/pascalandy/caddy-securityheader)
104+
- **/who2** = [whoami](https://hub.docker.com/r/emilevauge/whoami/)
105+
- **/portainer** = [portainer](https://hub.docker.com/r/portainer/portainer/)
106+
107+
For /who1 and /who2 you will see the container's Ids (5fe91baf7a3a & 78a0c7287df1) in this example
108+
109+
```
110+
$ docker ps | grep whoami
111+
5fe91baf7a3a emilevauge/whoami:latest "/whoamI" About a minute ago Up About a minute 80/tcp toolwebapp_who3.1.9zk09prm85gnl0ieuuncynhxh
112+
78a0c7287df1 emilevauge/whoami:latest "/whoamI" About a minute ago Up About a minute 80/tcp toolwebapp_who2.1.wj7vf83ag91ft7jgdy3gwejp4
113+
```
114+
115+
116+
## How to access Traefik
117+
118+
![traefik](https://user-images.githubusercontent.com/6694151/50121682-86334d80-0227-11e9-8f25-93dd8714d306.jpg)
119+
120+
121+
#### Traefik password
122+
123+
**user**: admin / **pass**: changethispass
124+
125+
This password is encrypted in our configs `.configs/traefik.toml`
126+
127+
To quickly generate yours with htpasswd, use my container:
128+
129+
```
130+
docker run --rm -it devmtl/alpinefire:3.8-D sh -c 'htpasswd -Bbn admin changethispass'
131+
```
132+
133+
This will display:
134+
135+
```
136+
admin:$2y$05$pAfipn3.brdHMI2eWGnYH.84XYqLozp1sUPi36/l54UAwv.zGLtNC
137+
```
138+
139+
Insert this string in your `.configs/traefik.toml`.
140+
141+
#### What is Traefik?
142+
143+
[Traefik](https://docs.traefik.io/configuration/backends/docker/) is a powerful layer 7 reverse proxy. Once running, the proxy will give you access to many web apps. I think this is a substantial use case to understand how this reverse-proxy works.
144+
145+
#### Traefik version
146+
147+
In `toolproxy.yml` look for something like `traefik:1.7.19`.
148+
149+
#### Other stuff to know?
150+
151+
- This stack does not use ACME (https://). ACME is a pain while developing … reaching limits, etc.
152+
- If you don’t want to use socat, check out the monorepo `traefik-manager-noacme`
153+
154+
## Screenshots
155+
156+
![docker-stack-this-stack5_11](https://user-images.githubusercontent.com/6694151/34073735-76c60ae2-e26e-11e7-85a1-755a7177b3f2.jpg)
157+
![docker-stack-this-stack5_12](https://user-images.githubusercontent.com/6694151/34073736-76d461c8-e26e-11e7-9aea-c8dbc049a383.jpg)
158+
![docker-stack-this-stack5_13](https://user-images.githubusercontent.com/6694151/34073737-76e1d998-e26e-11e7-8b7c-c619e91adadd.jpg)
159+
![docker-stack-this-stack5_14](https://user-images.githubusercontent.com/6694151/34073738-76f163ae-e26e-11e7-86d7-27ea62ae3284.jpg)
160+
![docker-stack-this-stack5_15](https://user-images.githubusercontent.com/6694151/34073739-77006d4a-e26e-11e7-8f2e-cbd4268ea403.jpg)
161+
![docker-stack-this-stack5_16](https://user-images.githubusercontent.com/6694151/49540846-158f4700-f89f-11e8-8e14-ceca2ff2b910.jpg)
162+
163+
![docker-stack-this-stack5_17](https://user-images.githubusercontent.com/6694151/49540848-1922ce00-f89f-11e8-9fdc-b6fce70825c8.jpg)
164+
165+
## All commands
166+
In the active path, just execute those bash-scripts:
167+
168+
- `./runup.sh`
169+
- `./rundown.sh`
170+
171+
**Bonus!** `./runctop.sh` is not a stack but a simple `docker run` to see the memory consumed by each container.
172+

traefik_stack6/REFERENCES.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

traefik_stack6/dynamic_conf.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# dynamic configurations
2+
# traefik will update them on the fly
3+
4+
http:
5+
routers:
6+
my-api:
7+
entryPoints:
8+
# Expose on :8080 aka 'dashboard'
9+
- dashboard
10+
# Activate this Router if Client asks for '/dashboard' or '/api'
11+
rule: "PathPrefix(`/dashboard`) || PathPrefix(`/api`)"
12+
# Expose the API
13+
service: api@internal
14+
# Use basic auth Middleware define below
15+
middlewares:
16+
- dashboard-auth
17+
18+
my-secure-api:
19+
entryPoints:
20+
# Expose via https
21+
- https
22+
# Activate this Router if Client requests specific subdomain and '/dashboard' or '/api'
23+
rule: "Host(`dashboard.traefik.moritzvd.com`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
24+
service: api@internal
25+
middlewares:
26+
- dashboard-auth
27+
tls:
28+
# Use ACME HTTP Challgen defined in 'traefik.yml' to get valid cert
29+
certResolver: myhttpchallenge
30+
31+
# Catch all global Router for redirects
32+
https-redirect:
33+
entryPoints:
34+
- http
35+
# Activate this Router on any Host requested
36+
rule: "hostregexp(`{host:.+}`)"
37+
# A service definition is mandatory that's why we use a dummy service define at the bottom
38+
service: dummy
39+
middlewares:
40+
- redirect-to-https
41+
42+
middlewares:
43+
dashboard-auth:
44+
basicAuth:
45+
users:
46+
# see README.md
47+
- "myuser:$$2y$$05$$jxN.6f/TMXWaf1ftsC9u2O4il1vPd5CHGW9Mi7kc3u30fpHYs57Ni"
48+
49+
redirect-to-https:
50+
redirectScheme:
51+
scheme: https
52+
permanent: true
53+
54+
services:
55+
# required as we defined entryPoints:http
56+
dummy:
57+
loadBalancer:
58+
servers:
59+
- url: localhost

traefik_stack6/htdocs/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang=en>
3+
4+
<head>
5+
<meta charset=utf-8>
6+
<title>Hello from httpd</title>
7+
</head>
8+
9+
<body>
10+
<h1>Hello from Apache served via a traefik reverse proxy</h1>
11+
<p><img src="https://www.apache.org/foundation/press/kit/APACHE_20th_anniversary.png" width="200" alt="Apache Logo"> <img src="https://raw.githubusercontent.com/docker-library/docs/a6cc2c5f4bc6658168f2a0abbb0307acaefff80e/traefik/logo.png" width="200" alt="Traefik Logo"></p>
12+
</body>
13+
14+
</html>

0 commit comments

Comments
 (0)