.
This commit is contained in:
commit
dede9ce18d
21 changed files with 485 additions and 0 deletions
41
jobs/README.md
Normal file
41
jobs/README.md
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# Overview
|
||||
|
||||
So we have some machines(we call those "nodes")
|
||||
and each of those nodes runs (1) a nomad client; and (2) a consul client.
|
||||
Also, all these nodes are in a wireguard network.
|
||||
|
||||
nomad is responsible for actually deploying the servers on an available machine.
|
||||
actually the Nomad *Server* has state and knows what all clients are doing,
|
||||
while Nomad *Clients* are just doing what the server tells them to, like deploying
|
||||
a job.
|
||||
|
||||
A job is just a docker container, or the smallest deployable unit ig.
|
||||
|
||||
the same server-client-relationship exists with consul. Here, Consul's main
|
||||
purpose is to resolve hosts. A job registers itself (via a Consul Client) like
|
||||
"hey im a postgres server and i run on 10.0.2.1:5432" and then the Consul Master
|
||||
updates its catalogue: "oh so postgres is 10.0.2.1:5432" and then in our jobs, we
|
||||
can just use "postgres.service.consul" and it resolves to 10.0.2.1:5432 so thats cool.
|
||||
|
||||
Now wireguard is needed because while consul resolves hostnames, it doesn't help
|
||||
us connect to the resolved IPs. With a single node, that's fine but if we want to
|
||||
access a service on another node, we need wireguard(or something similar).
|
||||
Actually if we run all nodes in the same network and it'd be fine without.
|
||||
|
||||
|
||||
|
||||
## Most Basic Implementation
|
||||
|
||||
- single node
|
||||
- runs `nomad agent -dev` and `consul agent -dev`
|
||||
- /etc/nomad.d/consul.hcl:
|
||||
consul {
|
||||
address = "127.0.0.1:8500"
|
||||
}
|
||||
- all jobs define a consul service
|
||||
|
||||
|
||||
## useful commands
|
||||
|
||||
- `nomad job run <job>.hcl`
|
||||
- `consul catalog services` <- list registered services
|
||||
47
jobs/lobby.nomad.hcl
Normal file
47
jobs/lobby.nomad.hcl
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
job "lobby" {
|
||||
type = "service"
|
||||
|
||||
group "lobby" {
|
||||
count = 1
|
||||
|
||||
network {
|
||||
mode = "host"
|
||||
port "minecraft" {
|
||||
to = 25565
|
||||
}
|
||||
}
|
||||
|
||||
task "run" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "git.lab0x13.site/scrow/papermc:0.1"
|
||||
force_pull = false
|
||||
ports = ["minecraft"]
|
||||
#args = ["java", "-jar", "server.jar", "--port=${NOMAD_PORT_minecraft}"]
|
||||
}
|
||||
|
||||
env {
|
||||
HOST_POSTGRES = "jdbc:postgresql://postgres.service.consul/scrow"
|
||||
HOST_NATS = "nats://nats.service.consul"
|
||||
}
|
||||
|
||||
resources {
|
||||
cpu = 1000
|
||||
memory = 2048
|
||||
}
|
||||
|
||||
service {
|
||||
name = "lobby"
|
||||
port = "minecraft"
|
||||
provider = "consul"
|
||||
|
||||
check {
|
||||
type = "tcp"
|
||||
interval = "5s"
|
||||
timeout = "1s"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
39
jobs/nats.nomad.hcl
Normal file
39
jobs/nats.nomad.hcl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
job "nats" {
|
||||
type = "service"
|
||||
|
||||
group "nats" {
|
||||
|
||||
network {
|
||||
mode = "host"
|
||||
port "nats" {
|
||||
to = 4222
|
||||
}
|
||||
}
|
||||
|
||||
task "nats" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "nats:alpine"
|
||||
ports = ["nats"]
|
||||
}
|
||||
|
||||
resources {
|
||||
cpu = 500
|
||||
memory = 1000
|
||||
}
|
||||
|
||||
service {
|
||||
name = "nats"
|
||||
port = "nats"
|
||||
provider = "consul"
|
||||
|
||||
check {
|
||||
type = "tcp"
|
||||
interval = "5s"
|
||||
timeout = "1s"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
45
jobs/postgresql.nomad.hcl
Normal file
45
jobs/postgresql.nomad.hcl
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
job "postgres" {
|
||||
datacenters = ["dc1"]
|
||||
type = "service"
|
||||
|
||||
group "db" {
|
||||
network {
|
||||
mode = "host"
|
||||
port "postgres" {
|
||||
to = 5432
|
||||
}
|
||||
}
|
||||
|
||||
task "postgres" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "postgres:18-alpine"
|
||||
ports = ["postgres"]
|
||||
}
|
||||
|
||||
env {
|
||||
POSTGRES_USER = "postgres"
|
||||
POSTGRES_DB = "scrow"
|
||||
POSTGRES_HOST_AUTH_METHOD = "trust"
|
||||
}
|
||||
|
||||
resources {
|
||||
cpu = 500
|
||||
memory = 512
|
||||
}
|
||||
|
||||
service {
|
||||
name = "postgres"
|
||||
port = "postgres"
|
||||
provider = "consul"
|
||||
|
||||
check {
|
||||
type = "tcp"
|
||||
interval = "10s"
|
||||
timeout = "1s"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
jobs/velocity.nomad.hcl
Normal file
22
jobs/velocity.nomad.hcl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
job "velocity" {
|
||||
type = "service"
|
||||
|
||||
group "proxy" {
|
||||
network {
|
||||
port "minecraft" {
|
||||
static = 25565
|
||||
}
|
||||
}
|
||||
|
||||
task "velocity" {
|
||||
driver = "docker"
|
||||
config {
|
||||
image = "scrow/velocity:local"
|
||||
}
|
||||
resources {
|
||||
cpu = 2000
|
||||
memory = 1000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue