Add Postgres database to cluster
This commit is contained in:
parent
cf0a415179
commit
8d63c50ffb
@ -19,6 +19,12 @@ all:
|
||||
group: "100"
|
||||
mode: "0755"
|
||||
read_only: false
|
||||
- name: postgres-data
|
||||
path: /srv/volumes/postgres
|
||||
owner: "999"
|
||||
group: "999"
|
||||
mode: "0755"
|
||||
read_only: false
|
||||
- name: lldap-data
|
||||
path: /srv/volumes/lldap
|
||||
owner: "root"
|
||||
|
48
databases/main.tf
Normal file
48
databases/main.tf
Normal file
@ -0,0 +1,48 @@
|
||||
resource "nomad_job" "mysql-server" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/mysql.nomad")
|
||||
|
||||
# Block until deployed as there are servics dependent on this one
|
||||
detach = false
|
||||
}
|
||||
|
||||
resource "nomad_job" "postgres-server" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/postgres.nomad")
|
||||
|
||||
# Block until deployed as there are servics dependent on this one
|
||||
detach = false
|
||||
}
|
||||
|
||||
resource "nomad_job" "adminer" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/adminer.nomad")
|
||||
}
|
||||
|
||||
resource "nomad_job" "redis" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/redis.nomad")
|
||||
|
||||
# Block until deployed as there are servics dependent on this one
|
||||
detach = false
|
||||
}
|
||||
|
||||
resource "nomad_job" "rediscommander" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/rediscommander.nomad")
|
||||
}
|
@ -56,7 +56,7 @@ job "mysql-server" {
|
||||
|
||||
template {
|
||||
data = <<EOH
|
||||
{{ with nomadVar "nomad/jobs" }}
|
||||
{{ with nomadVar "nomad/jobs/mysql-server" }}
|
||||
MYSQL_ROOT_PASSWORD={{ .mysql_root_password }}
|
||||
{{ end }}
|
||||
EOH
|
||||
|
@ -1,18 +0,0 @@
|
||||
resource "nomad_job" "mysql-server" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/mysql.nomad")
|
||||
|
||||
# Block until deployed as there are servics dependent on this one
|
||||
detach = false
|
||||
}
|
||||
|
||||
resource "nomad_job" "adminer" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/adminer.nomad")
|
||||
}
|
73
databases/postgres.nomad
Normal file
73
databases/postgres.nomad
Normal file
@ -0,0 +1,73 @@
|
||||
job "postgres-server" {
|
||||
datacenters = ["dc1"]
|
||||
type = "service"
|
||||
priority = 80
|
||||
|
||||
group "postgres-server" {
|
||||
count = 1
|
||||
|
||||
restart {
|
||||
attempts = 10
|
||||
interval = "5m"
|
||||
delay = "25s"
|
||||
mode = "delay"
|
||||
}
|
||||
|
||||
network {
|
||||
mode = "bridge"
|
||||
|
||||
port "db" {
|
||||
to = 5432
|
||||
host_network = "wesher"
|
||||
}
|
||||
}
|
||||
|
||||
volume "postgres-data" {
|
||||
type = "host"
|
||||
read_only = false
|
||||
source = "mysql-data"
|
||||
}
|
||||
|
||||
service {
|
||||
name = "postgres-server"
|
||||
provider = "nomad"
|
||||
port = "db"
|
||||
}
|
||||
|
||||
task "postgres-server" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "postgres:14"
|
||||
ports = ["db"]
|
||||
}
|
||||
|
||||
volume_mount {
|
||||
volume = "postgres-data"
|
||||
destination = "/var/lib/postgresql"
|
||||
read_only = false
|
||||
}
|
||||
|
||||
env = {
|
||||
# Allow connections from any host
|
||||
"MYSQL_ROOT_HOST" = "%"
|
||||
}
|
||||
|
||||
template {
|
||||
data = <<EOH
|
||||
{{ with nomadVar "nomad/jobs/postgres-server" }}
|
||||
POSTGRES_USER={{ .superuser }}
|
||||
POSTGRES_PASSWORD={{ .superuser_pass }}
|
||||
{{ end }}
|
||||
EOH
|
||||
destination = "secrets/db.env"
|
||||
env = true
|
||||
}
|
||||
|
||||
resources {
|
||||
cpu = 300
|
||||
memory = 256
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
resource "nomad_job" "redis" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/redis.nomad")
|
||||
|
||||
# Block until deployed as there are servics dependent on this one
|
||||
detach = false
|
||||
}
|
||||
|
||||
resource "nomad_job" "rediscommander" {
|
||||
hcl2 {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
jobspec = file("${path.module}/rediscommander.nomad")
|
||||
}
|
Loading…
Reference in New Issue
Block a user