nginx load-balances a dummy http server

This commit is contained in:
LUXEY Adrien 2021-05-08 14:25:56 +02:00
parent efd6069af4
commit fab59e7a7a
3 changed files with 96 additions and 1 deletions

View file

@ -9,7 +9,9 @@
1. Base components: things that need to be installed before services
* Reverse-proxy/load-balancer: `nginx` is a good match for a one-node deployment. Installing it with Nomad/Consul will make me practice Consul Template etc.
* [x] Dummy HTTP server to have something to work with.
* [x] Reverse-proxy/load-balancer: `nginx` is a good match for a one-node deployment. Installing it with Nomad/Consul will make me practice Consul Template etc.
* Generate services configuration outside the `nginx` service definition.
* TLS: Let's Encrypt will probably be part of the same job definition as `nginx`.
2. Gitea migration

View file

@ -0,0 +1,38 @@
job "dummy-http-server" {
datacenters = ["dc1"]
group "server-group" {
count = 5
# update {
# canary = 1
# max_parallel = 5
# }
network {
port "http" {}
}
service {
name = "dummy-http-server"
port = "http"
check {
type = "http"
path = "/health"
interval = "2s"
timeout = "2s"
}
}
task "server" {
driver = "docker"
config {
image = "hashicorp/http-echo:latest"
args = [
"-listen", ":${NOMAD_PORT_http}",
"-text", "Hello and welcome to ${NOMAD_IP_http}:${NOMAD_PORT_http}",
]
}
}
}
}

View file

@ -0,0 +1,55 @@
job "nginx" {
datacenters = ["dc1"]
group "nginx" {
count = 1
network {
port "http" {
static = 8080
}
}
service {
name = "nginx"
port = "http"
}
task "nginx" {
driver = "docker"
config {
image = "nginx"
ports = ["http"]
volumes = [
"local:/etc/nginx/conf.d",
]
}
template {
data = <<EOF
upstream dummy-http-server-backend {
{{ range service "dummy-http-server" }}
server {{ .Address }}:{{ .Port }};
{{ else }}server 127.0.0.1:65535; # force a 502
{{ end }}
}
server {
listen 8080;
location / {
proxy_pass http://dummy-http-server-backend;
}
}
EOF
destination = "local/dummy-http-server-load-balancer.conf"
change_mode = "signal"
change_signal = "SIGHUP"
}
}
}
}