Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit 1116ffd

Browse files
author
Riaan Nolan
committed
Merge branch 'feature/traefik-proxy-fully-integrates-with-hashicorp-nomad' into 'master'
traefik on nomad, adding docs, screenshots See merge request all-staff/hashiqube!93
1 parent f01da4b commit 1116ffd

File tree

7 files changed

+160
-20
lines changed

7 files changed

+160
-20
lines changed

Vagrantfile

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Vagrant::configure("2") do |config|
7272
if machines.size == 1 # only expose these ports if 1 machine, else conflicts
7373
config.vm.network "forwarded_port", guest: 8200, host: 8200 # vault
7474
config.vm.network "forwarded_port", guest: 4646, host: 4646 # nomad
75+
config.vm.network "forwarded_port", guest: 8080, host: 8080 # nomad-traefik
76+
config.vm.network "forwarded_port", guest: 8181, host: 8181 # nomad-traefik-admin
7577
config.vm.network "forwarded_port", guest: 19702, host: 19702 # waypoint-kubernetes-minikube
7678
config.vm.network "forwarded_port", guest: 9702, host: 9702 # waypoint-nomad
7779
config.vm.network "forwarded_port", guest: 19200, host: 19200 # boundary

hashicorp/README.md

+72-20
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,78 @@ Bringing machine 'user.local.dev' up with 'virtualbox' provider...
939939
```
940940
![Nomad](images/nomad.png?raw=true "Nomad")
941941

942+
## Traefik Load Balancer for Nomad
943+
https://traefik.io/blog/traefik-proxy-fully-integrates-with-hashicorp-nomad/ <br />
944+
https://doc.traefik.io/traefik/v2.8/providers/nomad/
945+
946+
We are thrilled to announce the full integration of the new Nomad built-in Service Discovery with Traefik Proxy. This is a first-of-its-kind ingress integration that simplifies ingress in HashiCorp Nomad. Utilizing Nomad directly with Traefik Proxy has never been so easy!
947+
948+
In early May, Hashicorp announced Nomad Version 1.3. Among other updates, it also includes a nice list of improvements on usability and developer experience. Before this release, when using service discovery with Nomad, Traefik Proxy users had to use Hashicorp Consul and Nomad side-by-side in order to benefit from Traefik Proxy’s famous automatic configuration. Now, Nomad has a simple and straightforward way to use service discovery built-in. This improves direct usability a lot! Not only in simple test environments but also on the edge.
949+
950+
`http://localhost:8080/` and `http://localhost:8181`
951+
952+
![Traefik Load Balancer](images/traefik-dashboard.png?raw=true "Traefik Load Balancer")
953+
954+
![Traefik Load Balancer](images/traefik-proxy.png?raw=true "Traefik Load Balancer")
955+
956+
`vagrant up --provision-with nomad --provider docker`
957+
958+
The new native Service Discovery in Nomad really does work seamlessly. With this integration, delivering load balancing, dynamic routing configuration, and ingress traffic routing become easier than ever. Check out the Traefik Proxy 2.8 Release Candidate and the Nomad 1.3 release notes.
959+
960+
`curl -H "Host: whoami.nomad.localhost" http://localhost:8080 -v`
961+
962+
```
963+
* Trying 127.0.0.1:8080...
964+
* Connected to localhost (127.0.0.1) port 8080 (#0)
965+
> GET / HTTP/1.1
966+
> Host: whoami.nomad.localhost
967+
> User-Agent: curl/7.79.1
968+
> Accept: */*
969+
>
970+
* Mark bundle as not supporting multiuse
971+
< HTTP/1.1 200 OK
972+
< Content-Length: 365
973+
< Content-Type: text/plain; charset=utf-8
974+
< Date: Thu, 16 Jun 2022 02:08:56 GMT
975+
<
976+
Hostname: 86bb7e3d366a
977+
IP: 127.0.0.1
978+
IP: 172.18.0.5
979+
RemoteAddr: 172.18.0.1:51192
980+
GET / HTTP/1.1
981+
Host: whoami.nomad.localhost
982+
User-Agent: curl/7.79.1
983+
Accept: */*
984+
Accept-Encoding: gzip
985+
X-Forwarded-For: 172.17.0.1
986+
X-Forwarded-Host: whoami.nomad.localhost
987+
X-Forwarded-Port: 80
988+
X-Forwarded-Proto: http
989+
X-Forwarded-Server: 5d7dc64220c8
990+
X-Real-Ip: 172.17.0.1
991+
992+
* Connection #0 to host localhost left intact
993+
```
994+
## Fabio Load Balancer for Nomad
995+
https://github.com/fabiolb/fabio <br />
996+
https://fabiolb.net
997+
998+
Fabio is an HTTP and TCP reverse proxy that configures itself with data from Consul.
999+
1000+
Traditional load balancers and reverse proxies need to be configured with a config file. The configuration contains the hostnames and paths the proxy is forwarding to upstream services. This process can be automated with tools like consul-template that generate config files and trigger a reload.
1001+
1002+
Fabio works differently since it updates its routing table directly from the data stored in Consul as soon as there is a change and without restart or reloading.
1003+
1004+
When you register a service in Consul all you need to add is a tag that announces the paths the upstream service accepts, e.g. urlprefix-/user or urlprefix-/order and fabio will do the rest.
1005+
1006+
`http://localhost:9999/` and `http://localhost:9998`
1007+
1008+
![Fabio Load Balancer](images/fabio.png?raw=true "Fabio Load Balancer")
1009+
`vagrant up --provision-with nomad`
1010+
1011+
Fabio runs as a Nomad job, see `hashicorp/nomad/jobs/fabio.nomad`
1012+
Some routes are added via Consul, see `hashicorp/consul.sh`
1013+
9421014
## Consul
9431015
https://www.consul.io/
9441016

@@ -1611,23 +1683,3 @@ Bringing machine 'hashiqube0.service.consul' up with 'virtualbox' provider...
16111683
hashiqube0.service.consul: ++++ Login with admin:password
16121684
hashiqube0.service.consul: /tmp/vagrant-shell: line 5: 5093 Terminated sh -c 'sudo tail -f /var/log/boundary.log | { sed "/worker successfully authed/ q" && kill $$ ;}'
16131685
```
1614-
1615-
## Fabio Load Balancer
1616-
https://github.com/fabiolb/fabio <br />
1617-
https://fabiolb.net
1618-
1619-
Fabio is an HTTP and TCP reverse proxy that configures itself with data from Consul.
1620-
1621-
Traditional load balancers and reverse proxies need to be configured with a config file. The configuration contains the hostnames and paths the proxy is forwarding to upstream services. This process can be automated with tools like consul-template that generate config files and trigger a reload.
1622-
1623-
Fabio works differently since it updates its routing table directly from the data stored in Consul as soon as there is a change and without restart or reloading.
1624-
1625-
When you register a service in Consul all you need to add is a tag that announces the paths the upstream service accepts, e.g. urlprefix-/user or urlprefix-/order and fabio will do the rest.
1626-
1627-
`http://localhost:9999/` and `http://localhost:9998`
1628-
1629-
![Fabio Load Balancer](images/fabio.png?raw=true "Fabio Load Balancer")
1630-
`vagrant up --provision-with nomad`
1631-
1632-
Fabio runs as a Nomad job, see `hashicorp/nomad/jobs/fabio.nomad`
1633-
Some routes are added via Consul, see `hashicorp/consul.sh`
473 KB
Loading

hashicorp/images/traefik-proxy.png

299 KB
Loading

hashicorp/nomad.sh

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ cd /vagrant/hashicorp/nomad/jobs;
122122
#nomad run --address=http://localhost:4646 countdashboardtest.nomad
123123
nomad plan --address=http://localhost:4646 fabio.nomad
124124
nomad run --address=http://localhost:4646 fabio.nomad
125+
nomad plan --address=http://localhost:4646 traefik.nomad
126+
nomad run --address=http://localhost:4646 traefik.nomad
127+
nomad plan --address=http://localhost:4646 traefik-whoami.nomad
128+
nomad run --address=http://localhost:4646 traefik-whoami.nomad
125129
# curl -v -H 'Host: fabio.service.consul' http://${VAGRANT_IP}:9999/
126130
echo -e '\e[38;5;198m'"++++ Nomad http://localhost:4646"
127131
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# https://traefik.io/blog/traefik-proxy-fully-integrates-with-hashicorp-nomad/
2+
3+
job "traefik-whoami" {
4+
datacenters = ["dc1"]
5+
6+
type = "service"
7+
8+
group "traefik-whoami" {
9+
count = 1
10+
11+
network {
12+
port "http" {
13+
to = 8080
14+
}
15+
}
16+
17+
service {
18+
name = "traefik-whoami"
19+
port = "http"
20+
provider = "nomad"
21+
22+
tags = [
23+
"traefik.enable=true",
24+
"traefik.http.routers.http.rule=Host(`whoami.nomad.localhost`)",
25+
]
26+
}
27+
28+
task "server" {
29+
env {
30+
WHOAMI_PORT_NUMBER = "${NOMAD_PORT_http}"
31+
}
32+
33+
driver = "docker"
34+
35+
config {
36+
image = "traefik/whoami"
37+
ports = ["http"]
38+
}
39+
}
40+
}
41+
}

hashicorp/nomad/jobs/traefik.nomad

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# https://traefik.io/blog/traefik-proxy-fully-integrates-with-hashicorp-nomad/
2+
3+
job "traefik" {
4+
datacenters = ["dc1"]
5+
type = "service"
6+
7+
group "traefik" {
8+
count = 1
9+
10+
network {
11+
port "http"{
12+
static = 8080
13+
}
14+
port "admin"{
15+
static = 8181
16+
}
17+
}
18+
19+
service {
20+
name = "traefik-http"
21+
provider = "nomad"
22+
port = "http"
23+
}
24+
25+
task "server" {
26+
driver = "docker"
27+
config {
28+
image = "traefik:v2.8.0-rc1"
29+
ports = ["admin", "http"]
30+
args = [
31+
"--api.dashboard=true",
32+
"--api.insecure=true", ### For Test only, please do not use that in production
33+
"--entrypoints.web.address=:${NOMAD_PORT_http}",
34+
"--entrypoints.traefik.address=:${NOMAD_PORT_admin}",
35+
"--providers.nomad=true",
36+
"--providers.nomad.endpoint.address=http://10.9.99.10:4646" ### IP to your nomad server
37+
]
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)